var isMinNS4 = true;
var isMinIE4 = true;
var isMinIE5 = true;

isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
isMinIE4 = (document.all) ? 1 : 0;
isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;

function whatbrowser(){
	if(document.layers){
		thisbrowser="NN4";
	}
	if(document.all){
		thisbrowser="ie";
	}
	if(!document.all && document.getElementById){
		thisbrowser="NN6";
	}
}
//breakFrames();

function LoadImages( ) {
//  if( isMinNS4 || isMinIE4 ) {
  img1  = new Image( );
  img2  = new Image( );

  img1.src  = "/Images/button-bg.gif";
  img2.src  = "/Images/button-bg-over.gif";
//  }
}

LoadImages( );

function DoNothing( ) { }

//======================================= Global Functions =======================================

// Rollover
function RollOver( StrImageName,StrNewImagePath ) {
  if( isMinNS4 || isMinIE4 ) {
    document.images[ StrImageName ].src = StrNewImagePath;
  }
}

function getURL(StrUrl) {
	window.location.href = StrUrl;
}

function TargetBlank(StrBlankUrl) {
	var width = 800;
	var height = 580;
    var d = ((screen.width-width)/2);
	var h = ((screen.height-height)/2);
    window.open(StrBlankUrl,'','top='+h+',left='+d+',width='+width+',height='+height+',toolbar=1,location=1,directories=1,menubar=1,status=1,scrollbars=1,resizable=1');
}

function getMenuLink(StrUrl, StrTarget, IntMenuID) {
	var arg = getMenuLink.arguments;
	SetCookie('menuID', IntMenuID);
	if (arg.length > 0) {
		if(arg[1]=='_blank') {
			TargetBlank(StrUrl);
		} else if(arg[1]=='') {
			window.location.href = ''+StrUrl;
		} else if(arg[1]=='_top') {
			window.top.location.href = ''+StrUrl;
		} else {
			//myWindow = eval('window.'+ StrTarget +'.location.href');
			window.top.location.href = 'frames.php?frm=index.php?'+ StrUrl;
			//myWindow = StrUrl;
		}
	} else {
		window.location.href = StrUrl;
	}
}

function Redir(StrUrl) {
	window.location.href = StrUrl;
}

function thisPage(BulWithQuery) {
	var strUrl, urlArray;
    strUrl = window.location.href;
    urlArray = strUrl.split("/");
	lastItem = urlArray.length-1;
	StrOut = urlArray[lastItem];
	if(!BulWithQuery) {
		lastItemArr = StrOut.split("?");
		StrOut = lastItemArr[0];
	}
    return StrOut;
}

//======================================= Contact Form Functions =======================================

function pLayer(layerName) {
	if (document.getElementById(layerName).style.display == "block") {
		document.getElementById(layerName).style.display = "none";
	}
	else {
		document.getElementById(layerName).style.display = "block";
	} 
}

// =========== Functions that gets the value of a key (strKey) from the GET query string. ==========

function jsGet(strKey) {
    var strUrl, strOut, strKey;
    var strUrlArray, strRecArray;
	var startPos, endPos, x;
	strOut = "";
    strUrl = window.location.href;
    startPos = strUrl.indexOf("?")+1;
    endPos = strUrl.length;
    strUrl = strUrl.substring(startPos, endPos);
    strUrlArray = strUrl.split("&");
    for (x=0; x < strUrlArray.length; x++) {
        strRecArray = strUrlArray[x].split("=");
        if (strKey==strRecArray[0]){
            strOut = strRecArray[1];
			break;
        }
    }
    return strOut;
}


function getstr(IntRec) {
	var a = new Array('kdsalumnilist-request','kdsalumnilist-d-request','kdsalumnilist');
	var d = 'kinneretdayschool';
	var e = 'org';
	return a[IntRec]+'@'+d+'.'+e;
}
function postme(IntRec) {
	window.location.href = "ma"+"i"+"lt"+"o"+":" + getstr(IntRec);
}
function writeme(IntRec) {
	document.write('<a href="javascript:postme('+ IntRec +');" dir="ltr">'+ getstr(IntRec) +'</a>');
}

/********************************************************
variable getResolution();
Gets the clients available screen width and returns the 
width in "a,b,c,d or e" depending on the resolution. 
Will return "z" on unsupported resolutions.
Possible future modifications could be if both are null,
open a new browser window "full screen" write an image
100% x 100% get the image size and return the values.
********************************************************/

function getResolution(){
	var iWidth, iHeight, sRes;

	if (window.innerWidth != null) {
		iWidth = window.innerWidth;
		iHeight = window.innerHeight; 
	}


		else if (document.body.clientWidth != null) {
			iWidth = document.body.clientWidth;
			iHeight=document.body.clientHeight;
		}
		else { iWidth = 640; }
		if(iWidth <= 640) 
			{sRes = 1;}		// 640 x 480 Resolution
		else if(iWidth <= 800)
			{sRes = 2;}		// 800 x 600 Resolution
		else if(iWidth <= 1024)
			{sRes = 3;}		// 1024 x 800 Resolution
		else if(iWidth <= 1280)
			{sRes = 4;}		// 1280 x 1024 Resolution
		else if(iWidth <= 1600)
			{sRes = 5;}		// 1600 x 1200 Resolution
		else {sRes = 6}
		return (sRes);
}

/********************************************************
getBrowser();
Gets the users browser type and returns "ie5, ie4, ie3, 
ns6, ns4, ns3". Will return "other" on any other browser.
********************************************************/

function getBrowser() {
	var vBrowser=navigator.appName;			
	var vVersion=navigator.appVersion;
	var sBrowser;
	if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("6")>=0)
		{sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
	else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("5")>=0)
		{sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
	else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("4")>=0)
		{sBrowser="ie4";}		// Microsoft Internet Explorer 4.x
	else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("3")>=0)
		{sBrowser="ie3";}	// Microsoft Internet Explorer 3.x
	else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("6")>=0)
		{sBrowser="ns6";}	// Netscape Navigator 6.x
	else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("4")>=0)
		{sBrowser="ns4";}	// Netscape Navigator 4.x
	else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("3")>=0)
		{sBrowser="ns3";}	// Netscape Navigator 3.x
	else
		{sBrowser="other";}	// All Others 	
	return(sBrowser);
}	

/********************************************************
breakFrames();
breakFrames() Tests if user was linked to here within
a frame. If true then will reopen current location
in the parent window.
********************************************************/

function breakFrames(){
	if(self.parent.frames.length != 0)
		{self.parent.location = document.location;}
}


/*====================== Cookies Functions ======================*/

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
