//To make textbox input always in upper case
function makeUpper(obj) {
	obj.value = obj.value.toUpperCase();
}
//Trim text
function textTrim(to_trim)
{
	var str = to_trim;

	// Triming spaces on the left
	str = str.replace(/^\s+/, "");

	// Triming spaces on the right
	str = str.replace(/\s+$/, "");

	return str;
}
//To show hide menu items
//param id_to_show = id of the element which should be visible
//param ids_to_hide = comma separated ids of the elements which should be hide
function showHideSubMenu(id_to_show, ids_to_hide) {
	//Hide
	var arr_id = ids_to_hide.split(',');
	for(i=0;i<arr_id.length;i++) {
		var id = textTrim(arr_id[i]);
		var obj = document.getElementById(id);
		var objImage = document.getElementById(id+'Image');
		if(obj!=null) {
			obj.style.display = 'none';
		}
		if(objImage!=null) {
			objImage.src = 'hpimages/collapse_arrow.gif';
		}
	}
	//Show
	var objShow = document.getElementById(id_to_show);
	var objShowImage = document.getElementById(id_to_show+'Image');
	if(objShow!=null) {
		objShow.style.display = (objShow.style.display=='none')?'block':'none';
	}
	if(objShowImage!=null) {
		objShowImage.src = (objShow.style.display=='none')?'hpimages/collapse_arrow.gif':'hpimages/expand_arrow.gif';
	}
}
//To set form action on home.html
function setFormAction(frm) {
//Basic validation of zipcode
// 1. It should be 5 digit number
	if (frm.txtZipBox.value.length<5 || isNaN(frm.txtZipBox.value) || new Number(frm.txtZipBox.value) < 0) {
		alert('Please enter valid zip code.');
		frm.txtZipBox.value='';
		frm.txtZipBox.focus();
		return false;
	}

	document.hdForm.action = frm.selInsuranceType.value;

	if(frm.selInsuranceType.value == 'Renters')
	{
		currOwn = document.createElement("input");
		currOwn.type = "hidden";
		currOwn.name = "currOwn1";
		currOwn.value = "N";
		document.hdForm.appendChild(currOwn);
		document.hdForm.action = '/home-insurance/';
	}

	document.hdForm.zipcode.value = frm.txtZipBox.value;
	document.hdForm.submit();

	
}
//To go to filename specified
function validateZipCode(frm) {
//Basic validation of zipcode
// 1. It should be 5 digit number
	if (frm.txtZipBox.value.length<5 || isNaN(frm.txtZipBox.value) || new Number(frm.txtZipBox.value) < 0) {
		alert('Please enter valid zip code.');
		frm.txtZipBox.value='';
		frm.txtZipBox.focus();
		return false;
	}
	return true;
}

//To be used in menu
function goToUrl(filename) {
	var arr_url = document.URL.split('/');
	arr_url[arr_url.length-1] = filename;
	document.location = arr_url.join('/');
}
//OPen popup window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//Alter Check Boxes
function alterCheckBoxes(frm, id, value) {
	for(i=0; i<frm.elements.length; i++) {
		if (frm.elements[i].id == id) {
			frm.elements[i].checked = value;
		}
	}
}
//Check Selection
function checkSelection(frm, id, msg_confirm, alert_msg) {
	for(i=0; i<frm.elements.length; i++) {
		if (frm.elements[i].id == id) {
			if(frm.elements[i].checked) {
				return confirm(msg_confirm);
			}
		}
	}
	alert(alert_msg);
	return false;
}

function checkSelection_withoutconfirm(frm, id,alert_msg) {
	for(i=0; i<frm.elements.length; i++) {
		if (frm.elements[i].id == id) {
			if(frm.elements[i].checked) {
				return true;
			}
		}
	}
	alert(alert_msg);
	return false;
}
// Check for valid Zip Code 
// 1. Should be 5 characters long
// 2. Should be all digits.
// 3. Should not contain negative numbers. 
function checkValidZipCode_US(zipcodeField)
{
   if (zipcodeField.value.length<5 || isNaN(zipcodeField.value) || new Number(zipcodeField.value) < 0) {
		alert('Please enter valid zip code.');
		zipcodeField.value='';
		zipcodeField.focus();
		return false;
	}
	return true;
}

//Begin Mantis Task#73
function checkPhone_ValidZipCode(frm)
{
	if(textTrim(frm.dayPhone.value)=='')
	{
		alert("Please enter Daytime Telephone number.")
		frm.dayPhone.focus();
		return false;
	}
	return checkValidZipCode_US(frm.contZip);
}
//End Mantis Task#73

//Begin Mantis Task#74
function checkPhone(frm)
{
	if(frm.dayPhone.value!='' || frm.dayPhone.value!= null){
		if(textTrim(frm.dayPhone.value)=='')
		{
			alert("Please enter Daytime Telephone number.")
			frm.dayPhone.focus();
			return false;
		}
		else
		return true;	
	}
	else
		return false;
}
//End Mantis Task#74
//Patch function: to be removed
function setContactValue(obj) {

}