/* 
 * @author Summit Saini 
 * @company Ness Technologies Pte Ltd
 * @date 11092004
 * @description Added Javascript function(s) to open POPUP window for spell checker
 */
function LTrim(str) {
	if(str==null) {
		return null;
	}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}
function RTrim(str) {
	if(str==null) {
		return null;
	}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}
function Trim(str) {
	return LTrim(RTrim(str));
}
function spellCheck(url,idx) {
	url = url + idx;
	if (idx == "1") {
		var value=document.inquiry.inquiry_remarks.value;
		if(value != "" && value.length > 0) {
			val = Trim(value);
			if(val == "" && val.length == 0) {
				alert("Please enter some text in \"Write your message to the supplier\" textarea to perform Spell Checking");
				document.inquiry.inquiry_remarks.value="";
			} else {
				if(calChars(document.inquiry.inquiry_remarks)) {
					winPop(url, 400, 600, idx, "yes");
					document.inquiry.openWin1.value="1";
				}
			}
		} else {
			alert("Please enter some text in \"Write your message to the supplier\" textarea to perform Spell Checking");
		}
	} else if(idx == "2") {
		var value=document.inquiry.inquiry_company_information.value;
		if(value != "" && value.length > 0) {
			val = Trim(value);
			if(val == "" && val.length == 0) {
				alert("Please enter some text in \"Tell the supplier about your company\" textarea to perform Spell Checking");
				document.inquiry.inquiry_company_information.value="";
			} else {
				if(calChars(document.inquiry.inquiry_company_information)) {
					winPop(url, 400, 600, idx, "yes");
					document.inquiry.openWin2.value="1";
				}
			}
		} else {
			alert("Please enter some text in \"Tell the supplier about your company\" textarea to perform Spell Checking");
		}
	}
}
function winPop(page,height,width,windowname,scrollbars) {
	params = "height=" + height + ",width=" + width + ",status=yes,toolbar=no,directories=no,menubar=no,location=no,scrollbars=" + scrollbars + ",resizable=yes,top=50,left=50,screenX=50,screenY=50";
	popWindow = open(page,windowname,params);
}
function calChars(txField) {
	var remarks=txField.value;
	if (remarks.length >1500 ) {
		alert("Your message is too long.");
		txField.focus();
		return false;
	}	
	return true;
}	
function checkEmail(theField, fieldName, hideField) {
	if (Trim(theField.value).length>0 && checkForEmailError(theField.value)>0) {
		var errCode = checkForEmailError(theField.value);
		if (errCode == 1) {
			showBox(fieldName+"1");
			hideBox(fieldName+"2");
		} else if (errCode == 2) {
			showBox(fieldName+"2");
			hideBox(fieldName+"1");
		}
        theField.value = "";
        theField.select();
        theField.focus();
		return false;
	} else {
		hideBox(fieldName+"1");
		hideBox(fieldName+"2");
	}
	return true;
}
function changeAction() {
	var updprofile = document.inquiry.update_user_info;
	var updchecked = false;
	if(updprofile!=null) {
		if(updprofile.checked==true) {
			document.inquiry.update_user_profile.value = "yes";
			updchecked = true;
		} else {
			document.inquiry.update_user_profile.value = "no";
			updchecked = false;
		}
	}
	var origemail = document.inquiry.originalemail.value;
	var inputemail = document.inquiry.contact_detail_email.value;
	var isLoggedInUser = document.inquiry.isLoggedIn.value;
	if(((origemail!=inputemail)||(updchecked==true))&&(isLoggedInUser=="true")) {
		document.inquiry.action = document.inquiry.actionToSSO.value;
	} else {
		document.inquiry.action = document.inquiry.formaction.value;
	}
	if (document.inquiry.AGG_single_inq!=null && document.inquiry.AGG_single_inq!=undefined) {
		document.inquiry.action = document.inquiry.action + "&AGG_single_inq=" + document.inquiry.AGG_single_inq.value;
	}
}
function chkTxAreas(docType) {
	var txArea1 = document.inquiry.inquiry_remarks;
	var txArea2 = document.inquiry.inquiry_company_information;
	if (txArea1.value.length>1500 || txArea2.value.length>1500) {
		var errMsg = "The information typed in for the following fields are too long:\n";
		if (txArea1.value.length>1500 && txArea2.value.length>1500) {
            errMsg = errMsg + "* Message\n";
			errMsg = errMsg + "* Tell the supplier about your company\n";
			txArea1.focus();
		} else if (txArea1.value.length>1500) {
            errMsg = errMsg + "* Message\n";
			txArea1.focus();
		} else if (txArea2.value.length>1500) {
			errMsg = errMsg + "* Tell the supplier about your company\n";
			txArea2.focus();
		}
		errMsg = errMsg + "Please limit them to 1500 characters or less.";
		alert(errMsg);
		return false;
	}	
	if( !isValidPhoneFaxNumbers()) {
		return false;
	}
	/* 
     * @author Summit Saini 
     * @company Ness Technologies Pte Ltd
     * @date 11092004
     * @description check to open spell checker windows based on values "1" & "2"
     */
	document.inquiry.ValidateInquiry.value = "";
	if(document.inquiry.openWin1.value=="1") {
		alert("Please close the spell Checker Window for \"Write your message to the supplier\"");
		return false;
	}
	if(document.inquiry.openWin2.value=="1") {
		alert("Please close the spell Checker Window for \"Tell the supplier about your company\"");
		return false;
	}
	/** Removed for MR #19167: 2-step process
	if (document.inquiry.tabtype!=null) {
		//for new
		var foundError = false;
		if (document.inquiry.tabtype[0].checked) {
			hideBox('InvalidFormatInquiryUsername');
			hideBox('InvalidFormatInquiryPassword');
			if (hasSpecialChars(document.inquiry.inquiry_username.value)) {
				showBox('InvalidFormatInquiryUsername');
				foundError = true;
			}
			if (hasSpecialChars(document.inquiry.inquiry_password.value)) {
				showBox('InvalidFormatInquiryPassword');
				foundError = true;
			}
			if (document.inquiry.inquiry_username.value.length<=0 || document.inquiry.inquiry_password.value.length<=0 || document.inquiry.inquiry_reenter_password.value.length<=0) {
				if (document.inquiry.inquiry_username.value.length<=0) {
					document.inquiry.inquiry_username.onblur();
				}
				if (document.inquiry.inquiry_password.value.length<=0) {
					document.inquiry.inquiry_password.onblur();
				}
				if (document.inquiry.inquiry_reenter_password.value.length<=0) {
					document.inquiry.inquiry_reenter_password.onblur();
				}
				foundError = true;
			}
			if (document.inquiry.inquiry_password.value.length>0 && document.inquiry.inquiry_reenter_password.value.length>0) {
				if (!checkValuesMatch(document.inquiry.inquiry_reenter_password,'MustMatchInquiryReenterPassword',document.inquiry.inquiry_password))
					foundError = true;
			}
			if (document.inquiry.inquiry_username.value.length>0) {
				var userExistsErrorDiv = document.getElementById("AlreadyTakenInquiryUsername");
				if (userExistsErrorDiv.style.display == 'block')
					foundError = true;
			}
			if (document.inquiry.contact_detail_email.value.length>0) {
				var emailExistsErrorDiv = document.getElementById("AlreadyTakenInquiryEmail");
				if (emailExistsErrorDiv.style.display == 'block') {
					foundError = true;
				} else if (emailValidationInProgress) {
					foundError = true;
				}
			}
			if (foundError == true) {
				return false;
			}
		//for current
		} else if (document.inquiry.tabtype[1].checked) {
			if (document.inquiry.uid.value.length<=0) {
				if (document.inquiry.inquiry_login_username.value.length>0 && document.inquiry.inquiry_login_password.value.length>0 && !validationInProgress) {
					validateLoginCombo();
					return false;
				} else {
					hideBox('HttpErrorLoginComboCheck');
					if (document.inquiry.inquiry_login_username.value.length<=0) {
						document.inquiry.inquiry_login_username.onblur();
					}
					if (document.inquiry.inquiry_login_password.value.length<=0) {
						document.inquiry.inquiry_login_password.onblur();
					}
					return false;
				}
			}
		}
	}
	if (document.inquiry.contact_detail_email.value.length>0) {
		var emailExistsErrorDiv = document.getElementById("AlreadyTakenInquiryEmail");
		if (emailExistsErrorDiv.style.display == 'block') {
			return false;
		} else if (emailValidationInProgress) {
			return false;
		}
	}
	**/

	changeAction();
	changeButton('buttonImage','greyImage','submIndicator');
	clearDefaultValues();
	return true;
}
function clearDefaultValues() {
	var myFrm = document.inquiry;
	if (myFrm.contact_detail_first_name!=null && myFrm.contact_detail_first_name.value == 'First/Given Name')
		myFrm.contact_detail_first_name.value = '';
	if (myFrm.contact_detail_last_name!=null && myFrm.contact_detail_last_name.value == 'Last/Family Name')
		myFrm.contact_detail_last_name.value = '';
	if (myFrm.contact_detail_tel_area_code!=null && (myFrm.contact_detail_tel_area_code.value == 'Area Code' || myFrm.contact_detail_tel_area_code.value == 'Area C'))
		myFrm.contact_detail_tel_area_code.value = '';
	if (myFrm.contact_detail_tel_number!=null && myFrm.contact_detail_tel_number.value == 'Telephone Number')
		myFrm.contact_detail_tel_number.value = '';
	if (myFrm.contact_detail_tel_ext_number!=null && myFrm.contact_detail_tel_ext_number.value == 'Ext')
		myFrm.contact_detail_tel_ext_number.value = '';
	if (myFrm.contact_detail_fax_area_code!=null && (myFrm.contact_detail_fax_area_code.value == 'Area Code' || myFrm.contact_detail_tel_area_code.value == 'Area C'))
		myFrm.contact_detail_fax_area_code.value = '';
	if (myFrm.contact_detail_fax_number!=null && myFrm.contact_detail_fax_number.value == 'Telephone Number')
		myFrm.contact_detail_fax_number.value = '';
	if (myFrm.contact_detail_address_city!=null && myFrm.contact_detail_address_city.value == 'City')
		myFrm.contact_detail_address_city.value = '';
	if (myFrm.contact_detail_address_state!=null && myFrm.contact_detail_address_state.value == 'Province/State')
		myFrm.contact_detail_address_state.value = '';
	if (myFrm.contact_detail_address_postal_code!=null && myFrm.contact_detail_address_postal_code.value == 'Zip/Postal Code')
		myFrm.contact_detail_address_postal_code.value = '';
}
function initRegFields() {
	if (document.inquiry.inquiry_username.value.length>0)
		document.inquiry.inquiry_username.onblur();
	if (document.inquiry.inquiry_password.value.length>0)
		document.inquiry.inquiry_password.onblur();
	if (document.inquiry.inquiry_reenter_password.value.length>0)
		document.inquiry.inquiry_reenter_password.onblur();
	if (document.inquiry.inquiry_login_username.value.length>0)
		document.inquiry.inquiry_login_username.onblur();
	if (document.inquiry.inquiry_login_password.value.length>0)
		document.inquiry.inquiry_login_password.onblur();
	if (document.inquiry.contact_detail_email.value.length>0)
		document.inquiry.contact_detail_email.onblur();
}
//use regex method to test valid value, by Jansen Sep27, 2004
function isDecimal(s,message,field) {
	if(!(/^\d+(\.\d+)?$/.test(s))){
		alertCleanFocus("Please enter only numbers for " + message + ".",field);
		return false;
	}
	// added by Felix 24/1/2006 for MR #428
	if(s.length==10) {
		if (parseFloat(s)>parseFloat("9999999999")){
			alertCleanFocus("Please enter only numbers for " + message + ".",field);
			return false;
		}
	}
	return true;
}
function isValidPhoneFaxNumbers() {
	return (isValidPhoneNumber(true) && isValidFaxNumber(true));
}
function isValidPhoneNumber(input) {
	var varTelNum = document.inquiry.contact_detail_tel_number;
	if(input) {
		if(document.inquiry.contact_detail_tel_country_code.value.length>0 && !isNum(document.inquiry.contact_detail_tel_country_code,"telephone country code"))
			return false;
		if(document.inquiry.contact_detail_tel_area_code.value.length>0 && document.inquiry.contact_detail_tel_area_code.value!='Area Code' && document.inquiry.contact_detail_tel_area_code.value!='Area C' && !isNum(document.inquiry.contact_detail_tel_area_code,"telephone area code"))
			return false;
	}
	if(varTelNum.value.length>0 && varTelNum.value!='Telephone Number') {
		if(!(/^\d+([ \-\d]*\d)?$/.test(varTelNum.value))) {
			alertCleanFocus("Please enter only numbers for your Telephone Number. You may separate the numbers with a space or dash.",varTelNum);
			return false;
		}
	}
	if(input) {
		if(document.inquiry.contact_detail_tel_ext_number.length>0 && document.inquiry.contact_detail_tel_ext_number.value!='Ext' && !isNum(document.inquiry.contact_detail_tel_ext_number,"telephone extension"))
			return false;
	}
    return true;
}
function isValidFaxNumber(input) {
	var varFaxNum=document.inquiry.contact_detail_fax_number;
	if(input) {
		if(document.inquiry.contact_detail_fax_country_code.length>0 && !isNum(document.inquiry.contact_detail_fax_country_code,"fax country code"))
			return false;
		if(document.inquiry.contact_detail_fax_area_code.length>0 && document.inquiry.contact_detail_fax_area_code.value!='Area Code' && document.inquiry.contact_detail_fax_area_code.value!='Area C' && !isNum(document.inquiry.contact_detail_fax_area_code,"fax area code"))
			return false;
	}
    if(varFaxNum.value.length>0 && varFaxNum.value!='Telephone Number') {
		if(!(/^\d+([ \-\d]*\d)?$/.test(varFaxNum.value))) {
			alertCleanFocus("Please enter only numbers for your Fax Number. You may separate the numbers with a space or dash.",varFaxNum);
			return false;
		}
	}
    return true;
}
//for login fields checking
function displayAlert() {
	if (document.formLogin.UserID.value == "") {
		alert("Please enter Login Name.")	
		document.formLogin.UserID.focus();
		return false;
	}
	if (document.formLogin.UserPassword.value == "" ) {
		alert("Please enter Password.")
		document.formLogin.UserPassword.focus();
		return false;
	}
	return true;
}
//for opening sample company description
function openViewSample(_link) {
	msg=open(_link,"SettingsViewSample","height=290,width=480,status=0,toolbar=0,directories=0,menubar=0,location=0,scrollbars=0,resizable=0,top=50,left=50");
}
/* 
 * @author Summit Saini 
 * @company Ness Technologies Pte Ltd
 * @date 10052004
 * @description javascript function to open attachment page
 */
