var ns = navigator.userAgent.indexOf('Netscape') != -1;  
var isWin = navigator.appVersion.indexOf('Win') != -1;
var isIE = navigator.userAgent.indexOf('MSIE') != -1 && !isOpera;
var isIE6 = navigator.userAgent.indexOf('MSIE 6') != -1 && !isOpera;
var isIE7 = navigator.userAgent.indexOf('MSIE 7') != -1 && !isOpera;
var isAOL = navigator.appVersion.indexOf('AOL') != -1;		
var isOpera9 = navigator.userAgent.indexOf('Opera/9') != -1;
var isOpera10 = navigator.userAgent.indexOf('Opera/9.80') != -1;
var isOpera = navigator.userAgent.indexOf('Opera/9') != -1;

var isFirefox = navigator.userAgent.indexOf('Firefox') != -1;			
var isFirefox2 = navigator.userAgent.indexOf('Firefox/2') != -1;
		
var isMac = navigator.userAgent.indexOf('Mac OS X') != -1;
var isIntelMac105F = navigator.userAgent.indexOf('Intel Mac OS X 10.5') != -1;
var isIntelMac105S = navigator.userAgent.indexOf('Intel Mac OS X 10_5') != -1;
var isPPC = navigator.userAgent.indexOf('PPC Mac OS X') != -1;
var isSafari = navigator.appVersion.indexOf('Safari') != -1;
var macie52 = navigator.userAgent.indexOf('MSIE 5.2') != -1 && ! win;		

var iframeWebObj = "";
var FormObj = "";

//******************************************************//
//*********** Lzx windows + Exist JSP window ***********//
//******************************************************//

//Debug
//
//alert(navigator.userAgent);
//alert(navigator.appVersion);
//

function evaluateIframe(url, targetX, targetY, targetWidth, targetHeight, iframeName)
{
	iframeWebObj = document.getElementById(iframeName);
	//check supported version and browser
	var supported = comparabilityCheck();
	if(supported)
	{
		//back button history control
		//location.replace(url);
		if(iframeWebObj)
		{
			customizeIframeObj(url, targetX, targetY, targetWidth, targetHeight, iframeName);
		}
		else
		{
			createIframeObj(url, targetX, targetY, targetWidth, targetHeight, iframeName)		
		}		
	}
}

function createIframeObj(url, targetX, targetY, targetWidth, targetHeight, iframeName)
{
	if (document.createElement)
	{		
		//Use LZX and iframe to embed HTML into LZX
		
		iframeWebObj=document.createElement('iframe');
		iframeWebObj.id = iframeName;				
		iframeWebObj.src = 'about:blank';
		
		with(iframeWebObj.style)
		{
			visibility = 'hidden';
			left= targetX + 'px';
			top= targetY + 'px';
			width=targetWidth;
			height=targetHeight;			
		}

		document.body.appendChild(iframeWebObj);
		customizeIframeObj(url, targetX, targetY, targetWidth, targetHeight, iframeName);
		
		//setTimeout ('customizeIframeObj("'+url+'", "'+targetWidth+'", "'+targetHeight+'")', 5000 );  
	}
}

function customizeIframeObj(url, targetX, targetY, targetWidth, targetHeight, iframeName)
{
	iframeWebObj = document.getElementById(iframeName);			
	iframeWebObj.src = url;
	iframeWebObj.style.position = 'absolute';
	iframeWebObj.style.zIndex = 0;
	iframeWebObj.style.border='0px';
	iframeWebObj.style.visibility = 'visible';
	iframeWebObj.style.bgcolor = '#6B859F';
	
	if(isWin)	
	{
		with (iframeWebObj.style)
		{
			left= targetX + 'px';
			top= targetY + 'px';
			width=targetWidth;
			height=targetHeight;
		}						
	}
	else if(isMac)
	{
		if(isPPC)
		{
			//Do not support
		}
		else
		{
			if(isIntelMac105F || isIntelMac105S)
			{
				with (iframeWebObj.style)
				{
					left= targetX + 'px';
					top= targetY + 'px';
					width=targetWidth;
					height=targetHeight;
				}				
			}				
		}		
	}
}

