/*----------------------------------------------------------------------------------
*  File Name:	    TradingPartner.js
*
*  Description:  This file contains Trading Partner form functions.
*
*
*                    Mod Log
*| Author          | Date         | Authorization | Description
*|-----------------|--------------|---------------|---------------------------------
*| Brad Coon       | 02/06/2003   |               | Initial Development
*| Debbie Bowen	   | 05/10/2004   | CO #355       | Revised Companion Guide file name
*| Brad Coon       | 07/13/2003   | CO #289       | Added validation to validate() for
*|                                                  reset question and answer fields.
*----------------------------------------------------------------------------------*/



/*--------------------------------------------------------------------------------
*  Function:     showDivTags & openCompGuides
*
*  Description:  These functions control the profile pages from radio buttons
*
*  Notes:
*
*  Return Value: None
*
*  Input Parms:  div_id
*
*                    Mod Log
*| Author          | Date       | Authorization | Description
*|-----------------|------------|---------------|-------------------------------
*| Brad Coon       | 02/06/03   |               | Initial Development
*| Debbie Bowen	   | 05/10/2004 | CO #355       | Revised Companion Guide file name
*
*-------------------------------------------------------------------------------*/
function showDivTags(div_id) {
	location.href = "/ihcp/TradingPartner/TP_Profile_" + div_id + ".asp"
}

function openCompGuides() {
	
	NewWindow('tp_companion_guides.asp', 'myname', '700', '400');
}

	

/*--------------------------------------------------------------------------------
*  Function:     checkUpperBox
*
*  Description:  This function controls the auto checking feature fro all transactions
*
*  Notes:  This function is really a Heirarchial checkboxing
*
*  Return Value: None
*
*  Input Parms:  checkBoxName1, checkBoxName2, checkBoxName3
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon      | 02/06/03 | 				       | Initial Development
*
*-------------------------------------------------------------------------------*/
function checkUpperBox(checkBoxName1, checkBoxName2, checkBoxName3) {

	if ((checkBoxName1 == checkBoxName3) || (checkBoxName2 == checkBoxName3)) {
		if (document.tp_profile.elements[checkBoxName3].checked == true) {
			 document.tp_profile.elements[checkBoxName3].checked = true;
			 
			document.tp_profile.elements[checkBoxName1].checked = true;
		}
		else if (document.tp_profile.elements[checkBoxName3].checked == false) {
			document.tp_profile.elements[checkBoxName3].checked = false;
			 	
			for (i = 0; i < document.tp_profile.elements.length; i++) {
				var checkBoxName = document.tp_profile.elements[i].name.match(checkBoxName1);
		
				if (checkBoxName == null) {	}
				else {
					document.tp_profile.elements[i].checked = false;
				}
			}
			if (checkBoxName2 == checkBoxName3) {
				document.tp_profile.elements[checkBoxName1].checked = true;
			}
		}
	}
	else {
		for (i = 0; i < document.tp_profile.elements.length; i++) {
			var checkBoxName = document.tp_profile.elements[i].name.match(checkBoxName1);
		
			if (checkBoxName == null) {	}
			else {
				document.tp_profile.elements[i].checked = false;
			}
		}
		document.tp_profile.elements[checkBoxName1].checked = true;
		document.tp_profile.elements[checkBoxName2].checked = true;
		document.tp_profile.elements[checkBoxName3].checked = true;
	}
}



/*--------------------------------------------------------------------------------
*  Function:     setReturnField & returnName
*
*  Description:  These functions capture the profile 'Company Name' field name and 
*	returns the Company name value from the company name pop-up
*
*  Notes:  
*
*  Return Value: None
*
*  Input Parms:  companyField & companyNameOut
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon      | 02/06/03 | 				       | Initial Development
*
*-------------------------------------------------------------------------------*/
var returnField;

function setReturnField(companyField) {
returnField = companyField;

}

function returnName(companyNameOut) {

    document.tp_profile.elements[returnField].value = companyNameOut;
	document.tp_profile.elements[returnField].focus();
}





/*--------------------------------------------------------------------------------
*  Function:     tabNext
*
*  Description:  This function allows the user's cursor to jump fields after the 
*	number of pre-defined characters has been met.
*
*  Notes:  
*
*  Return Value: None
*
*  Input Parms:  obj,event,len,next_field
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon      | 02/06/03 | 				       | Initial Development
*
*-------------------------------------------------------------------------------*/
var phone_field_length = 0;

function tabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
	}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}




/*--------------------------------------------------------------------------------
*  Function:     checkKey & noSubmit
*
*  Description:  These functions control whether or not to allow the TAB 
*	key to function. The key is disabled when the TAB key could cause
* 	unwanted selection of transactions
*
*  Notes:  
*
*  Return Value: None
*
*  Input Parms:  tabSwitch
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon      | 02/06/03 | 				       | Initial Development
*
*-------------------------------------------------------------------------------*/