function gotoAttachSection(url) {
	document.inquiry.inquiry_remarks.disabled = false;
	document.inquiry.inquiry_company_information.disabled = false;
	url=url+"&openWin1="+document.inquiry.openWin1.value+"&openWin2 = "+document.inquiry.openWin2.value;
	url = url + "&inquiry_path=" + document.inquiry.inquiry_path.value;
	document.inquiry.action = url;
	document.inquiry.method = "POST";
	document.inquiry.submit();
}
/* 
 * @author Summit Saini 
 * @company Ness Technologies Pte Ltd
 * @date 1129004
 * @description javascript function to disable Textareas
 */
function disableWin(txt1, txt2) {
	if(txt1 == "1")
		document.inquiry.inquiry_remarks.disabled=true;
	else
		document.inquiry.inquiry_remarks.disabled=false;
	if(txt2 == "1")
		document.inquiry.inquiry_company_information.disabled=true;
	else
		document.inquiry.inquiry_company_information.disabled=false;
}
// from jspopup and jspopuphelp
function pop(page,height,width) {
	params = "height=" + height + ",width=" + width + ",status=1,toolbar=0,directories=0,menubar=0,location=0,scrollbars=1,resizable=1,top=50,left=50,screenX=50,screenY=50";
	mypopup = window.open(page,"PopupWindow",params);
	mypopup.focus();
}
function popup(page,height,width) {
	params = "height=" + height + ",width=" + width + ",status=no,toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,top=50,left=50,screenX=50,screenY=50"
	popHelp = open(page,"HelpWindow",params);
	popHelp.focus();
}