function relocateIframeObj(targetX, targetY, targetWidth, targetHeight, iframeName)
{
	iframeWebObj = document.getElementById(iframeName);	
	if(iframeWebObj)
	{
		if(isWin)	
		{	
			with (iframeWebObj.style)
			{
				left= targetX + 'px';
				top= targetY + 'px';
				width=targetWidth;
				height=targetHeight;				
			}					
		}
		else if(isMac)
		{
			if(isPPC)
			{
				//Do not support
			}
			else
			{
				if(isIntelMac105F || isIntelMac105S)
				{
					with (iframeWebObj.style)
					{
						left= targetX + 'px';
						top= targetY + 'px';
						width=targetWidth;
						height=targetHeight;						
					}				
				}
			}
		}		
	}
}

function cleanIframObj(iframeName)
{
	iframeWebObj = document.getElementById(iframeName);
	if(iframeWebObj)
	{
		iframeWebObj.src = 'about:blank';
		with(iframeWebObj.style)
		{
			visibility = 'hidden';
		}		
	}
}

function comparabilityCheck()
{	
	if(isWin)
	{
		return true;
	}
	else if(isMac)
	{
		if(isPPC)
		{
			//No support for PPC
			return false;	
		}
		else
		{
			if(isIntelMac105F || isIntelMac105S)
			{
				return true;				
			}
			else
			{
				//No support for 10.4 Tiger
				return false;					
			}
		}
	}
	else
	{
		return false;		
	}
}

function comparabilityCheck4NavigatorVersion(browser, version)
{	
	if(isWin)
	{
		switch(browser)
		{			
			case "Firefox" :
						if(parseFloat(version) >= 1.5)
						{
							return true;
						}
						else
						{
							return false;
						}
						
						break;
						
			case "Safari" :
						if(parseFloat(version) > 3)
						{
							return true;
						}
						else
						{
							return false;
						}
						
						break;
						
			default:
					return false;
		}
	}
	else if(isMac)
	{
		if(isPPC)
		{
			return false;	
		}
		else
		{
			if(isIntelMac105F || isIntelMac105S)
			{
				switch(browser)
				{
					case "Firefox": 
									if(parseFloat(version) > 1.5)
									{
										return true;
									}
									else
									{
										return false;
									}
									
									break;
								
					case "Safari" :
									if(parseFloat(version) > 3)
									{
										return true;
									}
									else
									{
										return false;
									}
									
									break;
									
					default:
							return false;
				}		
			}
			else
			{
				return false;					
			}
		}
	}
	else
	{
		return false;		
	}
}

function openRequestedSite(url, width, height, target)
{
	//bring to front if there is opened window so that user can not be confused when they open targeted window again that is hide
	var win = target + "_WIN";
	if(isIE)
	{
		if(isIE6)
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=137');
		}
		else
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=144');
		}
		
	}
	else
	{
		win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=128');
	}
	
	win.focus();
	return false;
}

function openEmptyWindowForTarget(url, width, height, target)
{
	//bring to front if there is opened window so that user can not be confused when they open targeted window again that is hide
	var win = target + "_WIN";
	if(isIE)
	{
		if(isIE6)
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=137');
		}
		else
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=144');
		}
		
	}
	else
	{
		win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=0,top=128');
	}

	win.focus();
	return false;
}

function downloadFromRemoteSite(url, width, height, target)
{
	//bring to front if there is opened window so that user can not be confused when they open targeted window again that is hide
	var win = target + "_WIN";
	if(isIE)
	{
		if(isIE6)
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=no,resizable=no,width='+width+',height='+height+',left=0,top=137');
		}
		else
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=no,resizable=no,width='+width+',height='+height+',left=0,top=144');
		}
		
	}
	else
	{
		win = window.open(url,target,'toolbar=no,location=no,scrollbars=no,resizable=no,width='+width+',height='+height+',left=0,top=128');
	}

	win.focus();
	return false;
}

function OpenRemoteJspPage(url, width, height, target)
{
	//bring to front if there is opened window so that user can not be confused when they open targeted window again that is hide
	var win = target + "_WIN";
	if(isIE)
	{
		if(isIE6)
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=no,width='+width+',height='+height+',left=0,top=137');
		}
		else
		{
			win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=no,width='+width+',height='+height+',left=0,top=144');
		}
		
	}
	else
	{
		win = window.open(url,target,'toolbar=no,location=no,scrollbars=yes,resizable=no,width='+width+',height='+height+',left=0,top=128');
	}

	win.focus();
	return false;
}

function changeFocusToBody()
{
	document.body.focus();
}

function reOpenAsLzxPage()
{
	window.open('splash.jsp','lzx','toolbar=no,location=no,scrollbars=yes,resizable=yes,left=0,top=0');
}

