function isBlank(formName, fieldName) {
    var fld  = "";
    eval("fld = document."+formName+ "." +fieldName+".value");
    fld = trim(fld);
    if (fld == "") {
        var alrt = "Please Enter "+fieldName;
        alert(alrt);
        eval("document."+formName+"."+fieldName+".focus()");
        return false;
    } else {
        return true;
    }
}
function trim(strInput) {
    return strInput.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
}
function isNumber(formName, fieldName) {
    var t1 = "";
    eval("t1 = document."+formName+ "." +fieldName+".value");
    if ((t1 != "") && (parseFloat(t1) > 0) && !(isNaN(t1))) {
	return true;
    } else {
	alert("Please enter " + fieldName + " as integer number.");
	eval("document."+ formName +"."+fieldName+".focus()");
	eval("document."+ formName +"."+fieldName+".select()");
	return false;
    }
 }
 function isEmailOk(formName, fldName) {
     var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
     var email = "";
     eval("email = document."+formName+ "." + fldName + ".value");
     if (email == "") {
 	alert ('Please enter E-mail address.');
 	eval("document."+formName+ "." + fldName + ".focus()");
 	eval("document."+formName+ "." + fldName + ".select()");
 	return false;
     }
     if (!email.match(re)) {
 	alert ('Check E-mail Address!');
 	eval("document."+formName+ "." + fldName + ".focus()");
 	eval("document."+formName+ "." + fldName + ".select()");
 	return false;
     }
     return true;
 }    

