function IsLeapYear (year)
{
	var leap = false;
	if (year <=0)
	{
		return false;
	}

	if ((year & 0x03) == 0)
	{
		leap = true;
		if ((year & 0x7F) == 0)
		{
			leap = false;
		}
	}
	return leap;
}

function UpdateDay(id1, id2, id3)
{
	var year = document.all(id1);
	var month = document.all(id2);
	var day = document.all(id3);

	if (month.selectedIndex == 2)
	{
		// Either 28 days or 29 days
		day.options.remove(31);
		day.options.remove(30);
		day.options.remove(29);
		
		if (IsLeapYear(year.selectedIndex))
		{
			var oOption1 = document.createElement("OPTION");
			day.options.add(oOption1);
			oOption1.innerText="29";
			oOption1.Value="29";
		}
	}
	else if ((month.selectedIndex == 4)
			  ||(month.selectedIndex == 6)
			  ||(month.selectedIndex == 9)
			  ||(month.selectedIndex == 11))
	{
		day.options.remove(31);
		day.options.remove(30);
		day.options.remove(29);
		
		var oOption1 = document.createElement("OPTION");
		day.options.add(oOption1);
		oOption1.innerText="29";
		oOption1.Value="29";
											
		var oOption2 = document.createElement("OPTION");
		day.options.add(oOption2);
		oOption2.innerText="30";
		oOption2.Value="30";
	}
	else
	{
		day.options.remove(31);
		day.options.remove(30);
		day.options.remove(29);
						
		var oOption1 = document.createElement("OPTION");
		day.options.add(oOption1);
		oOption1.innerText="29";
		oOption1.Value="29";
						
		var oOption2 = document.createElement("OPTION");
		day.options.add(oOption2);
		oOption2.innerText="30";
		oOption2.Value="30";
						
		var oOption3 = document.createElement("OPTION");
		day.options.add(oOption3);
		oOption3.innerText="31";
		oOption3.Value="31";
	}
	
}

function DatePicker1(form, ctrl, selectID)
{
	var url = "../DatePicker.aspx?fn=" + form + "&tn=" + ctrl;
	url+= "&function=AddPerson('" + selectID + "')";
	PopupDate(url);
}

function AddPerson(selectID)
{
	var name = document.all("TxtBirthday").value;
	if (name != null && name != "")
	{
		var myOpt = new Option;
		myOpt.value = name;
		myOpt.text  = name;
		document.all(selectID).options.add(myOpt);
	}
	document.all("TxtBirthday").value = "";
}

function RemovePerson(selectID)
{
	var opt = document.all(selectID);
	var index = opt.selectedIndex;
	if (index >=0)
	{
		opt.remove(index);
	}
}

function MirrorSelection(mirrorFld, selectID)
{
	var opt = document.all(selectID);
	var mirrorCtrl = document.all(mirrorFld);
	if (opt != null)
	{
		mirrorCtrl.value = opt.options[opt.selectedIndex].value;
	}
}

function SubmitAAA(selPersons, selCoverage, selDuration, selDestination)
{
	var opt = document.all(selPersons);
	var i = 0;
	var txt = "";
	for (i = 0; i < opt.options.size; i++)
	{
		if (opt.options[i] != null)
		{
			if (txt != "")
			{
				txt+= ",";
			}
			txt+= opt.options[i].value;
		}
	}
	if (txt != "")
	{
		document.all("AgesField").value = txt;

		MirrorSelection("Mirror_Coverage", selCoverage)		
		MirrorSelection("Mirror_Destination", selDestination)		
		MirrorSelection("Mirror_Duration", selDuration)		
		AropeForm.submit();
	}
}

function DisableSection(obj, objName, disableOn, fields)
{
	if (fields == "")
	{
		return;
	}
	
	var i = 0;
	var arr = fields.split(",");
	var disable = true;
	
	if (disableOn == "")
	{
		disable = document.all(objName).checked;
	}
	else
	{
		disable = (obj.value == disableOn);
	}
	
	if (disable)
	{
		for (i = 0; i < arr.length; i++)
		{
			document.all(arr[i]).disabled = true;
			document.all(arr[i]).style.background = "#CCCCCC";
		}
	}
	else
	{
		for (i = 0; i < arr.length; i++)
		{
			document.all(arr[i]).disabled = false;
			document.all(arr[i]).style.background = "white";
		}
	}
}

function DisableSectionValidators(obj, objName, disableOn, validators)
{
	if (validators == "")
	{
		return;
	}
	
	var i = 0;
	var arr = validators.split(",");
	var disable = true;
	
	if (disableOn == "")
	{
		disable = document.all(objName).checked;
	}
	else
	{
		disable = (obj.value == disableOn);
	}
	
	if (disable)
	{
		for (i = 0; i < arr.length; i++)
		{
			document.all(arr[i]).enabled = false;
		}
	}
	else
	{
		for (i = 0; i < arr.length; i++)
		{
			document.all(arr[i]).enabled = true;
		}
	}
}