/* for hiding and showing stuff */

function showHide(elemID,imageID,plusURL,minusURL) {
	if (document.getElementById) {
		if (document.getElementById(elemID).style.display == "block") {
			document.getElementById(elemID).style.display = "none";
			document.images[imageID].src = plusURL;
		} else {
			document.getElementById(elemID).style.display = "block";
			document.images[imageID].src = minusURL;
		}
	} else if (document.layers) {
		if (document[elemID].display == "block") {
			document[elemID].display = "none";
			document.images[imageID].src = plusURL;
		} else {
			document[elemID].display = "block";
			document.images[imageID].src = minusURL;
		}
	}
}

function showBox(elemID) {
	if (document.getElementById) {
		document.getElementById(elemID).style.display = "block";
	} else if (document.layers) {
		document[elemID].display = "block";
	}
}
function hideBox(elemID) {
	if (document.getElementById) {
		document.getElementById(elemID).style.display = "none";
	} else if (document.layers) {
		document[elemID].display = "none";
	}
}
function changeButton(elemID1, elemID2, elemID3) {
	if (document.getElementById) {
		//document.getElementById(elemID1).style.display = "none";
		//document.getElementById(elemID2).style.display = "block";
		document.getElementById(elemID3).style.display = "block";
	} else if (document.layers) {
		//document[elemID1].display = "none";
		//document[elemID2].display = "block";
		document[elemID3].display = "block";
	}
}

function isNum(field) {
	if(field.value.length>0){
		if(!(/^[0-9]+$/.test(field.value))) {
			return false;
		}
	}
	return true;
}
function isPhone(field) {
	if(field.value.length>0) {
		if(!(/^\d+([ \-\d]*\d)?$/.test(Trim(field.value)))) {
			return false;
		}
	}
	return true;
}


function alertCleanFocus(alertMsg,field){
	if (field!=null) {
		if (alertMsg.length>0)
			alert(alertMsg);
		field.focus();
		field.value="";
	}
}

function validatePhone(myForm,elemID,elemID2) {
	if (
	(myForm.contact_detail_tel_country_code.value.length>0 && !isNum(myForm.contact_detail_tel_country_code))
	||
	(myForm.contact_detail_tel_ext_number.value.length>0 && myForm.contact_detail_tel_ext_number.value!='Ext' && !isNum(myForm.contact_detail_tel_ext_number))
	||
	(myForm.contact_detail_tel_area_code.value.length>0 && myForm.contact_detail_tel_area_code.value!='Area Code' && myForm.contact_detail_tel_area_code.value!='Area C' && !isNum(myForm.contact_detail_tel_area_code))
	||
	(myForm.contact_detail_tel_number.value.length>0 && myForm.contact_detail_tel_number.value!='Telephone Number' && !isPhone(myForm.contact_detail_tel_number))
	 ) {
		showBox(elemID);
		hideBox(elemID2);
		if (myForm.contact_detail_tel_country_code.value.length>0 && !isNum(myForm.contact_detail_tel_country_code)) {
			myForm.contact_detail_tel_country_code.value = "";
		} else if (myForm.contact_detail_tel_area_code.value.length>0 && myForm.contact_detail_tel_area_code.value!='Area Code' && myForm.contact_detail_tel_area_code.value!='Area C' && !isNum(myForm.contact_detail_tel_area_code)) {
			myForm.contact_detail_tel_area_code.value = "";
			blurFieldWithDefault(myForm.contact_detail_tel_area_code,'Area Code');
		} else if (myForm.contact_detail_tel_ext_number.value.length>0 && myForm.contact_detail_tel_ext_number.value!='Ext' && !isNum(myForm.contact_detail_tel_ext_number)) {
			myForm.contact_detail_tel_ext_number.value = "";
			blurFieldWithDefault(myForm.contact_detail_tel_ext_number,'Ext');
		} else if (myForm.contact_detail_tel_number.value.length>0 && myForm.contact_detail_tel_number.value!='Telephone Number' && !isPhone(myForm.contact_detail_tel_number)) {
			myForm.contact_detail_tel_number.value = "";
			blurFieldWithDefault(myForm.contact_detail_tel_number,'Telephone Number');
		}
	} else {
		hideBox(elemID);
	}
}
function validateFax(myForm,elemID,bID) {
	if (
	(myForm.contact_detail_fax_country_code.value.length>0 && !isNum(myForm.contact_detail_fax_country_code))
	||
	(myForm.contact_detail_fax_area_code.value.length>0 && myForm.contact_detail_fax_area_code.value!='Area Code' && myForm.contact_detail_fax_area_code.value!='Area C' && !isNum(myForm.contact_detail_fax_area_code))
	||
	(myForm.contact_detail_fax_number.value.length>0 && myForm.contact_detail_fax_number.value!='Telephone Number' && !isPhone(myForm.contact_detail_fax_number))
	) {
		showBox(elemID);
		if (myForm.contact_detail_fax_country_code.value.length>0 && !isNum(myForm.contact_detail_fax_country_code)) {
			myForm.contact_detail_fax_country_code.value = "";
			document.getElementById(bID).style.color = "#C00";
		} else if (myForm.contact_detail_fax_area_code.value.length>0 && !isNum(myForm.contact_detail_fax_area_code)) {
			myForm.contact_detail_fax_area_code.value = "";
			blurFieldWithDefault(myForm.contact_detail_fax_area_code,'Area Code');
			document.getElementById(bID).style.color = "#C00";
		} else if (myForm.contact_detail_fax_number.value.length>0 && !isPhone(myForm.contact_detail_fax_number)) {
			myForm.contact_detail_fax_number.value = "";
			blurFieldWithDefault(myForm.contact_detail_fax_number,'Telephone Number');
			document.getElementById(bID).style.color = "#C00";
		}
	} else {
		hideBox(elemID);
		document.getElementById(bID).style.color = "#000";
	}
}

function validateNumber(field,elemID) {
	if (!isNum(field)) {
		showBox(elemID);
		alertCleanFocus("",field);
	} else {
		hideBox(elemID);
	}
}

function checkFilledFullName(myForm,elemID) {
	firstName = Trim(myForm.contact_detail_first_name.value);
	lastName = Trim(myForm.contact_detail_last_name.value);
	if (firstName.length<=0 || lastName.length<=0) {
		showBox(elemID);
	} else {
		hideBox(elemID);
	}
}