function isCheck(formName, fieldName) {
    var fld  = "";
    eval("fld = document."+formName+ "." +fieldName+".checked");
    if (fld == false) {
    var alrt = "Please agree to the Terms And Conditions";
    alert(alrt);
    return false;
    } else {
        return true;
    }  
}
function isPasswordOk(formName, fieldName1, fieldName2) {
    eval("str = document."+formName+ "." +fieldName1+".value");
    eval("str1 = document."+formName+ "." +fieldName2+".value");

    str = trim(str);
    str1 = trim(str1);
    if (str == "") {
        alert("Enter Your Password.");
        eval("document."+formName+"."+fieldName1+".value=str");
        eval("document."+formName+"."+fieldName1+".select()");
        eval("document."+formName+"."+fieldName1+".focus()");
        return false;
    }
    if(str.length <5) 	{
        alert("Your Password Should be at least 5 Characters.");
        eval("document."+formName+"."+fieldName1+".select()");
        eval("document."+formName+"."+fieldName1+".focus()");
        return false;		
    }
    if (str1 == "") {
        alert("Please Confirm Your Password.");
        eval("document."+formName+"."+fieldName1+".value=str1");
        eval("document."+formName+"."+fieldName2+".select()");
        eval("document."+formName+"."+fieldName2+".focus()");
        return false;
    }
    if (str == str1) { 
    } else {
        alert("Confirm Your Password Again.");    	 
        eval("document."+formName+"."+fieldName2+".value=\"\"");
        eval("document."+formName+"."+fieldName2+".select()");
        eval("document."+formName+"."+fieldName2+".focus()");
        return false;
    }
    return true;
}   
function isPhoneNumber(formName,phone_number,ph1,ph2,ph3) {
    var strNum = 10;
    var country = "mCountry";
    str1 = eval("document."+ formName +"."+ph1+".value");
    str2 = eval("document."+ formName +"."+ph2+".value");
    str3 = eval("document."+ formName +"."+ph3+".value");
    try {
        str1 = trim(str1);
        str2 = trim(str2);
        str3 = trim(str3);
    } catch(e) {}

    if (str1 == "") {
        alert("Please enter area code in phone number.");
        eval("document."+ formName +"."+ph1+".focus()");
        eval("document."+ formName +"."+ph1+".select()");
        return false;
    }
    if (str2 == "") {
        alert("Please check the phone number.");
        eval("document."+ formName +"."+ph2+".focus()");
        eval("document."+ formName +"."+ph2+".select()");
        return false;
    }
    if (str3 == "") {
        alert("Please check the phone number.");
        eval("document."+ formName +"."+ph3+".focus()");
        eval("document."+ formName +"."+ph3+".select()");
        return false;
    }
    var str = str1 + str2 + str3;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1);
        if (ch < "0" || "9" < ch) {
            alert('Phone number should be numeric.');
	    eval("document."+ formName +"."+ph1+".focus()");
	    eval("document."+ formName +"."+ph1+".select()");
	    return false;
        } 
    }
    var cty = "";
    eval("cty = document."+ formName +"."+country+".value");
    
    if(trim(cty) == 'CN') {
        strNum = 11;
    } else {
        strNum = 10;
    }
    if (str.length != strNum) {
        alert("The phone number should have "+strNum+" digits.");
        eval("document."+ formName +"."+ph1+".focus()");
        eval("document."+ formName +"."+ph1+".select()");
        return false;
    }
    eval("document."+ formName +"."+phone_number+".value="+str);
    return true;
}
function autoTab(formName, srcFiled,trgtField) {
    var ph = "";
    eval("ph = document."+formName+"."+srcFiled+".value");
    var phLen = ph.length;
    if(phLen == 3) {
        eval("document."+formName+"."+trgtField+".focus()");
    }
}
function validateLoginForm() {
    if(isBlank('loginForm','userName')&&
        isBlank('loginForm','pwd')) {
        return true;
    } else {
        return false;
    }
}
function showDiv(divName) {
    try {
        document.getElementById(divName).style.display = "block";
    } catch(e) {}
}
function hideDiv(divName) {
    try {
        document.getElementById(divName).style.display = "none";
    } catch(e) {}
}
function isDateOk(formName,myDate,myMonth,myYear) {
    var dd=0;
    var mm=0;
    var yy=0;
    var lp=0;
    dd = eval("document." + formName + "." + myDate  + ".value");
    mm = eval("document." + formName + "." + myMonth + ".value");
    yy = eval("document." + formName + "." + myYear  + ".value");
    if (dd==0 || mm==0 || yy==0) {
        return false;
    }
    if (isNaN(yy)) {
	alert("Please enter " + myYear + " as integer number.");
	eval("document."+ formName +"."+myYear+".select()");
        return false;
    }
    if (yy.length != 4) {
	    alert("Year should be in YYYY format.");
	    eval("document."+ formName +"."+myYear+".select()");
	    return false;
    }
    lp = yy % 4;
    if ( lp==0 && mm==2) {
	if (dd > 29) {
	    alert("Invalid Date. Please check.");
            eval("document." + formName + "." + myDate + ".options[0].selected = true");
	    eval("document." + formName + "." + myDate + ".focus()");
  	    return false;
	}
    } else {
        if (mm==2) {
  	    if (dd>28) {
	 	alert("Invalid Date!!");
		eval("document." + formName + "." + myDate + ".options[0].selected = true");
		eval("document." + formName + "." + myDate + ".focus()");
		return false;
	    }
	} else if ((mm==4) || (mm==6) || (mm==9) || (mm==11)) {
	    if (dd>30) {
		alert("Invalid Date!!");
		eval("document." + formName + "." + myDate + ".options[0].selected = true");
		eval("document." + formName + "." + myDate + ".focus()");
		return false;
	    }
	}
    }
    
    return true;
}
function isZero(formName,fieldName){
    var fld  = "";
    eval("fld = document."+formName+ "." +fieldName+".value");
    fld = trim(fld);
    if (fld == 0) {
        var alrt = "Zero is not valid in "+fieldName;
	alert(alrt);
	eval("document."+formName+"."+fieldName+".focus()");
	return false;
    } else {
	return true;
    }
}

