//<script>
function CForm() {
	/* data members */
	this.frm			= window.document.forms[0];		//default form reference
	this.confirmExit    = true;							//trigger to confirm exit of page
	
	/* member functions */
	this.setProperty	   = setProperty;					//sets class property for given id
	this.disable		   = disable;						//enables/disables given field id
	this.parsePolicyNumber = parsePolicyNumber;				//parses a policy number
	this.handlePolicyEntry = handlePolicyEntry;				//provides easier policy number input
	this.CancelNOL         = CancelNOL;						//handles cancellation of NOLs
}

function setProperty( tagName,id, value ) {
	try {
		//Step 1: get tag references
		var tags = document.getElementsByTagName(tagName);
		//Step 2: set class value for each reference
		for ( var i = 0; i < tags.length; i++ ) {
			if(tags[i].id == id || tags[i].name == id)
			{
				//IE
				if(window.event) {
    					if ( tags[i].className != value ) tags[i].className = value;
  				}
  				//MOZ
  				else {
				
    					if ( tags[i].getAttribute('class') != value ) tags[i].setAttribute("class", value);
  				}
			}
			
		}
	} catch( exception ) {
		var error = new CError();
		error.handleError( error.ECLAIMS_ERR_FORM, exception.message, "CForm::setProperty");
		delete(error);
	} finally {
	}
}

function disable(tagName, id, value ) {
	try {
		//Step 1: get tag references
		var tags = document.getElementsByTagName( tagName );
		
		//Step 2: disable each reference
		for (var i = 0; i < tags.length; i++ ) 
		{
			if(tags[i].id == id || tags[i].name == id)
			{
				tags[i].disabled = value;
			}
		}
	} catch( exception ) {
	
	} finally {
	}
}

function handlePolicyEntry( objRef, e ) {
	try {	
		var unicode = (e.keyCode)? e.keyCode: e.charCode;
		var frm    = document.forms[document.forms.length-1];
		// I determine if anything is highlighted if so then allow the replacing of the data
		if ( document.selection.createRange().text.length > 0 ){
			return false;
		}

		// Determine if user has hit a arrow or delete, backspace key	
		// KeyCode 8 = Backspace Key	KeyCode 46= Delete Key
		// KeyCode 39= Right Arrow Key	KeyCode 37= Left Arrow Key
		// KeyCode 9 = Tab Key
		if ( unicode == 8 || unicode == 46 || unicode == 37 || unicode == 39 || unicode == 9 || oEvent.shiftKey) {//since we don't use letters in this feild event.shiftKey is ok.
			return	false;
		}	
	
	
		// I will now look at the paticular part of the policynumber to know what to do
		// Region - I will check to see if two character have already been enter
		// State - I will check to see if two character have already been enter
		// Prefix - I will check to see if two character have already been enter
		// PolicyNumber - nothing
		// Note: if something is highlighted I will allow the user to enter data before
		//	moving to the next field
		// Added check to prevent set focus when alpah is type in policy number field
		switch( objRef.name ){
			case "efRO"		:
				if ( objRef.value.length == 2 ) {
					frm.efST.focus();
					var oRange =  frm.efST.createTextRange();
					oRange.findText( frm.efST.value )
					oRange.select();
				}
					break;
			case "efST"		: 
				if ( objRef.value.length == 2 ){
					frm.efPR.focus();
					var oRange =  frm.efPR.createTextRange();
					oRange.findText( frm.efPR.value )
					oRange.select();
				}
				break;
			case "efPR"		: 
				if ( objRef.value.length == 2 && ( ( unicode >= 96 && unicode <= 105 && oEvent.shiftKey == false ) || ( unicode >= 48 && unicode <= 57 && unicode == false) ) ) {
					frm.efPolicyNum.focus();	
					var oRange =  frm.efPolicyNum.createTextRange();
					oRange.findText( frm.efPolicyNum.value )
					oRange.select();
				}
				break;
			case "efPolicyNum":	
				break;
		}		
	} catch( exception ) {
		//ignore
	}
}

function parsePolicyNumber( frm ) { 
	try {
		var policy = frm.efPolicyNumber.value;
		//if policy does not start with a number assume NICOA policy
		
		if ( policy.substring(0,1).match(/^[0-9]+$/) ) {
			frm.efRO.value = policy.substring(0,2);
			frm.efST.value = policy.substring(2,4);
			//reformat the policy number since the policy number passed
			//from mynationwide doesn't have space(s) for prefix
			if ( policy.length == 12 ) {
				frm.efPR.value = policy.substring(4,6);
				frm.efPolicyNum.value = policy.substring(6,12);
			} else if ( policy.length == 11 ) { 
				frm.efPR.value = policy.substring(4,5) + " ";
				frm.efPolicyNum.value = policy.substring(5,11);
			} else if ( policy.length == 10 ) {
				frm.efPR.value = "  ";
				frm.efPolicyNum.value = policy.substring(4,10);
			}
			//Clear Allied fields
			if (frm.efAlliedMajorPfx!=null) {
				frm.efAlliedMajorPfx.value="";
				frm.efAlliedMinorPfx.value="";
				frm.efAlliedPolicyNumber.value="";
			}			
		}
		else if (frm.efAlliedMajorPfx!=null){ //Allied Policy
			if (policy.length>14) {
				frm.efAlliedMajorPfx.value=policy.substring(0,policy.length-14);	
				frm.efAlliedMinorPfx.value=policy.substring(policy.length-14,policy.length-10);
				frm.efAlliedPolicyNumber.value=policy.substring(policy.length-10, policy.length);					
			}
			else {
				frm.efAlliedMajorPfx.value="";	
				frm.efAlliedMinorPfx.value=policy.substring(0,policy.length-10);
				frm.efAlliedPolicyNumber.value=policy.substring(policy.length-10, policy.length);				
			}

			//Clear NW fields
			frm.efRO.value="";
			frm.efST.value="";
			frm.efPR.value="";
			frm.efPolicyNum.value="";
		}

	} catch( exception ) {
	}
}

/******************************************************************************
* NAME: CancelForm()
* AUTH:	Paul Kersey
* DATE: 08/2006
*
* DESC: provide a confirm box for use to check when they try to cancel 
*		the claim
* MODS: 5/24/2007 Li Tan: Modified to make the page goes back to where it was coming from
*		
******************************************************************************/
function CancelNOL(strAuth) {
	if ( confirm(g_oMessage.HandleConfirm(g_oMessage.MSG_ALL_CANCEL)) ) {
		this.confirmExit = false;
		if ( strAuth == 'ClaimsCenter' ) {
			window.location = "http://www.nationwide.com/insurance-claims-center.jsp";
		} else if ( strAuth == 'MYNW' ) {
			window.location = "/mynationwidesecure/";
		}
	} else {
		return false;
	}		
}
//</script>
