//function to open new window
function RequestInfo(pProduct)
{
	openwin('/contactus/contact.asp?reqinfo=true&prod=' + pProduct,500,500);
}

function ContactUs(pProduct)
{
	openwin('/contactus/contact.asp?email=true&prod=' + pProduct,500,500);
}

function CallBack(pProduct)
{
	openwin('/contactus/contact.asp?callback=true&prod=' + pProduct,500,500);
}

function MyPolicyUpdate()
{
	openwin('/members/mypolicy_update.asp',500,500);
}

function openwin(strUrl,intWidth,intHeight)
{
	intLeft = (window.screen.availWidth / 2) - (intWidth/2);
	intTop = (window.screen.availHeight / 2) - (intHeight/2); 
			
	ref = window.open(strUrl,"newWin","width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft + ",top=" + intTop + ",screenX=" + intLeft + ",screenY=" + intTop + ",toolbar=no,menubar=yes,status=yes,location=no,resizable=yes,scrollbars=yes");
	ref.focus();
	ref.resizeTo(intWidth,intHeight);
	ref.moveTo(intLeft,intTop);
	ref.focus();
}

function newWindow(page)
{
	window.open('/quote/app-forms/' + page,'Details','scrollbars=yes,menubar=yes,status=yes,location=no,width=800,height=' + window.screen.availHeight + ',top=0,left=0')
}

function newWin(page)
{
	window.open(page,'Details','scrollbars=yes,menubar=yes,status=yes,location=no,width=800,height=' + window.screen.availHeight + ',top=0,left=0')
}

function IsEmpty(field)
{
	if(field.value!="")
	{
		return false;
	}
	return true;
}

function IsEmail(emailAddress) 
{
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function IsPhoneNumber(field) 
{
	var valid = "0123456789- +"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if ((ok == "no")||((field.value.length<=4)&&(field.value.length>0))) 
	{
		return false;
  	}
	return true;
}

function CheckEmail(field)
{
	if (IsEmpty(field))
	{
		alert ('Please include an email address!');
		return false;
	}
	
	if (!IsEmail(field.value))
	{
		alert ('Please check that the email address is valid');
		return false;
	}

	return true;
}

function CheckPhone(field)
{
	if (IsEmpty(field))
	{
		alert('Please include a phone number');
		return false;
	}
	
	if (!IsPhoneNumber(field))
	{
		alert('Please check that your phone number is valid');
		return false;
	}
	
	return true;
}

function IsValidDate(dayref,monthref,yearref)
{
		
	var day = dayref.value
	var month = new String(monthref.value);
	month = month.toLowerCase();
	var year = yearref.value;
	var isleap = "false";
				
	//Check that the startdate is a valid date		
	if (month=="apr" || month=="jun" || month=="sep" || month=="nov")
	{
		if (day>30) 
		{
			alert("You have entered an invalid date! This month cannot have 31 days");
			dayref.focus();
			return false;
		}
	}
	else if (month=="feb") 
	{
		//Calculate whether the year is a leap year	
		if ((year%4) != 0 )
			isleap = "FALSE";
		else if ((year%400) == 0 )
			isleap = "TRUE";
		else if ((year%100) == 0 )
			isleap = "FALSE";
		else
			isleap = "TRUE";
								
		if (isleap == "FALSE")
		{
			if (day>28) 
			{
				alert("You have entered an invalid date! February cannot have more than 28 days in this year.");
				dayref.focus();
				return false;
			}
		}
		else
		{
			if (day>29) 
			{
				alert("You have entered an invalid date! February cannot have more than 29 days.");
				dayref.focus();
				return false;
			}
		}
	}
	
	return true;
}

function IsValidDateRange(fdayref,fmonthref,fyearref,tdayref,tmonthref,tyearref)
{
	fromdate = new Date(fyearref.value,GetMonthAsInt(fmonthref.value),fdayref.value);
	todate = new Date(tyearref.value,GetMonthAsInt(tmonthref.value),tdayref.value);
	if(fromdate > todate)
	{
		return false;
	}
	return true;
}

function GetMonthAsInt(month)
{
	//NOTE: the Date object requires the month as an integer between 0 - 11
	var imonth;
	var tmonth = month.toLowerCase( );
	switch(tmonth)
	{
		case "jan":
			imonth=0
			break;
		case "feb":
			imonth=1
			break;
		case "mar":
			imonth=2
			break;
		case "apr":
			imonth=3
			break;
		case "may":
			imonth=4
			break;
		case "jun":
			imonth=5
			break;
		case "jul":
			imonth=6
			break;
		case "aug":
			imonth=7
			break;
		case "sep":
			imonth=8
			break;
		case "oct":
			imonth=9
			break;
		case "nov":
			imonth=10
			break;
		case "dec":
			imonth=11
			break;
	}
	return imonth;
}

function CheckIsLegalPassword(pw)
{
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-@. ";
	var temp;
	
	for (var i=0; i<pw.length; i++) 
	{
		temp = "" + pw.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;
}

function CheckIsNumericInteger(field)
{
	var validchars = "0123456789";
	var temp;
	
	for (var i=0; i<field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;
}
function CheckIsNumericDecimal(field)
{
	var validchars = "0123456789.";
	var temp;
	
	for (var i=0; i<field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;
}

function CheckIsNumericDecimal2DP(field)
{
	var temp;
	var dot = "." ;
	var decplaces = -1 ;
	var startcount = false;
	
	for (var i=0; i<field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
	    if (dot.indexOf(temp) != "-1") 
		{
			startcount = true;
	    }		
		if(startcount == true)
		{
			decplaces++;
		}
		
	}
	
	if(startcount == true)
	{
		if(decplaces > 2)
		{
			return false;
		}
	}	
	return true;
}

function popwin(page,width,height,top,left)
{
	var popup;
	var w = width;
	var h = height;			
	var t;
	if(top<0){
		t = (window.screen.height-h)/2;
	}else{
		t = top;
	}
	var l;
	if(left<0){
		l = (window.screen.width-w)/2;
	}else{
		l = left;
	}
	popup = window.open(page,'page','width='+ w +',height='+ h +',top='+ t +',left='+ l + ",scrollbars=yes");
	popup.focus();
	return;
}
function PrintPage()
{	
	document.getElementById('loginrow').style.display = 'none';
	document.getElementById('logorow').style.display = 'none';
	document.getElementById('navrow').style.display = 'none';
	document.getElementById('submenu').style.display = 'none';
	document.getElementById('topbuttons').style.display = 'none';
	document.getElementById('bottombuttons').style.display = 'none';
	document.getElementById('footernav').style.display = 'none';	
	document.getElementById('footernav2').style.display = 'none';	
	if(document.getElementById('isifa').value != "")
	{
		document.getElementById('earlyyearsprintgap').style.display = 'block';	
	}
	else
	{
		document.getElementById('earlyyearsprintgap2').style.display = 'block';	
	}	
	/*window.print();
	document.getElementById('loginrow').style.display = 'block';
	document.getElementById('logorow').style.display = 'block';
	document.getElementById('navrow').style.display = 'block';
	document.getElementById('submenu').style.display = 'block';
	document.getElementById('topbuttons').style.display = 'block';
	document.getElementById('bottombuttons').style.display = 'block';
	document.getElementById('footernav').style.display = 'block';
	document.getElementById('footernav2').style.display = 'block';
	if(document.getElementById('isifa').value != "")
	{
		document.getElementById('earlyyearsprintgap').style.display = 'none';	
	}
	else
	{
		document.getElementById('earlyyearsprintgap2').style.display = 'none';	
	}	*/
}