var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;

function setSrc(id, url) {
  if (NS4) {eval("document." + id + ".document." + id).src = url}
  else if (IE4) {eval("document.all." + id).src = url}
       else if (IE5 || N6) {document.getElementById(id).src = url};
}

function showHide(object) {

    if (document.getElementById && document.getElementById(object) != null){
		if (document.getElementById(object).style.display == 'none'){
	        document.getElementById(object).style.display ='';
	    }else {
	        document.getElementById(object).style.display ='none';
	    }
	}else if (document.layers && document.layers[object] != null){
        if (document.layers[object].visibility == 'hidden'){
			document.layers[object].visibility = 'visible'
		}else {
			document.layers[object].visibility = 'hidden'
		}
	}else if (document.all){
		if (document.all[object].style.display == 'none'){
			document.all[object].style.display = '';
		}else {
			document.all[object].style.display = 'none';
		}
	}
}

function showHideByAction(object,Action) {
    if (document.getElementById && document.getElementById(object) != null){
	        document.getElementById(object).style.display = (Action == 'show') ? '' : 'none';
	}else if (document.layers && document.layers[object] != null){
			document.layers[object].visibility = (Action == 'show') ? 'visible' : 'hidden';
	}else if (document.all){
			document.all[object].style.display = (Action == 'show') ? '' : 'none';
	}
}

function enableDisableByAction(object,Action) {
	
    if (document.getElementById && document.getElementById(object) != null){
        document.getElementById(object).disabled = (Action == 'show') ? false : true;
	}
	else if (document.layers && document.layers[object] != null){
			document.layers[object].disabled = (Action == 'show') ? false : true;
	}
	else if (document.all){
			document.all[object].disabled = (Action == 'show') ? false : true;
	}
}

function showHideExt(object,img) {

    if (document.getElementById && document.getElementById(object) != null){
		if (document.getElementById(object).style.display == 'none'){
	        document.getElementById(object).style.display ='';
	        setSrc(img,"img/skicover/prodselect_exp.gif");
	    }else {
	        document.getElementById(object).style.display ='none';
	        setSrc(img,"img/skicover/prodselect_min.gif");
	    }
	}else if (document.layers && document.layers[object] != null){
        if (document.layers[object].visibility == 'hidden'){
			document.layers[object].visibility = 'visible'
	        setSrc(img,"img/skicover/prodselect_exp.gif");
		}else {
			document.layers[object].visibility = 'hidden'
			setSrc(img,"img/skicover/prodselect_min.gif");
		}
	}else if (document.all){
		if (document.all[object].style.display == 'none'){
			document.all[object].style.display = '';
	        setSrc(img,"img/skicover/prodselect_exp.gif");
		}else {
			document.all[object].style.display = 'none';
			setSrc(img,"img/skicover/prodselect_min.gif");
		}
	}
}

function DoExpand(divt,divd)
{
	showHide(divd)
	showHide(divt)
}

function DoExpandExt(divt,divd,img)
{
	showHideExt(divt,img)
	showHide(divd)
}

function setDates(Type)
{
	
	var iDay   = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateDay').value;
	var iMonth = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateMonth').value;
	var iYear  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateYear').value;
	var pType  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'PolicyType').value
	
	if (pType == 3)
	{
		if (iDay == 1)	iDay = 32;
		
		if (iDay == 32 && iMonth == 1){ 
			iMonth = 12;
			iYear -= 1;
		}else if (iDay == 32){ 
			iMonth -= 1
		}
		if (iDay==32   && iMonth==2) iDay=29
		if ((iDay==32) && (iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11)) iDay=31
		
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = --iDay;
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = iMonth;
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = ++iYear;
	}
	
	if (pType == 1)
	{
		var cDate = new Date(iMonth.toString() + '/' + iDay.toString() + '/' + iYear.toString());

		var nDate = GetDateAfterDays(cDate,1);
		
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = nDate.getDate()
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = nDate.getMonth() + 1
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = nDate.getFullYear()
	}
}

function GetDateAfterDays(currdate,days)
{	
	var oneday = 60 * 1000 * 60 * 24 ;
	var daysafter = parseInt(days);
	var currdatems = currdate.getTime();

	var addms = oneday * daysafter;

	var daysafterdate = new Date();
	daysafterdate.setTime(currdatems + addms);
	return daysafterdate;
}


function setDatesEVA(Type)
{
	
	var iDay   = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateDay').value;
	var iMonth = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateMonth').value;
	var iYear  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateYear').value;

	var cDate = new Date(iMonth.toString() + '/' + iDay.toString() + '/' + iYear.toString());
	var nDate = GetDateAfterDays(cDate,1);

	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = nDate.getDate()
	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = nDate.getMonth() + 1
	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = nDate.getFullYear()
}

function EnableDisableControls(ddlCoverFor,Type)
{
	DisableControls(Type);
	
	var PolicyType  = eval('document.frmPageForm.cntrlInsSearch_ddl'+ Type +'PolicyType').value;
	
	switch (ddlCoverFor)
	{
		case '1':
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Infants').value = 0;
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Children').value = 0;
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 1;
			break;
		case '2':
		
			switch (PolicyType)
				{
					case '1':
						enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Infants','show');			
						eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Children').value = 0;
						eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 2;
						break;
					default :
						enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Infants','hide');			
						eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Children').value = 0;
						eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 2;
						break;
				}
				break;
				
			break;
		case '3':
			enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Infants','show');			
			enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Children','show');			
	
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 1;
			break;
		case '4':
			enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Infants','show');			
			enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Children','show');	
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 2;
			break;	
		case '5':
			enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Adults','show');
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Infants').value = 0;
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Children').value = 0;
			break;
	}
}

function ShowHideSelection(ddlCoverFor,Type)
{
	EnableDisableControls(ddlCoverFor,Type);

	if (Type == ''){
		showHideByAction('insSearch','show');
		showHideByAction('evaSearch','hide');

		switch (ddlCoverFor)
		{
			case '6':
				showHideByAction('insSearch','hide');
				showHideByAction('evaSearch','show');
		}
	}
}


function DisableControls(Type)
{
	enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Infants','hide');			
	enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Children','hide');	
	enableDisableByAction('cntrlInsSearch_ddl' + Type + 'Adults','hide');			
}

function ResetSelection(Type)
{
	ShowHideSelection(eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'CoverFor').value,Type)

}