function getBrowserName()
{	
	if(ns)
	{
		return "Netscape";
	}
	else if(isIE)
	{
		return "IE";
	}
	else if(isAOL)
	{
		return "AOL";
	}
	else if(isOpera)
	{
		return "Opera";
	}
	else if(isFirefox)
	{
		return "Firefox";
	}
	else if(isSafari)
	{
		return "Safari";
	}
	else if(macie52)
	{
		return "MacIE";
	}
	else
	{
		return "Unknow";
	}
}

function getIEversion()
{
	var ver = 0;
	if(isIE)
	{
	    var ua = navigator.userAgent;
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}

	return ver;
}

function getSupportedBrowserVersion()
{
	var ver = 0;
    var ua = navigator.userAgent;
    
	if(isIE)
	{
		//from 7
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}
	else if(isFirefox)
	{
		//from 2
	    var re  = new RegExp("Firefox/([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}
	else if(ns)
	{
		//from 8
	    var re  = new RegExp("Netscape/([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}
	else if(isOpera)
	{
		//from 9.80
	    var re  = new RegExp("Version/([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}
	else if(isSafari)
	{
		//from 3
	    var re  = new RegExp("Version/([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null) ver = parseFloat( RegExp.$1 );
	}
	
	return ver;
}
//*******************************************************//
//*********** Execute Struts Action from Lzx  ***********//
//*******************************************************//

function callParentReport(ColorID,ColorName)
{
	document.colorNameHolder.FavoriteColorID.value = ColorID;
	document.colorNameHolder.FavoriteColorName.value = ColorName;
	document.colorNameHolder.submit();
}

function callParentNotes(ColorID,ColorName)
{
	document.homeworkColorHolder.FavoriteColorID.value = ColorID;
	document.homeworkColorHolder.FavoriteColorName.value = ColorName;
	document.homeworkColorHolder.submit();
}

function callParentPayment(ColorID,ColorName)
{
	document.payColorHolder.FavoriteColorID.value = ColorID;
	document.payColorHolder.FavoriteColorName.value = ColorName;
	document.payColorHolder.submit();
}

function callReg(ColorID,ColorName)
{
	document.regColorHolder.FavoriteColorID.value = ColorID;
	document.regColorHolder.FavoriteColorName.value = ColorName;
	document.regColorHolder.submit();
}

function callHelp(ColorID,ColorName)
{
	if(ColorID == 'undefined')
	{
		//Do nothing
	}
	else
	{
		document.helpColorHolder.FavoriteColorID.value = ColorID;
		document.helpColorHolder.FavoriteColorName.value = ColorName;
	}
	
	document.helpColorHolder.submit();
}

function callChangePW(ColorID,ColorName)
{
	document.changeColorHolder.FavoriteColorID.value = ColorID;
	document.changeColorHolder.FavoriteColorName.value = ColorName;
	document.changeColorHolder.submit();
}

function callUserLogin(ColorID,ColorName)
{
	document.loginColorHolder.submit();
}

function callLogout(ColorID,ColorName)
{
	document.logoutColorHolder.submit();
}

function lzxSmartLogin(FavoriteColorName,FavoriteColorWord,FavoriteColorCode,FavoriteColorKey,passedFID)
{
	document.lzxSmartLogin.FavoriteColorName2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorName;
	document.lzxSmartLogin.FavoriteColorWord2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorWord;
	document.lzxSmartLogin.FavoriteColorCode2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorCode;
	document.lzxSmartLogin.FavoriteColorKey2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorKey;
	document.lzxSmartLogin.FavoriteColorID2739C7995ECBBE9E59FC141AD761394B.value = passedFID;
	document.lzxSmartLogin.submit();
}

function lzxSmartDirectoryLogin(FavoriteColorID,FavoriteColorName)
{
	document.lzxSmartDirectoryLogin.FavoriteColorID2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorID;
	document.lzxSmartDirectoryLogin.FavoriteColorName2739C7995ECBBE9E59FC141AD761394B.value = FavoriteColorName;
	document.lzxSmartDirectoryLogin.submit();
}

function openPublicPaymentGateway(quantity, itemname, publicPrice, publicEmail, isMultiple)
{
	document.publicPaymentGateway.publicItemID.value = "4";
	document.publicPaymentGateway.quantity.value = quantity;
	document.publicPaymentGateway.itemname.value = itemname;
	document.publicPaymentGateway.publicPrice.value = publicPrice;
	document.publicPaymentGateway.publicEmail.value = publicEmail;
	document.publicPaymentGateway.isMultiple.value = isMultiple;
	document.publicPaymentGateway.submit();
}

function openPublicDonationGateway(quantity, itemname, amount, publicEmail, isMultiple, donorName, donorAddress, donorCity, donorProv, donorPostalCode, supportingStudentName, taxReceipt)
{
	document.publicPaymentGateway.publicItemID.value = "11";
	document.publicPaymentGateway.quantity.value = quantity;
	document.publicPaymentGateway.itemname.value = itemname;
	document.publicPaymentGateway.publicPrice.value = amount;
	document.publicPaymentGateway.publicEmail.value = publicEmail;
	document.publicPaymentGateway.isMultiple.value = isMultiple;
	
	document.publicPaymentGateway.donorName.value = donorName;
	document.publicPaymentGateway.donorAddress.value = donorAddress;
	document.publicPaymentGateway.donorCity.value = donorCity;
	document.publicPaymentGateway.donorProv.value = donorProv;
	document.publicPaymentGateway.donorPostalCode.value = donorPostalCode;
	document.publicPaymentGateway.supportingStudentName.value = supportingStudentName;
	document.publicPaymentGateway.taxReceipt.value = taxReceipt;

	document.publicPaymentGateway.submit();
}

//Pdf download from lzxRegistration
function lzxDownloadFromLzxRegistration(sub_dir, filename)
{
	document.downloadFromLzxRegistration.sub_dir.value = sub_dir;
	document.downloadFromLzxRegistration.filename.value = filename;
	document.downloadFromLzxRegistration.submit();
}

//open ePayment page
function lzxOpenSchoolFeeOnlinePayment(FID, CID, username, schoolYear)
{
	document.schoolFeeOnlinePayment.username.value= username;
	document.schoolFeeOnlinePayment.calendar_id.value = CID;
	document.schoolFeeOnlinePayment.FID.value = FID;
	document.schoolFeeOnlinePayment.schoolYear.value = schoolYear;
	document.schoolFeeOnlinePayment.submit();
}

//Pdf download from lzxBackOffice
function DownloadPdfFromLzxBackOffice(sessionKey, filename)
{
	document.downloadPdfFromLzxBackOffice.sessionKey.value = sessionKey;
	document.downloadPdfFromLzxBackOffice.filename.value = filename;
	document.downloadPdfFromLzxBackOffice.submit();
}

//open eagyCheckout page
function lzxOpenSchoolProgramPayment(sessionKey, FID, ParentEmail, SID, webMastersEmail, source, isMultiple, parameterized, ItemId, cost, item, quantity)
{
	document.easyCheckoutPayment.sessionKey.value= sessionKey;
	document.easyCheckoutPayment.FID.value = FID;
	document.easyCheckoutPayment.ParentEmail.value = ParentEmail;
	document.easyCheckoutPayment.SID.value = SID;
	document.easyCheckoutPayment.WebMastersEmail.value = webMastersEmail;
	document.easyCheckoutPayment.source.value = source;
	document.easyCheckoutPayment.isMultiple.value = isMultiple;
	document.easyCheckoutPayment.parameterized.value = parameterized;
	document.easyCheckoutPayment.ItemId.value = ItemId;
	document.easyCheckoutPayment.cost.value = cost;
	document.easyCheckoutPayment.item.value = item;
	document.easyCheckoutPayment.quantity.value = quantity;
	document.easyCheckoutPayment.submit();
}

//**********************************************************//
//*********** Positioning LZX on the application ***********//
//**********************************************************//
function positioningParentNav(app)
{
	obj = document.getElementById("lzParentNavHolder");			
	obj.style.position = 'absolute';
	obj.style.zIndex = 10;
	obj.style.border='0px';
	obj.style.visibility = 'visible';
	
	if(app == "registration")
	{
		if(isFirefox)	
		{
			with (obj.style)
			{
				left= '22px';
				top= '133px';
			}						
		}
		else
		{
			with (obj.style)
			{
				left= '22px';
				top= '133px';
			}
		}
	}
	else
	{
		if(isFirefox)	
		{
			with (obj.style)
			{
				left= '30px';
				top= '133px';
			}						
		}
		else if(ns)
		{
			with (obj.style)
			{
				left= '30px';
				top= '133px';
			}			
		}
		else
		{
			with (obj.style)
			{
				left= '22px';
				top= '133px';
			}
		}
	}
}

function removePreloader()
{
	var preloader = document.getElementById("preloader");
	with(preloader.style)
	{
		display = 'none';
	}
}