function PopupDate(url)
{
	
	var w   = 300;
	var h   = 290;
	
	if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		{
			if (document.layers)
				var xMax = window.outerWidth, yMax = window.outerHeight;
			else
				var xMax = 640, yMax=480;
		}
	
	if (w>xMax)
		w = xMax * .9;
	if (h>yMax)
		h = yMax * .9;
	
	var l = (xMax - w)/2, t = (yMax-h)/2;
	
	handle_PUH = window.open(url,"DatePicker",'screenX='+l+',left='+l+',screenY='+t+',top='+t+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=0,width='+w+',height='+h);
}

function DatePicker(thisForm,thisControl)
{
	var url = "DatePicker.aspx?fn="+thisForm+"&tn="+thisControl;
	PopupDate(url);
}

//Register Scripts
function Register_EnableBtnRegister()
{
	if(document.all("ChkTerms").checked){
		document.all("BtnRegister").disabled=false;
		document.all("BtnRegister").src = "images/register.gif";
	}
	else{
		document.all("BtnRegister").disabled=true;
		document.all("BtnRegister").src = "images/registerX.gif"
	}
}

//Renew Scripts
function Renew_EnableTxtModify()
{
	if(document.all("RdbModify").checked)
	{
		document.all("TxtModifications").disabled = false;
		document.all("TxtModifications").style.background = "white";
	}
	else
	{
		document.all("TxtModifications").disabled = true;
		document.all("TxtModifications").style.background = "#CCCCCC";
	}
}

//Life Simulator Scripts
function UpdateTPD(yearListID,monthListID,dayListID,RdbYesTpdID,RdbNoTpdID)
{
	var year = document.all(yearListID);
	var month = document.all(monthListID);
	var day = document.all(dayListID);
	
	if( (year.selectedIndex==0) || (month.selectedIndex==0) || (day.selectedIndex==0) )
	{
		return;
	} 
	var today = new Date();
	
	var deltaYear = today.getYear() - year.options(year.selectedIndex).value;
	
	if(deltaYear>65)
	{
		document.all(RdbNoTpdID).checked = true;
		document.all(RdbYesTpdID).disabled = true;
		document.all(RdbNoTpdID).disabled = true;
	}
	else if(deltaYear==65)
	{
		var deltaMonth = today.getMonth() - month.selectedIndex + 1;
		var deltaDay = today.getDate() - day.selectedIndex;
				
		if(deltaMonth>0)
		{
			document.all(RdbNoTpdID).checked = true;
			document.all(RdbYesTpdID).disabled = true;
			document.all(RdbNoTpdID).disabled = true;
		}
		else if(deltaMonth==0)
		{
			if(deltaDay>=0)
			{
				document.all(RdbNoTpdID).checked = true;
				document.all(RdbYesTpdID).disabled = true;
				document.all(RdbNoTpdID).disabled = true;
			}
			else
			{
				document.all(RdbYesTpdID).disabled = false;
				document.all(RdbNoTpdID).disabled = false;
			}
		}
		else
		{
			document.all(RdbYesTpdID).disabled = false;
			document.all(RdbNoTpdID).disabled = false;
		}
	}
	else
	{
		document.all(RdbYesTpdID).disabled = false;
		document.all(RdbNoTpdID).disabled = false;
	}
}

//ManageProducts Scripts

function ManageProducts_EnableBtnDetails()
{
	if(document.all("ChkChangeThumbnail").checked)
		document.all("InputThumbnail").disabled=false;
	else
		document.all("InputThumbnail").disabled=true;
}
						
function ManageProducts_EnableInputThumbnail()
{
	if(document.all("ChkChangeThumbnail").checked)
		document.all("InputThumbnail").disabled=false;
	else
		document.all("InputThumbnail").disabled=true;
}
						
function ManageProducts_EnableInputImage()
{
	if(document.all("ChkChangeImage").checked)
		document.all("InputImage").disabled=false;
	else
		document.all("InputImage").disabled=true;
}

function ManageProducts_EnableInputTemplate()
{
	if(document.all("ChkChangeTemplate").checked)
		document.all("InputTemplate").disabled=false;
	else
		document.all("InputTemplate").disabled=true;
}

function ManageProducts_EnableInputBanner()
{
	if(document.all("ChkChangeBanner").checked)
		document.all("InputBanner").disabled=false;
	else
		document.all("InputBanner").disabled=true;
}
						
function ManageProducts_EnableInputXMLfile()
{
	if(document.all("ChkChangeXMLfile").checked)
		document.all("InputXMLfile").disabled=false;
	else
		document.all("InputXMLfile").disabled=true;
}

function Redirect2Results()
{
	if (document.SearchForm.txtSearch.value != '')
	{
		window.open("quick.asp?keyword=" + document.SearchForm.txtSearch.value, 'SearchWindow', 'toolbar=no,resizable=yes,scrollbars=yes');		
	}
	else
	{
		alert('Please Enter a keyword');
		document.SearchForm.txtSearch.focus();
	}
}

function ShowImage(image)
{
	window.open(image, 'ImageMap', 'toolbar=no,width=440,height=420,resizable=no,scrollbars=no');
}

function ManageProducts_OpenTemplate(templateURL)
{
	window.open(templateURL, 'TemplateWindow', 'toolbar=no,resizable=yes,scrollbars=yes');
}
						
function ManageProducts_OpenImage(imageURL)
{
	window.open(imageURL, 'ImageWindow', 'toolbar=no,resizable=yes,scrollbars=yes');
}

function ManageProducts_OpenBanner(bannerURL)
{
	window.open(bannerURL, 'BannerWindow', 'toolbar=no,resizable=yes,scrollbars=yes');
}			
function ManageProducts_OpenXMLfile(XMLfileURL)
{
	window.open(XMLfileURL, 'XMLfileWindow', 'toolbar=no,resizable=yes,scrollbars=yes');
}