function hideSelectBox() {
     for (f = 0; f < document.forms.length; f++){
         var elements = document.forms[f].elements;
         for (e = 0; e < elements.length; e++){
            if (elements[e].type == "select-one") {
                elements[e].style.visibility = 'hidden';
            }
         }
    }  
}
function showSelectBox() {
     for (f = 0; f < document.forms.length; f++){
         var elements = document.forms[f].elements;
         for (e = 0; e < elements.length; e++){
            if (elements[e].type == "select-one") {
                elements[e].style.visibility = '';
            }
         }
    }  
}
function presetMailMessage() {
    var presetMailNo = document.custEmailForm.preMailSub.value ;
    var url = "getPresetEmail.php";
    var qstr = "preMailNo="+presetMailNo;
    var presetMail = new Array();
    try {
        xmlDoc = getXMLDoc(url,qstr);
    } catch (e) {}
    try {
        subject = xmlDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue;
    } catch (e) {}
    try {
        message = xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue;
    } catch (e) {}
    document.custEmailForm.subject.value = subject;
    document.custEmailForm.message.value = message;
}
function validateCustEmailForm() {
    if(isBlank('custEmailForm','subject')&&
        isBlank('custEmailForm','message')) {
	return true;
    } else {
	return false;
    }
}
function autoTabId(formName, srcFiled,trgtField,fldLen) {
    var fldVal = "";
    eval("fldVal = document."+formName+"."+srcFiled+".value");
    var fldValLen = fldVal.length;
    if(fldValLen == fldLen) {
        eval("document."+formName+"."+trgtField+".focus()");
    }
}
function clearMsg(frmName,fldName) {
    var txtVal = "";
    var replaceVal = "";

    try {
        eval("txtVal = document."+frmName+"."+fldName+".value");
    } catch (e) {}
    
    txtVal = trim(txtVal);
    
    if((txtVal == "Enter Product Name / #") || (txtVal == "Enter Product ID") || (txtVal == "e-mail") || (txtVal == "xxxxxx") || (txtVal == "Enter Quantity") || (txtVal == "Select Quantity")) {
        eval("document."+frmName+"."+fldName+".value = ''");
    } else if(txtVal == "") {
        if(eval("document."+frmName+"."+fldName+".focus()")) {
            eval("document."+frmName+"."+fldName+".value = ''");
        } else {    
            if(frmName == "pdtSearchFrm") {
                replaceVal = "Enter Product Name / #";
            } else if(frmName == "listPdtByNamForm"){
                replaceVal = "Enter Product ID";
            } else if((frmName == "loginForm") || (frmName == "vendorLoginForm")){
                replaceVal = "e-mail";
            } else if((frmName == "itemForm") || (frmName == "itemDetailForm")){
                replaceVal = "Enter Quantity";
            }
            eval("document."+frmName+"."+fldName+".value = '"+replaceVal+"'");
        }    
    }
}
function chkBlank(formName, fieldName,msg) {
    var fld  = "";
    eval("fld = document."+formName+ "." +fieldName+".value");
    fld = trim(fld);
    if (fld == "") {
        var alrt = "Please Enter "+msg;
        alert(alrt);
        eval("document."+formName+"."+fieldName+".focus()");
        return false;
    } else {
        return true;
    }
}
function chkNumber(formName, fieldName,msg) {
    var t1 = "";
    eval("t1 = document."+formName+ "." +fieldName+".value");
    if ((t1 != "") && (parseFloat(t1) > 0) && !(isNaN(t1))) {
	return true;
    } else {
	alert("Please Enter " + msg + " As Valid Numeric.");
	eval("document."+ formName +"."+fieldName+".focus()");
	eval("document."+ formName +"."+fieldName+".select()");
	return false;
    }
 }

/******* modified clear and show text in text field ******/

function clearInputValue(formName, fldName,textValue) {
    var inputValue = "";
    try {
        eval("inputValue = document."+formName+ "." + fldName + ".value");
    } catch(e) {}
    inputValue = trim(inputValue);
    if(inputValue == textValue) {
        try {
            eval("document."+formName+ "." + fldName + ".value = ''");
        } catch(e) {}
    }
} 
function inputClearedValue(formName, fldName,textValue) {
    var inputValue = "";
    try {
        eval("inputValue = document."+formName+ "." + fldName + ".value");
    } catch(e) {}
    inputValue = trim(inputValue);
    if(inputValue == "") {
       try {
            eval("document."+formName+ "." + fldName + ".value = textValue");
        } catch(e) {}
    }
}
/******** Date Validations *********/