function clickFieldWithDefault(fldObj,defaultString) {
	if (fldObj.value==defaultString) {
		fldObj.value = '';
	}
	fldObj.className = 'textinput';
}
function blurFieldWithDefault(fldObj,defaultString) {
	if (fldObj.value=='') {
		fldObj.className = 'textinputunfilled';
		fldObj.value = defaultString;
	}
}
function checkFilledMandatory(fldObj,elemID,fldType,trimBool,defaultString) {
	var retVal = true;
	if (fldType == "value") {
		if (trimBool!=null && trimBool==false) {
			fldVal = fldObj.value;
		} else {
			fldVal = Trim(fldObj.value);
		}
		if (fldVal == defaultString) {
			showBox(elemID);
			retVal = false;
		} else {
			if (fldVal.length <= 0) {
				showBox(elemID);
				retVal = false;
			} else {
				hideBox(elemID);
			}
		}
	}
	if (fldType == "select") {
		fldValIdx = fldObj.selectedIndex;
		if (fldValIdx <= 0) {
			showBox(elemID);
			retVal = false;
		} else {
			hideBox(elemID);
		}
	}
	return retVal;
}

function checkValuesMatch(fldObj,elemID,matchFldObj) {
	var retVal = true;
	if (fldObj.value.length>0 && matchFldObj.value.length>0) {
		if (fldObj.value != matchFldObj.value) {
			showBox(elemID);
			retVal = false;
		} else {
			hideBox(elemID);
		}
	}
	return retVal;
}

function showTipIfHidden(elemIDShow, elemIDHidden) {
	if (document.getElementById) {
		if (document.getElementById(elemIDHidden).style.display != "block") {
			document.getElementById(elemIDShow).style.display = "block";
		}
	} else if (document.layers) {
		if (document[elemIDHidden].display != "block") {
			document[elemID].display = "block";
		}
	}
}
function limitTextArea(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}
function compareValues(inputField,compareFieldValue,elemID) {
	if (Trim(inputField.value) == Trim(compareFieldValue)) {
		showBox(elemID);
	} else {
		hideBox(elemID);
	}
}
function checkMandatoryPair(field1,field2,elemID,inErrPage) {
	if (inErrPage == "no") {
		if ((Trim(field1.value).length>0) || (Trim(field2.value).length>0)) {
			hideBox(elemID);
		}
	}
}

function checkMandatoryPair(field1,field2,elemID) {
    if (field1 == 'country_code' && field2 =='tel_number')  {
        if (Trim(document.inquiry.contact_detail_tel_country_code.value).length <= 0 || Trim(document.inquiry.contact_detail_tel_number.value).length <= 0){
			showBox(elemID);
		} else {
			hideBox(elemID);
		}
	}
}
function checkMandatoryPairWithDefault(field1,defaultString1,field2,defaultString2,elemID) {
	if (Trim(field1.value).length <= 0 || field1.value==defaultString1 || Trim(field2.value).length <= 0 || field2.value==defaultString2){
		showBox(elemID);
	} else {
		hideBox(elemID);
	}
}



function showHideRows(elemID,imageID,plusURL,minusURL,linkObjID,copyForPlus,copyForMinus) {
	if (document.getElementById(elemID).style.display == "block") {
		document.getElementById(elemID).style.display = "none";
		document.images[imageID].src = plusURL;
		document.getElementById(linkObjID).innerHTML = copyForPlus;
	} else {
		document.getElementById(elemID).style.display = "block";
		document.images[imageID].src = minusURL;
		document.getElementById(linkObjID).innerHTML = copyForMinus;
	}
}
function showHideLabelAndField(elemID,imageID,plusURL,minusURL,linkObjID,copyForPlus,copyForMinus) {
	var fieldObjID = elemID + "FLD";
	var labelObjID = elemID + "LABEL";
	if (document.getElementById(fieldObjID).style.display == "block") {
		document.getElementById(fieldObjID).style.display = "none";
		document.getElementById(labelObjID).style.display = "none";
		document.images[imageID].src = plusURL;
		document.getElementById(linkObjID).innerHTML = copyForPlus;
	} else {
		document.getElementById(fieldObjID).style.display = "block";
		document.getElementById(labelObjID).style.display = "block";
		document.images[imageID].src = minusURL;
		document.getElementById(linkObjID).innerHTML = copyForMinus;
	}
}


function showProdTN(largeImgURL) {
	imgWinDiv.innerHTML = "<img src='" + largeImgURL + "' border='1' >";
}
function hideProdTN() {
	imgWinDiv.innerHTML = "";
}
function move_layer(event){
	event = event || window.event;
	imgWinDiv.style.left=event.clientX+document.body.scrollLeft+1;
	imgWinDiv.style.top =event.clientY+document.body.scrollTop+1;
}

function countMsgChar(limitNum,txtareaObj,cntSpanObj){
	var spanWithCount = document.getElementById(cntSpanObj);
	var summ = txtareaObj.value.replace(/[^\x00-\xff]/g,"aa");
	if(summ.length<=limitNum) {
		spanWithCount.innerHTML=summ.length;
	} else {
		txtareaObj.value = txtareaObj.value.toString().substr(0, limitNum);
		spanWithCount.innerHTML=limitNum;
	}
}


/** Added for Product Mouse Over MR **/
function getPPPosition(tag){
	var Position =[0,0];
	while(tag){
		tn=tag.tagName.toUpperCase();
		Position[0]+=tag.offsetLeft-(tn=="DIV"&&tag.scrollLeft?tag.scrollLeft:0);
		Position[1]+=tag.offsetTop-(tn=="DIV"&&tag.scrollTop?tag.scrollTop:0);
		if(tn=="BODY") break;
		tag=tag.offsetParent;
	}
	return Position;
}
function showPPSummary(e,prodID){
	try {
		clearTimeout(timer);
	} catch(s) {}

	eventElement=e.target||e.srcElement;
	var elementSrc = eventElement.src;
	var elementAlt = eventElement.alt;
	var elementParentHref = eventElement.parentNode.href;
	
	var toUse = prodID;
	var myProdDir = toUse.substring(toUse.length-3,toUse.length);
	//var src = "http://pdt.static.dev.globalsources.com/IMAGES/PDT/THUMB/" + myProdDir + "/T" + toUse + ".jpg";
	var src = "http://akamai.globalsources.com.edgesuite.net/f/593/3445/5d/pdt.static.globalsources.com/IMAGES/PDT/THUMB/" + myProdDir + "/T" + toUse + ".jpg";
	
	var xy = getPPPosition(eventElement);
	var showF = $$("showFrame");
	showF.style.left = (xy[0]-(imgWidth+3))+"px";
	showF.style.top = (xy[1]-overTop )+"px";
	showF.style.display = "block";
	$$("showFrame_img").src = src;
	$$("showFrame_img").alt = elementAlt;
	$$("showFrame_img").parentNode.href = elementParentHref;
}
function showPPOut(){
	timer = setTimeout("donePPOut()",500);
}
function donePPOut(){
	$$("showFrame").style.display = "none";
}
function clearPPTimer(){
	try {
		clearTimeout(timer);
	} catch(s) {}
}

