// function set used on registration form

function new_window(url) 
{ link3 = window.open(url,"Link3","toolbar=0,location=0,directories=0,status=o,menubar=0,scrollbars=1,resizable=1,width=780,height=550"); }

function checkInput(str)
{
// remove beginning space characters
	while(''+ str.charAt(0)== ' ')
		str = str.substring(1,str.length);

	if(str.length == 0 || str == "" || str == null)
	{
		return false;
	}
}

function containSpace(str)
{
// check if the string contain space
    if (str.indexOf(' ') >= 0) return true
    else return false
}

function isnumber(string)
{
	str = string + ''

	for (var i = 0; i < str.length; i++)
	{
		if (str.substring(i,i+1) == '.' || string < 0)
		{
			return true
		}
	}

	return false
}

function changeToOther(itemname)
{
// This function works with a dropdown list with "Other" as an option and freeform "Other" field.
// When "Other" is selected, there is a "If other, please specify" field will be enabled and turned white;
// Otherwise, the "If other, please specify" field will be disabled and turned grey.
// parameter itemname is the name of the dropdown list. The "Other" field has to be named as itemname+'other'.

	if (eval('document.forms[0].'+itemname+'.value == "Other"'))
	{
		eval('document.forms[0].'+itemname+'other.disabled = false');
		eval('document.forms[0].'+itemname+'other.style.backgroundColor = "white"');
	}
	else
	{
		eval('document.forms[0].'+itemname+'other.value=""');
		eval('document.forms[0].'+itemname+'other.disabled = true');
		eval('document.forms[0].'+itemname+'other.style.backgroundColor = "lightgrey"');
	}
}

function openOtherBroker()
{
     if(document.forms[0].broker.options[document.forms[0].broker.selectedIndex].value == 'OTHER')
     {
          document.forms[0].OtherBroker.disabled = false;
          document.forms[0].OtherBroker.style.backgroundColor = '#ffffff';
     }
     else
     {
          document.forms[0].OtherBroker.disabled = true;
          document.forms[0].OtherBroker.style.backgroundColor = 'lightgrey';
          document.forms[0].OtherBroker.value = '';
     }
}

function openOtherInsurer()
{
     if(document.forms[0].insurer.options[document.forms[0].insurer.selectedIndex].value == 'OTHER')
     {
          document.forms[0].OtherInsurer.disabled = false;
          document.forms[0].OtherInsurer.style.backgroundColor = '#ffffff';
     }
     else
     {
          document.forms[0].OtherInsurer.disabled = true;
          document.forms[0].OtherInsurer.style.backgroundColor = 'lightgrey';
          document.forms[0].OtherInsurer.value = '';
     }
}

function getTerms(url)
{
	nwin = window.open(url,'NewWindow','toolbar=no,status=no,scrollbars=yes,resizable=no,width=700,height=625,left=50,top=10') ;
}