function chkValidDt(formName,myDate,msg) {
    var dd=0;
    var mm=0;
    var yy=0;
    var lp=0;
    var len = 0;
    var fromDtArray = new Array();
    fromDt = eval("document." + formName + "." + myDate  + ".value");
    try {
        fromDtArray = fromDt.split("-");
    } catch(e) {}
    if((len > 0) && (len < 3)) {
        
        alert('Invaid Date !!');
        return false;
    } else{
        dd = fromDtArray[2];
        mm = fromDtArray[1];
        yy = fromDtArray[0];        
    }

    if (dd==0 || mm==0 || yy==0)  {
        alert(msg);
        return false;
    }
    
    lp = yy % 4;
    if ( lp==0 && mm==2) {
	if (dd > 29) {
	    alert("Invalid Date. Please check.");
  	    return false;
	}
    } else {
        if (mm==2) {
  	    if (dd>28) {
	 	alert("Invalid Date!!");
		eval("document." + formName + "." + myDate + ".options[0].selected = true");
		return false;
	    }
	} else if ((mm==4) || (mm==6) || (mm==9) || (mm==11)) {
	    if (dd>30) {
		alert("Invalid Date!!");
		return false;
	    }
	}
    }
    return true;
}
function chkDatesOK(formName,fldName1,fldName2) {
    var date1 = "";
    var date2 = "";
    var myDate1 = "";
    var myDate2 = "";
    var myMonth1 = "";
    var myMonth2 = "";
    var myYear1 = "";
    var myYear2 = "";
    var crntDate = new Date();
    var checkInDate = new Date();
    var checkOutDate = new Date();
    var date1Array = new Array();
    var date2Array = new Array();
    try {
        eval("date1 = document."+formName+"."+fldName1+".value");
    } catch(e) {}
    try {
        eval("date2 = document."+formName+"."+fldName2+".value");
    } catch(e) {}
    try {
        date1Array = date1.split("-");
        myDate1 = date1Array[2];
        myMonth1 = date1Array[1]-1;
        myYear1 = date1Array[0];
    } catch(e) {}
    try {
        date2Array = date2.split("-");
        myDate2 = date2Array[2];
        myMonth2 = date2Array[1]-1;
        myYear2 = date2Array[0];
    } catch(e) {}
    try {
        checkInDate.setDate(myDate1);
        checkInDate.setMonth(myMonth1);
        checkInDate.setFullYear(myYear1);
    } catch(e) {}
    try {
        checkOutDate.setDate(myDate2);
        checkOutDate.setMonth(myMonth2);
        checkOutDate.setFullYear(myYear2);
    } catch(e) {}
    if (checkInDate <= checkOutDate ) {
            return true;
    } else {
            alert("Please check your dates");
            return false;
    }
}

function replaceCommaValues(strInput1) {
    strInput = strInput1.replace(/,/g,'');
    strInput = strInput.replace(/ /g,'');
    strInput = strInput.replace('!@#$%^&*()','');
    strInput = strInput.replace('@','');
    strInput = strInput.replace('#','');
    strInput = strInput.replace('$','');
    strInput = strInput.replace('%','');
    strInput = strInput.replace('^','');
    strInput = strInput.replace('&','');
    strInput = strInput.replace('*','');
    strInput = strInput.replace('(','');
    strInput = strInput.replace(')','');
    strInput = strInput.replace(/[a-zA-Z]/g,'');
    strInput = trim(strInput);
    return strInput;
}

/******** Method To Reset Form *********/
    function resetFrm(frmName) {
        var fieldsArray = new Array("searchTerm","fromDt","toDt");
    
        for(var i in fieldsArray) {
            var fldName = fieldsArray[i];
            eval("document."+frmName+"."+fldName+".value=''");
        }

    }
function fillMyMsg(formName,fieldName, defaultValue) {
   var msg = "";
   try {
       eval("msg = document."+formName+"."+fieldName+".value");
       if(msg == "") {
           eval("document."+formName+"."+fieldName+".value = defaultValue");               
       } 
   } catch(e) {}
}

function clearMyMsg(formName,fieldName, defaultValue) {
   var msg = "";
   try {
       eval("msg = document."+formName+"."+fieldName+".value");
       if(msg == defaultValue) {
           eval("document."+formName+"."+fieldName+".value = ''");
       } 
   } catch(e) {}
}

function chkValidDtN(formName,myDate,msg) {
    var dd=0;
    var mm=0;
    var yy=0;
    var lp=0;
    var len = 0;
    var fromDtArray = new Array();
    fromDt = eval("document." + formName + "." + myDate  + ".value");
    
    try {
        fromDtArray = fromDt.split("-");
    } catch(e) {}
    if((len > 0) && (len < 3)) {
        
        alert('Invaid Date !!');
        return false;
    } else{
        dd = fromDtArray[1];
        mm = fromDtArray[0];
        yy = fromDtArray[2];        
    }

    if (dd==0 || mm==0 || yy==0)  {
        alert(msg);
        return false;
    }
    
    lp = yy % 4;
    if ( lp==0 && mm==2) {
	if (dd > 29) {
	    alert("Invalid Date. Please check.");
  	    return false;
	}
    } else {
        if (mm==2) {
  	    if (dd>28) {
	 	alert("Invalid Date!!");
		eval("document." + formName + "." + myDate + ".options[0].selected = true");
		return false;
	    }
	} else if ((mm==4) || (mm==6) || (mm==9) || (mm==11)) {
	    if (dd>30) {
		alert("Invalid Date!!");
		return false;
	    }
	}
    }
    return true;
}
function chkDatesOKN(formName,fldName1,fldName2) {
    var date1 = "";
    var date2 = "";
    var myDate1 = "";
    var myDate2 = "";
    var myMonth1 = "";
    var myMonth2 = "";
    var myYear1 = "";
    var myYear2 = "";
    var crntDate = new Date();
    var checkInDate = new Date();
    var checkOutDate = new Date();
    var date1Array = new Array();
    var date2Array = new Array();
    try {
        eval("date1 = document."+formName+"."+fldName1+".value");
    } catch(e) {}
    try {
        eval("date2 = document."+formName+"."+fldName2+".value");
    } catch(e) {}
    try {
        date1Array = date1.split("-");
        myDate1 = date1Array[1];
        myMonth1 = date1Array[0]-1;
        myYear1 = date1Array[2];
    } catch(e) {}
    try {
        date2Array = date2.split("-");
        myDate2 = date2Array[1];
        myMonth2 = date2Array[0]-1;
        myYear2 = date2Array[2];
    } catch(e) {}
    try {
        checkInDate.setDate(myDate1);
        checkInDate.setMonth(myMonth1);
        checkInDate.setFullYear(myYear1);
    } catch(e) {}
    try {
        checkOutDate.setDate(myDate2);
        checkOutDate.setMonth(myMonth2);
        checkOutDate.setFullYear(myYear2);
    } catch(e) {}
    if (checkInDate <= checkOutDate ) {
            return true;
    } else {
            alert("Please check your dates");
            return false;
    }
}
function kgsToLbsConverter(kgsVal) {
    var lbsVal = "";
    var factor = 2.2;
    lbsVal = kgsVal * 2.2;
    lbsVal = ((lbsVal*100)/100).toFixed(2);
    return lbsVal;
}