/*Add for MR 16487*/
function changeLabelBackgd(fldObj,fldType,tdID,bID,srcPink,srcBlue) {
	if (fldType == "value") {
		fldVal = Trim(fldObj.value);
		if (fldVal.length <= 0) {
			//document.getElementById(tdID).style.backgroundImage = 'url(' + srcPink + ')';
            document.getElementById(bID).style.color = "#CC0000";
		} else {
			//document.getElementById(tdID).style.backgroundImage = 'url(' + srcBlue + ')';
            document.getElementById(bID).style.color = "#000000";
		}
	}
	if (fldType == "select") {
		fldValIdx = fldObj.selectedIndex;
		if (fldValIdx <= 0) {
			//document.getElementById(tdID).style.backgroundImage = 'url(' + srcPink + ')';
            document.getElementById(bID).style.color = "#CC0000";
		} else {
			//document.getElementById(tdID).style.backgroundImage = 'url(' + srcBlue + ')';
            document.getElementById(bID).style.color = "#000000";
		}
	}
}
function changeLabelBackground(fldObj,fldName,bID) {
	if (fldName == "email") {
		fldVal = Trim(fldObj.value);
		if (fldVal.length <= 0 || document.getElementById('RegisteredEmail').style.display == "block" || document.getElementById('LiteEmail').style.display == "block"){
            document.getElementById(bID).style.color = "#CC0000";
		} else {
			document.getElementById(bID).style.color = "#000000";
		}
	}
}

function changeNumLabelBackgd(field,tdID,bID,srcPink) {
	if (!isNum(field)) {
		//document.getElementById(tdID).style.backgroundImage = 'url(' + srcPink + ')';
        document.getElementById(bID).style.color = "#CC0000";
	} else {
		//document.getElementById(tdID).style.backgroundImage = '';
        document.getElementById(bID).style.color = "#000000";
	}
}

function changeFaxBg(myForm,tdID,bID,srcPink) {
	if (!isNum(myForm.contact_detail_fax_country_code) || !isNum(myForm.contact_detail_fax_area_code) || !isPhone(myForm.contact_detail_fax_number)) {
		//document.getElementById(tdID).style.backgroundImage = 'url(' + srcPink + ')';
        document.getElementById(bID).style.color = "#CC0000";
	} else {
		//document.getElementById(tdID).style.backgroundImage = '';
        document.getElementById(bID).style.color = "#000000";
	}
}

function changePhoneBg(myForm,tdID,bID,srcPink,srcBlue) {
	if (
	(myForm.contact_detail_tel_country_code.value.length>0 && !isNum(myForm.contact_detail_tel_country_code))
	||
	(myForm.contact_detail_tel_ext_number.value.length>0 && myForm.contact_detail_tel_ext_number.value!='Ext' && !isNum(myForm.contact_detail_tel_ext_number))
	||
	(myForm.contact_detail_tel_area_code.value.length>0 && myForm.contact_detail_tel_area_code.value!='Area Code' && myForm.contact_detail_tel_area_code.value!='Area C' && !isNum(myForm.contact_detail_tel_area_code))
	||
	(myForm.contact_detail_tel_number.value.length>0 && myForm.contact_detail_tel_number.value!='Telephone Number' && !isPhone(myForm.contact_detail_tel_number))) {
        document.getElementById(bID).style.color = "#CC0000";
	} else if (
	Trim(document.inquiry.contact_detail_tel_country_code.value).length <= 0
	||
	Trim(document.inquiry.contact_detail_tel_number.value).length <= 0 || document.inquiry.contact_detail_tel_number.value=='Telephone Number'
	) {
        document.getElementById(bID).style.color = "#CC0000";
	}else {
        document.getElementById(bID).style.color = "#000000";
	}
}

function changeNameBg(field,defaultString) {
    if (field == 'first_name')  {
        if ((Trim(document.inquiry.contact_detail_first_name.value).length <= 0) || (document.inquiry.contact_detail_first_name.value == defaultString))  {
            document.getElementById('b_name').style.color = "#CC0000";
        } else {
            document.getElementById('b_name').style.color = "#000000";
        }
    }

    if (field == 'last_name')  {
        if ((Trim(document.inquiry.contact_detail_last_name.value).length <= 0) || (document.inquiry.contact_detail_last_name.value == defaultString))  {
            document.getElementById('b_name').style.color = "#CC0000";
        } else {
            document.getElementById('b_name').style.color = "#000000";;
        }
    }
}

function showTipWithError(errBox,TipBox) {
    if (document.getElementById(errBox).style.display == "block"){
        document.getElementById(TipBox).style.display = "block";
    } else {
        document.getElementById(TipBox).style.display = "none";
    }
}

function showEmailTipWithError() {
    if (document.getElementById('RegisteredEmail').style.display == "block"
        || document.getElementById('ReqdEmail').style.display == "block"
        ||document.getElementById('InvalidEmail1').style.display == "block"
        ||document.getElementById('InvalidEmail2').style.display == "block") {
        document.getElementById('TipEmail').style.display = "block";
    } else {
        document.getElementById('TipEmail').style.display = "none";
    }
}

function syncWithUVCheckbox(cbox,uvURL) {
	if (cbox.checked) {
		document.inquiry.uv_endeca_query_string.value=uvURL;
		document.inquiry.AGG_single_inq.value="Y";
		document.getElementById("uvToText").style.display = "inline";
	} else {
		document.inquiry.uv_endeca_query_string.value='';
		document.inquiry.AGG_single_inq.value="N";
		document.getElementById("uvToText").style.display = "none";
	}
}
function changeInqType(myNewInqFormURL) {
	var goToURL = myNewInqFormURL
	if (document.inquiry.expand_type!=null && document.inquiry.expand_type!=undefined) {
		if (document.inquiry.expand_type.checked) {
			goToURL = goToURL + "&expand_type=" + document.inquiry.expand_type.value;
		}
	}
	changeInqPath();
	document.inquiry.action = goToURL + "&inquiry_path=" + document.inquiry.inquiry_path.value + "&refresh=true";
	clearDefaultValues();
	document.inquiry.submit();
}
function changeInqPath() {
	var inqAllBoxExists = (document.inquiry.inquire_all_now!=null && document.inquiry.inquire_all_now!=undefined);
	var uvInqAllBoxExists = (document.inquiry.expand_type!=null && document.inquiry.expand_type!=undefined);
	if (inqAllBoxExists && document.inquiry.inquire_all_now.checked==true && uvInqAllBoxExists && document.inquiry.expand_type.checked==true) {
		document.inquiry.inquiry_path.value = "InquireAll_OnePPAll" + "_" + origInqPath;
	} else if (inqAllBoxExists && document.inquiry.inquire_all_now.checked==true && (!uvInqAllBoxExists || (uvInqAllBoxExists && document.inquiry.expand_type.checked==false))) {
		document.inquiry.inquiry_path.value = "InquireAll_OnePP" + "_" + origInqPath;
	} else if (uvInqAllBoxExists && document.inquiry.expand_type.checked==true && (!inqAllBoxExists || (inqAllBoxExists && document.inquiry.inquire_all_now.checked==false))) {
		if (document.inquiry.inquiry_path.value.indexOf("InquireAll_OneSP")<0) {
			document.inquiry.inquiry_path.value = "InquireAll_OnePPAGG" + "_" + origInqPath;
		}
	} else {
		if (document.inquiry.inquiry_path.value.indexOf("InquireAll_OneSP")<0) {
			document.inquiry.inquiry_path.value = origInqPath;
		}
	//alert(document.inquiry.inquiry_path.value);
        }
}

/**
  * Scripts for V96
  **/