//------------Netscape check----------------
var ver = navigator.appVersion;
var len = ver.length;
var netscape = "";

for(iln = 0; iln < len; iln++) {
	if (ver.charAt(iln) == "(") {
		break;
		netscape = (ver.charAt(iln+1).toUpperCase() != "C");
	}
}
//--------------End check-------------------
var tabState = '';

function checkKey(tabSwitch) {
	tabState = tabSwitch;
}

function noSubmit() { 
	var key = (netscape) ? DnEvents.which : window.event.keyCode;
	
	if (key == 13) {
		event.returnValue=false;
	} 
	
	if (key == 9) {
		if (tabState == 'off') {
			event.returnValue = false;
		}
	}
} 




/*--------------------------------------------------------------------------------
*  Function:     validate
*
*  Description:  This function check to make sure that fields are filled in properly
*
*  Notes:  
*
*  Return Value: None
*
*  Input Parms:  None
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon      | 02/06/03 | 				       | Initial Development
*
*-------------------------------------------------------------------------------*/
function validate() {

	if (document.tp_profile.company_name.value == "") {
		alert ("Please enter your Company Name for Trading Partner validation");
		document.tp_profile.company_name.select();
		return false;
	}
	else {
		document.tp_profile.company_name.value = document.tp_profile.company_name.value.replace(/[<>\'\"]/g, "");
	}

	if (document.tp_profile.name.value == "") {
		alert ("Please enter your Contact Name for Trading Partner validation");
		document.tp_profile.name.select();
		return false;
	}
	else {
		document.tp_profile.name.value = document.tp_profile.name.value.replace(/[<>\'\"]/g, "");
	}
	
	if (document.tp_profile.address.value == "") {
		alert ("Please enter your Address for Trading Partner validation");
		document.tp_profile.address.select();
		return false;
	}
	else {
		document.tp_profile.address.value = document.tp_profile.address.value.replace(/[<>\'\"]/g, "");
	}
	
	if (document.tp_profile.city.value == "") {
		alert ("Please enter your City for Trading Partner validation");
		document.tp_profile.city.select();
		return false;
	}
	else {
		document.tp_profile.city.value = document.tp_profile.city.value.replace(/[<>\'\"]/g, "");
	}
	
	if ((document.tp_profile.zip.value == "") || (document.tp_profile.zip.value.length < 5)) {
		alert ("Please complete your Zip Code for Trading Partner validation");
		document.tp_profile.zip.select();
		return false;
	}
	
	if ((document.tp_profile.phone_num_area.value == "") || (document.tp_profile.phone_num_area.value.length < 3)) {
		alert ("Please complete your Telephone Area Code and Number for Trading Partner validation");
		document.tp_profile.phone_num_area.select();
		return false;
	}
	
	if ((document.tp_profile.phone_num_first.value == "") || (document.tp_profile.phone_num_first.value.length < 3)) {
		alert ("Please complete your Telephone Area Code and Number for Trading Partner validation");
		document.tp_profile.phone_num_first.select();
		return false;
	}
	
	if ((document.tp_profile.phone_num_last.value == "") || (document.tp_profile.phone_num_last.value.length < 4)) {
		alert ("Please complete your Telephone Area Code and Number for Trading Partner validation");
		document.tp_profile.phone_num_last.select();
		return false;
	}
	
	if (document.tp_profile.ResetQuestion1.value == "0") {
		alert ("Please select your first File Exchange reset question");
		document.tp_profile.ResetQuestion1.focus();
		return false;
	}
	
	if (document.tp_profile.ResetResponse1.value == "") {
		alert ("Please enter an answer to the first reset question");
		document.tp_profile.ResetResponse1.focus();
		return false;
	}
	else {
		document.tp_profile.ResetResponse1.value = document.tp_profile.ResetResponse1.value.replace(/[<>\'\"]/g, "");
	}
	
	if (document.tp_profile.ResetQuestion2.value == "0") {
		alert ("Please select your second File Exchange reset question");
		document.tp_profile.ResetQuestion2.focus();
		return false;
	}
	
	if (document.tp_profile.ResetResponse2.value == "") {
		alert ("Please enter an answer to the second reset question");
		document.tp_profile.ResetResponse2.focus();
		return false;
	}
	else {
		document.tp_profile.ResetResponse2.value = document.tp_profile.ResetResponse2.value.replace(/[<>\'\"]/g, "");
	}
	
	//if (document.tp_profile.email.value == "") {
		//alert ("Please enter your E-mail address for Trading Partner validation");
		//document.tp_profile.email.select();
		//return false;
	//}
	//else{
		//  This e-mail verification function came from www.javascript.internet.com
		//  Essentially, it makes sure the format is XXX@XXX.XXX 
		//if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.tp_profile.email.value))) {
			//alert("Please correct your E-mail address for Trading Partner validation.   Ex: JoeMedicaid@IndyISP.com");
			//document.tp_profile.email.select();
			//return false;
		//}
	//}
}