function lbsToKgsConverter(lbsVal) {
    var kgsVal = "";
    var factor = 2.2;
    kgsVal = lbsVal / 2.2;
    kgsVal = ((kgsVal*100)/100).toFixed(2);
    return kgsVal;
}
function cmToInConverter(cmVal) {
   var inVal = "";
   inVal = cmVal * 0.3937008;
   inVal = ((10*inVal)/10).toFixed(2);
   return inVal;
}
function inToCmConverter(inVal) {
   var cmVal = "";
   cmVal = inVal * 2.54;
   cmVal = ((10*cmVal)/10).toFixed(2);
   return cmVal;
}


function validateSearchForm() {
    if(document.pdtSearchFrm.search.value == 'Type Product Name / # to search') {
	alert("Please Enter Product IDs, Names, etc.. ");
	document.pdtSearchFrm.search.focus();
	return false;
    } else {    
	if(chkBlank("pdtSearchFrm","search","Product IDs, Names, etc.. ")) {
	    return true;
	} else {
	    document.pdtSearchFrm.search.value = "";
	    return false;
	}
    }    
}


function checkBlankHidden(formName, fieldName,alertMsg) {
    var fld  = "";
    var fld1  = "";
    var fld2 = "";
    try {
        eval("fld = document."+formName+ "." +fieldName+".value");
        fld = trim(fld);
    } catch(e) {}
    try {
        eval("fld1 = document."+formName+ "." +fieldName+"Chk.value");
        fld1 = trim(fld1);
    } catch(e) {}
    var url = "getEncCaptcha.php";
    var qstr = "fld1="+fld1;
    try {
         xmlDoc = getXMLDoc(url,qstr);
    } catch (e) {}
    try {
         fld2 = xmlDoc.getElementsByTagName("encCaptcha")[0].firstChild.nodeValue;
    } catch(e) {}
    try {
        clearMsg("div_"+msgFld);
    } catch(e) {}
    if(fld == "") {
    alert("Please enter the verification code");
//	document.getElementById("div_"+msgFld).innerHTML = "<img src=\"images/msg-arrow.gif\">&nbsp;"+alertMsg;
//        document.getElementById("div_"+msgFld).style.display = "block";
    } else if(fld2 == fld) {
    } else {
        alert("Please check your code");
        return  false;

//	document.getElementById("div_"+msgFld).innerHTML = "<img src=\"images/msg-arrow.gif\">&nbsp;Please check your code";
//        document.getElementById("div_"+msgFld).style.display = "block";
    }
    return fld;
/*   
    if(fld == "") {
	document.getElementById("div_"+msgFld).innerHTML = "<img src=\"images/msg-arrow.gif\">&nbsp;"+alertMsg;
        document.getElementById("div_"+msgFld).style.display = "block";
    } else if(fld1 == fld) {
    } else {
	document.getElementById("div_"+msgFld).innerHTML = "<img src=\"images/msg-arrow.gif\">&nbsp;Please check your code";
        document.getElementById("div_"+msgFld).style.display = "block";
    }
    return fld;
*/
    
}