var userClickedPABox = false;
function switchTab(tabType) {
	// tabType values: "NEW" or "CURRENT"
	if (tabType == "NEW") {
		document.inquiry.tabtype[0].checked = true;
		document.getElementById('InqTabNewUser').style.display='block';
		document.getElementById('tabText').innerHTML='Your Contact Details to Supplier:';
		//document.getElementById('tabNewTD').className='tabCurrent';
		//document.getElementById('tabCurrentTD').className='tabBehind';
		document.getElementById('InqTabCurrentUser').style.display='none';
		document.getElementById('notificationsbox').style.display='block';
		if (!userClickedPABox && document.inquiry.add_cats_to_prefs!=null && document.inquiry.add_cats_to_prefs!=undefined) {
			document.inquiry.add_cats_to_prefs.checked = true;
			document.inquiry.add_cats_checked.value = "yes";
		}
		if (document.getElementById('AlreadyTakenInquiryEmail')!=null && document.getElementById('AlreadyTakenInquiryEmail').style.display=='block') {
			document.inquiry.contact_detail_email.focus();
		}
	} else if (tabType == "CURRENT") {
		document.inquiry.tabtype[1].checked = true;
		document.getElementById('InqTabCurrentUser').style.display='block';
		document.getElementById('tabText').innerHTML='Sign In to Send Your Inquiry:';
		//document.getElementById('tabCurrentTD').className='tabCurrent';
		//document.getElementById('tabNewTD').className='tabBehind';
		document.getElementById('InqTabNewUser').style.display='none';
		document.getElementById('notificationsbox').style.display='none';
		if (!userClickedPABox && document.inquiry.add_cats_to_prefs!=null && document.inquiry.add_cats_to_prefs!=undefined) {
			document.inquiry.add_cats_to_prefs.checked = false;
			document.inquiry.add_cats_checked.value = "no";
		}
	}
}
function checkFieldIsNotInError(isNotInErr1,isNotInErr2,tdID,bID,srcPink,srcBlue) {
	if (isNotInErr1 && isNotInErr2) {
		//document.getElementById(tdID).style.backgroundImage = 'url(' + srcBlue + ')';
		document.getElementById(bID).style.color = "#000000";
	} else {
		//document.getElementById(tdID).style.backgroundImage = 'url(' + srcPink + ')';
		document.getElementById(bID).style.color = "#CC0000";
	}
}
/* Added for new attach flow */
function fileAdded(file, response, icon, blank, removeAttURL) {
      var fileVal=response.split('|');
      //SUCCESS|Id|FileName|MimeType|Size
      var fileArr=new Array(4); 
      for (var i=1; i<fileVal.length; i++) {
          fileArr[i]=fileVal[i]
      }
      var attachID=fileArr[1];
      var fileSizeOrig=Trim(fileArr[4]);
      fileSize=fileSizeOrig/1024; //show in xK format
      var dec = (fileSizeOrig%1024!=0? 2 : 0);
      var fileName=Trim(file);
      var mimeType=Trim(fileArr[3]);
      removeAttURL+="&attachment_id="+attachID; //append id
      var newFileAdded='<span class=\"black_text\" id=\"'+attachID+'\" style=\"display:block;\"><img src=\"'+icon+'\" width=\"9\" height=\"14\" align=\"absmiddle\">&nbsp;'
            +fileName+'&nbsp;('+mimeType+')&nbsp;'+fileSize.toFixed(dec)+'K'
            +'<img src=\"'+blank+'\" width=\"10\" height=\"5\"> <a href=\"#\" onClick=\"removeAttachment(\''+removeAttURL+'\',\''+attachID+'\');return false;\">Remove</a><br>'      
            //+'<input type=\"hidden\" name=\"orig_Attachment_ID\" value=\"'+attachID+'\">'
            +'<input type=\"hidden\" name=\"Attachment_ID\" value=\"'+attachID+'\">'
            +'<input type=\"hidden\" name=\"File_Name\" value=\"'+fileName+'\">'
            +'<input type=\"hidden\" name=\"File_Size\" value=\"'+fileSizeOrig+'\">'
            +'<input type=\"hidden\" name=\"Mime_Type\" value=\"'+mimeType+'\"></span>';
     return newFileAdded;
}
function removeAttachment(removeAttURL, attachID) {
    //do ajax call.
    var isDeleted = false;
    var responseText = null;
    $.ajax({
        type:"GET", 
        url:removeAttURL, 				
        dataType:"html", 
        cache: false,
        error:function(ajaxrequest) {
            //isDeleted = false;
        },
        success:function(resultData) {
            responseText = resultData;
        },
        complete: function (XMLHttpRequest, textStatus) {
            if (textStatus == "success" && responseText!=null) {
                txt = responseText;
                if(txt.indexOf(attachID) == -1) {
                    //isDeleted
                    clearAttachID(attachID);
                }else {
                   //not Deleted
                   var errorbox=$('#attacherror_box');
                   showBox('attacherror_box');
                   errorbox.html('ERROR:: Unable to delete your attachment.');
                }    
            }
        }
    });
}
function clearAttachID(attachID) {
     var fileCnt=0;
     for (var i=0;i<document.inquiry.length;i++) {
        var e = document.inquiry.elements[i];
        if (e.name=='Attachment_ID' && e.value==attachID) {
            document.inquiry.elements[i+1].value="";
            document.inquiry.elements[i+2].value="";
            document.inquiry.elements[i+3].value="";
            e.value="";
        }
        if (e.name=='Attachment_ID' && e.value!="")
            fileCnt++;
    }
    //hide that file
    hideBox(attachID);

    //hide the grey box if last item
    if (fileCnt==0)
        hideBox('files');
}

function getLastIDAdded(lastadded){
 var fileVal=lastadded.split('|');
      //SUCCESS|Id|FileName|MimeType|Size
      var fileArr=new Array(4); 
      for (var i=1; i<fileVal.length; i++) {
          fileArr[i]=fileVal[i]
      }
      var lastAddedID=fileArr[1];
      return lastAddedID;
}
/*No need for now
function collectIDcheck(lastadded) {
      var fileVal=lastadded.split('|');
      //SUCCESS|Id|FileName|MimeType|Size
      var fileArr=new Array(4); 
      for (var i=1; i<fileVal.length; i++) {
          fileArr[i]=fileVal[i]
      }
      var lastAddedID=fileArr[1];
      
    var list='';
    for (var i=0;i<document.inquiry.length;i++) {
	var e = document.inquiry.elements[i];
        if (e.name=='Attachment_ID' && e.type=='checkbox' && e.checked==true) 
            list+=e.value+'|';
    }
    return list+lastAddedID;
}

function checkIDchecked(list) {
    for (var i=0;i<document.inquiry.length;i++) {
	var e = document.inquiry.elements[i];
        if (e.name=='Attachment_ID' && e.type=='checkbox') {
            if (e.value!=0 && list.indexOf(e.value)>-1)
                e.checked=true;
            else
                e.checked=false;
        }
    }
}
function grayFile(field, attachID) {
    check=field.checked;
    id=attachID;
    color=(check? '#000000' : '#999999');
    if (document.getElementById) {
        document.getElementById(id).style.color = color;
    } else if (document.layers) {
        document[id].color = color;
    }
    if (check) { //for action handling
        field.checked=true;
        field.value=attachID;
    } else {
        field.checked=false;
        field.value=0;
    }    
}
*/

function fileStatus(file,icon) {
   var fileupload='<img src=\''+icon+'\' width=9 height=14 align=absmiddle> '
       +'<span class=black_text>'+file + ' (Uploading ...)</span>';
   return fileupload;
}
function trackAttachment(errCode, trackType, WAGIF, lastID) {
    tractID='trackAttachment';
    tracking= WAGIF +'?formNm='+trackType;
    err_count=parseInt(document.inquiry.att_err_cnt.value);
    if (errCode==0)
        tracking+='&err=0&id='+lastID;
    else {
        err_count++;
        tracking+='&err='+err_count+'attachment';
        if (errCode=='MAX')
            tracking+='&filesize=1N&filetype=0&filevirus=0&othererr=0';
        else if (errCode=='FNA')
            tracking+='&filesize=0&filetype=1N&filevirus=0&othererr=0';
        else if (errCode=='VIR')
            tracking+='&filesize=0&filetype=0&filevirus=1N&othererr=0';
        else
            tracking+='&filesize=0&filetype=0&filevirus=0&othererr=1N';    
     }  
    document.inquiry.att_err_cnt.value=err_count; //save it
    if (document.getElementById) {
        document.getElementById(tractID).src= tracking;
    } else if (document.layers) {
        document[tractID].src = tracking;
	}
}
/*--end Added for new attach flow */

