﻿// JScript File

function MSIE_VER() {agt=navigator.userAgent.toLowerCase();pos=agt.indexOf('msie')+1;if(pos)return agt.charAt(pos+4);return 0}
function openWin(url,title,attrib) {wref=window.open(url,title,attrib);if(MSIE_VER()>=5)wref.focus()}

function openInnewWindow(url,width,height,toolbar) {if(toolbar==1) {openWin(url,'MoJoB','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+width+',height='+height)} else {openWin(url,'MoJoB','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,movable=yes,resizable=yes,width='+width+',height='+height)}}


function keypress(buttonclientid)
{
    if(event.which || event.keyCode)
    {
        if ((event.which == 13) || (event.keyCode == 13)) 
        { 
            document.getElementById(buttonclientid).click();
            return false;
        }
    } 
    else 
    {
        return true;
    }
}


// Create the new window
function openInNewWindow2(href, width, height, toolbar) {
    var newWindow = window.open(href, '_blank');
    if (newWindow) {
        if (newWindow.focus) {
            newWindow.focus();
        }
        return false;
    }
    
    return true;
}


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(src, width, height, title){
	//loads popup only if it is disabled
	if(popupStatus==0){

        $("#popupTitle").html(title);
		$("#contactArea").html("<div id='popupLoading'>טוען....</div><iframe id='sendmail_iframe' src='" + src + "' frameborder='0' scrolling='no' height='" + height + "' width='" + width + "' />");
		
		$("#sendmail_iframe").load(function () {
            $("#popupLoading").hide();
		    $("#sendmail_iframe").contents().find(".sendmail_closebutton").click(function(){
		           disablePopup(); return false;
	            });
		    });

		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
		
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": $(document).scrollTop() + (windowHeight - popupHeight)/2,
		"left": $(document).scrollLeft() + (windowWidth - popupWidth)/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function resolvePopup(src, width, height, title)
{
	    //CLOSING POPUP
	    //Click the x event!
	    $("#popupContactClose").click(function(){
		    disablePopup();
	    });
	
		//centering with css
		centerPopup();
		//load popup
		loadPopup(src, width, height, title);
		return false;
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Click out event!
//	$("#backgroundPopup").click(function(){
//		disablePopup();
//	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});


function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