function setPhoneStyle(cCountryValue)
{
	/* This function sets style of phone/fax field */

	// get North American style object
	objNA = document.getElementById('naphone');
	// get other style object
	objOther = document.getElementById('otherphone');
		
	if (cCountryValue == 'CANADA' || cCountryValue == 'U.S.A.')
	{
		// show North American style 
		objNA.style.visibility = 'visible';
		objNA.innerHTML = '(<input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'phone2'" + ')" size="2" maxlength="3" name="phone1" value="">) <input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'phone3'" + ')" size="2" maxlength="3" name="phone2" value="">-<input type="text" class="inputTxt" size="3" maxlength="4" name="phone3" value="">';
		document.forms[0].phone1.value = document.forms[0].phonevalue.value.replace(/[^0-9]/g, '').substr(0,3);
		document.forms[0].phone2.value = document.forms[0].phonevalue.value.replace(/[^0-9]/g, '').substr(3,3);
		document.forms[0].phone3.value = document.forms[0].phonevalue.value.replace(/[^0-9]/g, '').substr(6,4);
		// hide free from style
		objOther.style.visibility = 'hidden';
		objOther.innerHTML = '';
	}
	else{
		// show free form style
		objOther.style.visibility = 'visible';
		objOther.innerHTML = '<input type="text" class="inputTxt" size="16" name="phone" value="">';
		document.forms[0].phone.value = document.forms[0].phonevalue.value;
		// hide North American style
		objNA.style.visibility = 'hidden';
		objNA.innerHTML = '';
	}	

	/* set cell phone */
	// get North American style object
	objNA = document.getElementById('nacell');
	// get other style object
	objOther = document.getElementById('othercell');
	if (cCountryValue == 'CANADA' || cCountryValue == 'U.S.A.')
	{
		// show North American style
		objNA.style.visibility = 'visible';
		objNA.innerHTML = '(<input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'cell2'" + ')" size="2" maxlength="3" name="cell1" value="">) <input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'cell3'" + ')" size="2" maxlength="3" name="cell2" value="">-<input type="text" class="inputTxt" size="3" maxlength="4" name="cell3" value="">';
		document.forms[0].cell1.value = document.forms[0].cellvalue.value.replace(/[^0-9]/g, '').substr(0,3);
		document.forms[0].cell2.value = document.forms[0].cellvalue.value.replace(/[^0-9]/g, '').substr(3,3);
		document.forms[0].cell3.value = document.forms[0].cellvalue.value.replace(/[^0-9]/g, '').substr(6,4);
		// hide free from style		
		objOther.style.visibility = 'hidden';
		objOther.innerHTML = '';
	}
	else{
		// show free form style
		objOther.style.visibility = 'visible';
		objOther.innerHTML = '<input type="text" class="inputTxt" size="16" name="cell" value="">';
		document.forms[0].cell.value = document.forms[0].cellvalue.value;
		// hide North American style
		objNA.style.visibility = 'hidden';
		objNA.innerHTML = '';
	}	
	
	/* set fax */
	// get North American style object
	objNA = document.getElementById('nafax');
	// get other style object
	objOther = document.getElementById('otherfax');
		
	if (cCountryValue == 'CANADA' || cCountryValue == 'U.S.A.')
	{
		// show North American style 
		objNA.style.visibility = 'visible';
		objNA.innerHTML = '(<input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'fax2'" + ')" size="2" maxlength="3" name="fax1" value="">) <input type="text" class="inputTxt" onkeyup="keyup(this.name,3,' + "'fax3'" + ')" size="2" maxlength="3" name="fax2" value="">-<input type="text" class="inputTxt" size="3" maxlength="4" name="fax3" value="">';
		document.forms[0].fax1.value = document.forms[0].faxvalue.value.replace(/[^0-9]/g, '').substr(0,3);
		document.forms[0].fax2.value = document.forms[0].faxvalue.value.replace(/[^0-9]/g, '').substr(3,3);
		document.forms[0].fax3.value = document.forms[0].faxvalue.value.replace(/[^0-9]/g, '').substr(6,4);
		// hide free from style
		objOther.style.visibility = 'hidden';
		objOther.innerHTML = '';
	}
	else{
		// show free form style
		objOther.style.visibility = 'visible';
		objOther.innerHTML = '<input type="text" class="inputTxt" size="16" name="fax" value="">';
		document.forms[0].fax.value = document.forms[0].faxvalue.value;
		// hide North American style
		objNA.style.visibility = 'hidden';
		objNA.innerHTML = '';
	}	
}

function retainPhone()
{
	// this function is used to retain phone value when country is changed
	if (document.forms[0].country.value == 'CANADA' || document.forms[0].country.value == 'U.S.A.')
	{
		document.forms[0].phonevalue.value = document.forms[0].phone1.value + document.forms[0].phone2.value + document.forms[0].phone3.value;
		document.forms[0].cellvalue.value = document.forms[0].cell1.value + document.forms[0].cell2.value + document.forms[0].cell3.value;
		document.forms[0].faxvalue.value = document.forms[0].fax1.value + document.forms[0].fax2.value + document.forms[0].fax3.value;
	}
	else
	{
		document.forms[0].phonevalue.value = document.forms[0].phone.value;
		document.forms[0].cellvalue.value = document.forms[0].cell.value;
		document.forms[0].faxvalue.value = document.forms[0].fax.value;
	}
}