/* 1supp inqall redirect */
function inqAllSupplierCategory(selectObj,baseURL) {
	if (selectObj.selectedIndex > 0) {
		window.location.href = baseURL + "&point_id=" + selectObj[selectObj.selectedIndex].value;
	}
}

/* callout bubble for inqall box */
var tipwidth='150px' //default tooltip width
var tipbgcolor='white'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="5px" //horizontal offset of tooltip from anchor link
var horizontal_offset="50px" //horizontal offset of tooltip from anchor link
var ie4=document.all;
var ns6=document.getElementById&&!document.all;
if(ie4||ns6){document.write("<div id=\"fixedtipdiv\" style=\"visibility:hidden;width:"+tipwidth+";background-color:"+tipbgcolor+"\" ></div>");}
function getposOffset(_1,_2){var _3=(_2=="left")?_1.offsetLeft:_1.offsetTop;var _4=_1.offsetParent;while(_4!=null){_3=(_2=="left")?_3+_4.offsetLeft:_3+_4.offsetTop;_4=_4.offsetParent;}return _3;};
function showhide(_5,e,_6,_7,_8){if(ie4||ns6){dropmenuobj.style.left=dropmenuobj.style.top=-500;}if(_8!=""){dropmenuobj.widthobj=dropmenuobj.style;dropmenuobj.widthobj.width=_8;}if(e.type=="click"&&_5.visibility==_7||e.type=="mouseover"){_5.visibility=_6;}else{if(e.type=="click"){_5.visibility=_7;}}};
function iecompattest(){return (document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;};
function clearbrowseredge(_9,_a){var _b=(_a=="rightedge")?parseInt(horizontal_offset)*-1:parseInt(vertical_offset)*-1;if(_a=="rightedge"){var _c=ie4&&!window.opera?iecompattest().scrollLeft+iecompattest().clientWidth-15:window.pageXOffset+window.innerWidth-15;dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;if(_c-dropmenuobj.x<dropmenuobj.contentmeasure){_b=dropmenuobj.contentmeasure-_9.offsetWidth;}}else{var _c=ie4&&!window.opera?iecompattest().scrollTop+iecompattest().clientHeight-15:window.pageYOffset+window.innerHeight-18;dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;if(_c-dropmenuobj.y<dropmenuobj.contentmeasure){_b=dropmenuobj.contentmeasure+_9.offsetHeight;}}return _b;};
function fixedtooltip(_d,_e,e,_f){if(window.event){event.cancelBubble=true;}else{if(e.stopPropagation){e.stopPropagation();}}clearhidetip();dropmenuobj=document.getElementById?document.getElementById("fixedtipdiv"):fixedtipdiv;dropmenuobj.innerHTML=_d;if(ie4||ns6){showhide(dropmenuobj.style,e,"visible","hidden",_f);dropmenuobj.x=getposOffset(_e,"left");dropmenuobj.y=getposOffset(_e,"top");dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(_e,"rightedge")+"px";dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(_e,"bottomedge")+_e.offsetHeight+"px";}};
function hidetip(e){if(typeof dropmenuobj!="undefined"){if(ie4||ns6){dropmenuobj.style.visibility="hidden";}}};
function delayhidetip(){if(ie4||ns6){delayhide=setTimeout("hidetip()",disappeardelay);}};
function clearhidetip(){if(typeof delayhide!="undefined"){clearTimeout(delayhide);}};

/*
 * JQuery Form Plugin
 */
(function($){$.fn.ajaxSubmit=function(_1){if(!this.length){_2("ajaxSubmit: skipping submit process - no element selected");return this;}if(typeof _1=="function"){_1={success:_1};}var _3=$.trim(this.attr("action"));if(_3){_3=(_3.match(/^([^#]+)/)||[])[1];}_3=_3||window.location.href||"";_1=$.extend({url:_3,type:this.attr("method")||"GET"},_1||{});var _4={};this.trigger("form-pre-serialize",[this,_1,_4]);if(_4.veto){_2("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this;}if(_1.beforeSerialize&&_1.beforeSerialize(this,_1)===false){_2("ajaxSubmit: submit aborted via beforeSerialize callback");return this;}var a=this.formToArray(_1.semantic);if(_1.data){_1.extraData=_1.data;for(var n in _1.data){if(_1.data[n] instanceof Array){for(var k in _1.data[n]){a.push({name:n,value:_1.data[n][k]});}}else{a.push({name:n,value:_1.data[n]});}}}if(_1.beforeSubmit&&_1.beforeSubmit(a,this,_1)===false){_2("ajaxSubmit: submit aborted via beforeSubmit callback");return this;}this.trigger("form-submit-validate",[a,this,_1,_4]);if(_4.veto){_2("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this;}var q=$.param(a);if(_1.type.toUpperCase()=="GET"){_1.url+=(_1.url.indexOf("?")>=0?"&":"?")+q;_1.data=null;}else{_1.data=q;}var _5=this,_6=[];if(_1.resetForm){_6.push(function(){_5.resetForm();});}if(_1.clearForm){_6.push(function(){_5.clearForm();});}if(!_1.dataType&&_1.target){var _7=_1.success||function(){};_6.push(function(_8){$(_1.target).html(_8).each(_7,arguments);});}else{if(_1.success){_6.push(_1.success);}}_1.success=function(_9,_a){for(var i=0,_b=_6.length;i<_b;i++){_6[i].apply(_1,[_9,_a,_5]);}};var _c=$("input:file",this).fieldValue();var _d=false;for(var j=0;j<_c.length;j++){if(_c[j]){_d=true;}}var _e=false;if(_1.iframe||_d||_e){if(_1.closeKeepAlive){$.get(_1.closeKeepAlive,_f);}else{_f();}}else{$.ajax(_1);}this.trigger("form-submit-notify",[this,_1]);return this;function _f(){var _10=_5[0];if($(":input[name=submit]",_10).length){alert("Error: Form elements must not be named \"submit\".");return;}var _11=$.extend({},$.ajaxSettings,_1);var s=$.extend(true,{},$.extend(true,{},$.ajaxSettings),_11);var id="jqFormIO"+(new Date().getTime());var $io=$("<iframe id=\""+id+"\" name=\""+id+"\" src=\"about:blank\" />");var io=$io[0];$io.css({position:"absolute",top:"-1000px",left:"-1000px"});var xhr={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){this.aborted=1;$io.attr("src","about:blank");}};var g=_11.global;if(g&&!$.active++){$.event.trigger("ajaxStart");}if(g){$.event.trigger("ajaxSend",[xhr,_11]);}if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&$.active--;return;}if(xhr.aborted){return;}var _12=0;var _13=0;var sub=_10.clk;if(sub){var n=sub.name;if(n&&!sub.disabled){_1.extraData=_1.extraData||{};_1.extraData[n]=sub.value;if(sub.type=="image"){_1.extraData[name+".x"]=_10.clk_x;_1.extraData[name+".y"]=_10.clk_y;}}}setTimeout(function(){var t=_5.attr("target"),a=_5.attr("action");_10.setAttribute("target",id);if(_10.getAttribute("method")!="POST"){_10.setAttribute("method","POST");}if(_10.getAttribute("action")!=_11.url){_10.setAttribute("action",_11.url);}if(!_1.skipEncodingOverride){_5.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});}if(_11.timeout){setTimeout(function(){_13=true;cb();},_11.timeout);}var _14=[];try{if(_1.extraData){for(var n in _1.extraData){_14.push($("<input type=\"hidden\" name=\""+n+"\" value=\""+_1.extraData[n]+"\" />").appendTo(_10)[0]);}}$io.appendTo("body");io.attachEvent?io.attachEvent("onload",cb):io.addEventListener("load",cb,false);_10.submit();}finally{_10.setAttribute("action",a);t?_10.setAttribute("target",t):_5.removeAttr("target");$(_14).remove();}},10);var _15=50;function cb(){if(_12++){return;}io.detachEvent?io.detachEvent("onload",cb):io.removeEventListener("load",cb,false);var ok=true;try{if(_13){throw "timeout";}var _16,doc;doc=io.contentWindow?io.contentWindow.document:io.contentDocument?io.contentDocument:io.document;var _17=_11.dataType=="xml"||doc.XMLDocument||$.isXMLDoc(doc);_2("isXml="+_17);if(!_17&&(doc.body==null||doc.body.innerHTML=="")){if(--_15){_12=0;setTimeout(cb,100);return;}_2("Could not access iframe DOM after 50 tries.");return;}xhr.responseText=doc.body?doc.body.innerHTML:null;xhr.responseXML=doc.XMLDocument?doc.XMLDocument:doc;xhr.getResponseHeader=function(_18){var _19={"content-type":_11.dataType};return _19[_18];};if(_11.dataType=="json"||_11.dataType=="script"){var ta=doc.getElementsByTagName("textarea")[0];if(ta){xhr.responseText=ta.value;}else{var pre=doc.getElementsByTagName("pre")[0];if(pre){xhr.responseText=pre.innerHTML;}}}else{if(_11.dataType=="xml"&&!xhr.responseXML&&xhr.responseText!=null){xhr.responseXML=_1a(xhr.responseText);}}_16=$.httpData(xhr,_11.dataType);}catch(e){ok=false;$.handleError(_11,xhr,"error",e);}if(ok){_11.success(_16,"success");if(g){$.event.trigger("ajaxSuccess",[xhr,_11]);}}if(g){$.event.trigger("ajaxComplete",[xhr,_11]);}if(g&&!--$.active){$.event.trigger("ajaxStop");}if(_11.complete){_11.complete(xhr,ok?"success":"error");}setTimeout(function(){$io.remove();xhr.responseXML=null;},100);};function _1a(s,doc){if(window.ActiveXObject){doc=new ActiveXObject("Microsoft.XMLDOM");doc.async="false";doc.loadXML(s);}else{doc=(new DOMParser()).parseFromString(s,"text/xml");}return (doc&&doc.documentElement&&doc.documentElement.tagName!="parsererror")?doc:null;};};};$.fn.ajaxForm=function(_1b){return this.ajaxFormUnbind().bind("submit.form-plugin",function(){$(this).ajaxSubmit(_1b);return false;}).bind("click.form-plugin",function(e){var $el=$(e.target);if(!($el.is(":submit,input:image"))){return;}var _1c=this;_1c.clk=e.target;if(e.target.type=="image"){if(e.offsetX!=undefined){_1c.clk_x=e.offsetX;_1c.clk_y=e.offsetY;}else{if(typeof $.fn.offset=="function"){var _1d=$el.offset();_1c.clk_x=e.pageX-_1d.left;_1c.clk_y=e.pageY-_1d.top;}else{_1c.clk_x=e.pageX-e.target.offsetLeft;_1c.clk_y=e.pageY-e.target.offsetTop;}}}setTimeout(function(){_1c.clk=_1c.clk_x=_1c.clk_y=null;},10);});};$.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin");};$.fn.formToArray=function(_1e){var a=[];if(this.length==0){return a;}var _1f=this[0];var els=_1e?_1f.getElementsByTagName("*"):_1f.elements;if(!els){return a;}for(var i=0,max=els.length;i<max;i++){var el=els[i];var n=el.name;if(!n){continue;}if(_1e&&_1f.clk&&el.type=="image"){if(!el.disabled&&_1f.clk==el){a.push({name:n,value:$(el).val()});a.push({name:n+".x",value:_1f.clk_x},{name:n+".y",value:_1f.clk_y});}continue;}var v=$.fieldValue(el,true);if(v&&v.constructor==Array){for(var j=0,_20=v.length;j<_20;j++){a.push({name:n,value:v[j]});}}else{if(v!==null&&typeof v!="undefined"){a.push({name:n,value:v});}}}if(!_1e&&_1f.clk){var _21=$(_1f.clk),_22=_21[0],n=_22.name;if(n&&!_22.disabled&&_22.type=="image"){a.push({name:n,value:_21.val()});a.push({name:n+".x",value:_1f.clk_x},{name:n+".y",value:_1f.clk_y});}}return a;};$.fn.formSerialize=function(_23){return $.param(this.formToArray(_23));};$.fn.fieldSerialize=function(_24){var a=[];this.each(function(){var n=this.name;if(!n){return;}var v=$.fieldValue(this,_24);if(v&&v.constructor==Array){for(var i=0,max=v.length;i<max;i++){a.push({name:n,value:v[i]});}}else{if(v!==null&&typeof v!="undefined"){a.push({name:this.name,value:v});}}});return $.param(a);};$.fn.fieldValue=function(_25){for(var val=[],i=0,max=this.length;i<max;i++){var el=this[i];var v=$.fieldValue(el,_25);if(v===null||typeof v=="undefined"||(v.constructor==Array&&!v.length)){continue;}v.constructor==Array?$.merge(val,v):val.push(v);}return val;};$.fieldValue=function(el,_26){var n=el.name,t=el.type,tag=el.tagName.toLowerCase();if(typeof _26=="undefined"){_26=true;}if(_26&&(!n||el.disabled||t=="reset"||t=="button"||(t=="checkbox"||t=="radio")&&!el.checked||(t=="submit"||t=="image")&&el.form&&el.form.clk!=el||tag=="select"&&el.selectedIndex==-1)){return null;}if(tag=="select"){var _27=el.selectedIndex;if(_27<0){return null;}var a=[],ops=el.options;var one=(t=="select-one");var max=(one?_27+1:ops.length);for(var i=(one?_27:0);i<max;i++){var op=ops[i];if(op.selected){var v=op.value;if(!v){v=(op.attributes&&op.attributes["value"]&&!(op.attributes["value"].specified))?op.text:op.value;}if(one){return v;}a.push(v);}}return a;}return el.value;};$.fn.clearForm=function(){return this.each(function(){$("input,select,textarea",this).clearFields();});};$.fn.clearFields=$.fn.clearInputs=function(){return this.each(function(){var t=this.type,tag=this.tagName.toLowerCase();if(t=="text"||t=="password"||tag=="textarea"){this.value="";}else{if(t=="checkbox"||t=="radio"){this.checked=false;}else{if(tag=="select"){this.selectedIndex=-1;}}}});};$.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset();}});};$.fn.enable=function(b){if(b==undefined){b=true;}return this.each(function(){this.disabled=!b;});};$.fn.selected=function(_28){if(_28==undefined){_28=true;}return this.each(function(){var t=this.type;if(t=="checkbox"||t=="radio"){this.checked=_28;}else{if(this.tagName.toLowerCase()=="option"){var _29=$(this).parent("select");if(_28&&_29[0]&&_29[0].type=="select-one"){_29.find("option").selected(false);}this.selected=_28;}}});};function _2(){if($.fn.ajaxSubmit.debug&&window.console&&window.console.log){window.console.log("[jquery.form] "+Array.prototype.join.call(arguments,""));}};})(jQuery);