  function test(regex, current) {
        var re = new RegExp(regex);
        for (i = 0; i < document.forms[0].elements.length; i++) {
            elm = document.forms[0].elements[i];
            if (elm.type == "checkbox") {
                if (re.test(elm.name)) {
                    elm.checked = false;
                }
            }
        }
        current.checked = true;
    }
    

    function blank(fld) {
        fld.select();
    }

    function callme(frm, val) {
        if (frm.value === "") {
            frm.value = val;
        }
    }

    function changeBox() {
        document.getElementById("div1").style.display = "none";
        document.getElementById("div2").style.display = "";
        document.getElementById("txtpassword").select();
        document.getElementById("txtpassword").focus();
    }

    function restoreBox() {
        if (document.getElementById("txtpassword").value === "") {
            document.getElementById("div1").style.display = "";
            document.getElementById("div2").style.display = "none";
        }
    }

    function changeBoxL() {
        document.getElementById("div5").style.display = "none";
        document.getElementById("div6").style.display = "";
        document.getElementById("txtpass").select();
        document.getElementById("txtpass").focus();
    }

    function restoreBoxL() {
        if (document.getElementById("txtpass").value === "") {
            document.getElementById("div5").style.display = "";
            document.getElementById("div6").style.display = "none";
        }
    }

    function changeBox1() {
        document.getElementById("div3").style.display = "none";
        document.getElementById("div4").style.display = "";
        document.getElementById("txtpassword2").select();
        document.getElementById("txtpassword2").focus();
    }

    function restoreBox1() {
        if (document.getElementById("txtpassword2").value === "") {
            document.getElementById("div3").style.display = "";
            document.getElementById("div4").style.display = "none";
        }
    }


    function trimMe(str) {
        while (true) {
            if (str.charAt(0) == " ") {
                str = str.substr(1);
            } else {
                break;
            }
        }
        while (true) {
            if (str.charAt(str.length - 1) == " ") {
                str = str.substr(0, str.length - 1);
            } else {
                break;
            }
        }
        return str;
    }


    function validate() {
        if (trimMe(document.frmlogin.txtuser.value) === "" ||
            trimMe(document.frmlogin.txtuser.value) == "Email address") {
            alert("Please Enter Username.");
            document.frmlogin.txtuser.select();
            return false;
        }
        if (trimMe(document.frmlogin.txtpass.value) === "" ||
            trimMe(document.frmlogin.txtpass.value) == "Password") {
            alert("Please Enter Password.");
            document.frmlogin.txtpass.select();
            return false;
        }
        return true;
    }





    function validateme() {
        var hph_no = document.frmregistration.txtphone.value;
        var cph_no = document.frmregistration.txtcell_phone.value;
        var wph_no = document.frmregistration.txtwork_phone.value;
        flag = 0;
        for (var i = 0; i < document.frmregistration.length; i++) {
            cntrtype = document.frmregistration.elements[i].type;
            current = document.frmregistration.elements[i];
            if (cntrtype == "checkbox") {
                if (document.frmregistration.elements[i].checked) {
                    document.frmregistration.HID.value = current.name;
                    bestcontact = document.frmregistration.elements[i].value;
                    flag = 1;
                }
            }
        }
        if (trimMe(document.frmregistration.txtusername.value) === "" ||
            trimMe(document.frmregistration.txtusername.value) == "Email address*") {
            alert("Please Enter Username.");
            document.frmregistration.txtusername.select();
            return false;
        } else {
            var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
            var returnval = emailfilter.test(document.frmregistration.txtusername.value);
            if (returnval === false) {
                alert("Please Enter a valid Email-Id.");
                document.frmregistration.txtusername.select();
                return false;
            }
        }
        if (trimMe(document.frmregistration.txtusernameconf.value) === "" ||
            trimMe(document.frmregistration.txtusernameconf.value) == "Confirm email address*") {
            alert("Please Confirm Username.");
            document.frmregistration.txtusernameconf.select();
            return false;
        } else {
            var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
            var returnval1 = emailfilter.test(document.frmregistration.txtusernameconf.value);
            if (returnval1 === false) {
                alert("Please Enter a valid Email-Id.");
                document.frmregistration.txtusernameconf.select();
                return false;
            }
        }
        if (trimMe(document.frmregistration.txtusername.value) !== trimMe(document.frmregistration.txtusernameconf.value)) {
            alert("Please verify your email address again.");
            document.frmregistration.txtusernameconf.select();
            return false;
        }
        if (document.getElementById("div2")) {
            if (document.getElementById("div2").style.display == "none") {
                if (trimMe(document.frmregistration.txtpassword.value) === "" ||
                    trimMe(document.frmregistration.txtpassword.value) == "Password*") {
                    alert("Please Enter Password.");
                    document.frmregistration.txtpassword.focus();
                    return false;
                }
            }
        } else {
        	if(trimMe(document.frmregistration.txtpassword.value) === "") {
				alert("Please Re-Enter Your Password.");
				document.frmregistration.txtpassword.focus();
				return false;
        	}
        }
        if (document.getElementById("div4")) {
            if (document.getElementById("div4").style.display == "none") {
                if (trimMe(document.frmregistration.txt_password2.value) === "" ||
                    trimMe(document.frmregistration.txt_password2.value) == "Confirm password*") {
                    alert("Please Enter Confirm Your Password.");
                    document.frmregistration.txt_password2.focus();
                    return false;
                }
            }
        } else {
        	if (trimMe(document.frmregistration.txt_password2.value) === "") {
		        alert("Please Re-Enter Confirm Password.");
				document.frmregistration.txtpassword.focus();
				return false;
			}
		}
        if (document.frmregistration.txtpassword2) {
			if (trimMe(document.frmregistration.txtpassword.value) !== trimMe(document.frmregistration.txtpassword2.value)) {
				alert("Please verify your password again.");
				document.frmregistration.txtpassword2.focus();
				return false;
			}
		} else {
			if (trimMe(document.frmregistration.txtpassword.value) !== trimMe(document.frmregistration.txt_password2.value)) {
				alert("Your Passwords Don't Match.");
				document.frmregistration.txtpassword2.focus();
				return false;
			}
		}
        if (trimMe(document.frmregistration.txtfirstname.value) === "" ||
            trimMe(document.frmregistration.txtfirstname.value) == "First name*") {
            alert("Please Enter Your First Name.");
            document.frmregistration.txtfirstname.focus();
            return false;
        }
        if (trimMe(document.frmregistration.txtlastname.value) === "" ||
            trimMe(document.frmregistration.txtlastname.value) == "Last name*") {
            alert("Please Enter Your Last Name.");
            document.frmregistration.txtlastname.focus();
            return false;
        }
        if (trimMe(document.frmregistration.txtaddress.value) === "" ||
            trimMe(document.frmregistration.txtaddress.value) == "Address 1*") {
            alert("Please Enter Address 1.");
            document.frmregistration.txtaddress.focus();
            return false;
        }
        if (trimMe(document.frmregistration.txtcity.value) === "" ||
            trimMe(document.frmregistration.txtcity.value) == "City*") {
            alert("Please Enter City Name.");
            document.frmregistration.txtcity.focus();
            return false;
        }
        if (trimMe(document.frmregistration.select_state.value) === "" ||
            trimMe(document.frmregistration.select_state.value) == "State/Province*") {
            alert("Please Enter State Name.");
            document.frmregistration.select_state.focus();
            return false;
        }
        if (trimMe(document.frmregistration.select_state.value) == "Other" &&
            (trimMe(document.frmregistration.otherselect_state.value) === "" ||
            trimMe(document.frmregistration.otherselect_state.value) == "State*")) {
            alert("Please Enter State Name.");
            document.frmregistration.otherselect_state.focus();
            return false;
        }
        if (trimMe(document.frmregistration.txtzipcode.value) === "" ||
            trimMe(document.frmregistration.txtzipcode.value) == "Zip*") {
            alert("Please Enter Zipcode.");
            document.frmregistration.txtzipcode.focus();
            return false;
        } else {
            var serchar = document.frmregistration.txtzipcode.value.search(/-/);
            if (serchar >= 0) {
                alert("Please Enter valid Zipcode.");
                document.frmregistration.txtzipcode.focus();
                return false;
            }
        }
        if (hph_no.length < 10) {
            alert("Invalid Phone Number. It should be 10 digits.");
            document.frmregistration.txtphone.focus();
            return false;
        }
        if (document.frmregistration.txtcell_phone.value !== "" &&
            document.frmregistration.txtcell_phone.value !== "Cell Phone") {
            if (cph_no.length < 10) {
                alert("Invalid Phone Number. It should be 10 digit.");
                document.frmregistration.txtcell_phone.focus();
                return false;
            }
        }
        if (document.frmregistration.txtcell_phone.value !== "" &&
            document.frmregistration.txtcell_phone.value !== "Work Phone") {
            if (wph_no.length < 10) {
                alert("Invalid Phone no. It should be 10 digits.");
                document.frmregistration.txtcell_phone.focus();
                return false;
            }
        }
        if (flag === 0) {
            alert("Please select your contact preference.");
            return false;
        }
        if (bestcontact == "homephone") {
            if (document.frmregistration.txtphone.value === "" ||
                document.frmregistration.txtphone.value == "Home Phone") {
                alert("Okay. Could you please give me that home phone number?");
                document.frmregistration.txtphone.focus();
                return false;
            }
            if (document.frmregistration.txtphone.value !== "" &&
                document.frmregistration.txtphone.value !== "Home Phone") {
                if (hph_no.length < 10) {
                    alert("Invalid home phone Number. It should be 10 digits.");
                    document.frmregistration.txtphone.focus();
                    return false;
                }
            }
            
        }
        if (bestcontact == "cellphone") {
            if (document.frmregistration.txtcell_phone.value === "" ||
                document.frmregistration.txtcell_phone.value == "Cell Phone") {
                alert("Okay. Could you please give me that cell phone number?");
                document.frmregistration.txtcell_phone.focus();
                return false;
            }
            if (document.frmregistration.txtcell_phone.value !== "" &&
                document.frmregistration.txtcell_phone.value !== "Cell Phone") {
                if (cph_no.length < 10) {
                    alert("Invalid cell phone no. It should be 10 digit");
                    document.frmregistration.txtcell_phone.focus();
                    return false;
                }
            }
            
        }
        if (bestcontact == "workphone") {
            if (document.frmregistration.txtwork_phone.value === "" ||
                document.frmregistration.txtwork_phone.value == "Work Phone") {
                alert("Okay. Could you please give me that work phone number?");
                document.frmregistration.txtwork_phone.focus();
                return false;
            }
            if (document.frmregistration.txtwork_phone.value !== "" &&
                document.frmregistration.txtwork_phone.value !== "Work Phone") {
                if (wph_no.length < 10) {
                    alert("Invalid work phone no. It should be 10 digit");
                    document.frmregistration.txtwork_phone.focus();
                    return false;
                }
            }
            
        }
        return true;
    }


    function ccfield(obj) {
/*        if (obj !== "United States~226" && obj !== "Canada~38") {
            document.frmregistration.ccwork_phone.style.visibility = "visible";
            document.frmregistration.cccell_phone.style.visibility = "visible";
            document.frmregistration.ccphone.style.visibility = "visible";
        } else {
            document.frmregistration.ccwork_phone.style.visibility = "hidden";
            document.frmregistration.cccell_phone.style.visibility = "hidden";
            document.frmregistration.ccphone.style.visibility = "hidden";
            document.frmregistration.ccwork_phone.value = "CC";
            document.frmregistration.cccell_phone.value = "CC";
            document.frmregistration.ccphone.value = "CC";
        } */
    }


    function otherchange(obj) {
        if (obj == "Other") {
            document.getElementById("otherstate").style.display = "block";
        } else {
            document.getElementById("otherstate").style.display = "none";
        }
    }


    function checkNumber(e) {
        var charCode = e.which ? e.which : e.keyCode;
        if (charCode >= 48 && charCode <= 57 ||
            charCode == 9 || charCode == 8) {
            return true;
        }
        return;
    }


    function ajaxUpdater(id, obj, url, type, tab) {
        cid = obj.split("~");
        url = url + "?countryid=" + cid[1] + "&type=" + type + "&tab=" + tab;
        new (Ajax.Updater)(id, url, {asynchronous: true, evalScripts: true});
    }


    function validateitemdesc() {
        if (document.page_frm.txtamanu.value === "" ||
            document.page_frm.txtamanu.value == "Manufacturer/Brand") {
            alert("Manufacturer/Brand is required.");
            document.page_frm.txtamanu.focus();
            return false;
        }
        if (document.page_frm.etgvalid.value == "ETG" ||
            document.page_frm.etgvalid.value == "GAR") {
            if (document.page_frm.textotherinfo.value === "") {
                alert("Item description is required.");
                document.page_frm.textotherinfo.focus();
                return false;
            }
        }
        if (document.page_frm.whereBuy.value === "") {
            alert("Could you please tell us where you purchased this eTriever?");
            document.page_frm.whereBuy.focus();
            return false;
        }
        return true;
    }


    function changeBoxaddEt() {
        document.getElementById("div1").style.display = "none";
        document.getElementById("div2").style.display = "";
        document.getElementById("addiET").focus();
    }


    function restoreBoxaddEt() {
        if (document.getElementById("addiET").value === "") {
            document.getElementById("div1").style.display = "";
            document.getElementById("div2").style.display = "none";
        }
    }


    function validateaddEt() {
        flag = 0;
        for (var i = 0; i < document.page_frm.length; i++) {
            cntrtype = document.page_frm.elements[i].type;
            current = document.page_frm.elements[i];
            if (cntrtype == "radio") {
                if (document.page_frm.elements[i].checked) {
                    flag = 1;
                }
            }
        }
        if(document.getElementById("div2")) {
			if (document.getElementById("div2").style.display == "none") {
				if (document.page_frm.txtaddiET.value === "" ||
					document.page_frm.txtaddiET.value == "eTriever") {
					alert("eTriever number is required.");
					document.page_frm.txtaddiET.focus();
					return false;
				}
			}
        } else if (document.page_frm.txtaddiET.value === "" ||
				document.page_frm.txtaddiET.value == "eTriever") {
				alert("eTriever number is required.");
				document.page_frm.txtaddiET.focus();
				return false;
		} else if (document.page_frm.txtaddiET.value !== "" ||
                document.page_frm.txtaddiET.value !== "eTriever") {
			var et = document.page_frm.txtaddiET.value;
			if (et.substring(0, 3).toUpperCase() == "ETG" ||
				et.substring(0, 3).toUpperCase() == "GAR") {
				if (document.page_frm.textotherinfo.value === "") {
					alert("Item description is required.");
					document.page_frm.textotherinfo.focus();
					return false;
				}
			}
        }
        if (flag === 0) {
            alert("Please select an item type");
            return false;
        }
        if (document.page_frm.txtamanu.value === "" ||
            document.page_frm.txtamanu.value == "Manufacturer/Brand") {
            alert("Manufacturer/Brand is required.");
            document.page_frm.txtamanu.focus();
            return false;
        }
        if (document.getElementById("div2")){ 
			if (document.getElementById("div2").style.display === "") {
				if (document.page_frm.addiET.value !== "" ||
					document.page_frm.addiET.value !== "eTriever") {
					var et = document.page_frm.addiET.value;
					if (et.substring(0, 3).toUpperCase() == "ETG" ||
						et.substring(0, 3).toUpperCase() == "GAR") {
						if (document.page_frm.textotherinfo.value === "") {
							alert("Item description is required.");
							document.page_frm.textotherinfo.focus();
							return false;
						}
					}
				}
			}
        }
        if (document.page_frm.whereBuy.value === "") {
            alert("Could you please tell us where you purchased this eTriever?");
            document.page_frm.whereBuy.focus();
            return false;
        }
        return true;
    }


    function changeInnerHtml() {
        var et = document.page_frm.addiET.value;
        if (et.substring(0, 3).toUpperCase() == "ETG" ||
            et.substring(0, 3).toUpperCase() == "GAR") {
            document.getElementById("asterisk").innerHTML = "*";
        } else {
            document.getElementById("asterisk").innerHTML = "";
        }
        if (et.substring(0, 3).toUpperCase() == "GAR") {
            document.getElementById("chnageinner").innerHTML = "Please describe the garment you have protected with Global Lost & Found's recovery service.";
        } else {
            document.getElementById("chnageinner").innerHTML = "If there are unique features, distinguishing marks or condition issues that might help us distinguish your item from others, you may note them here (optional).";
        }
    }


    function rfound(obj, a) {
        document.reportfound.mailname.value = a;
        document.reportfound.rfetracker.value = obj;
        document.reportfound.submit();
    }


    function statusRecovery(obj, a) {
        document.statusrecovery.actiontype.value = a;
        document.statusrecovery.sretracker.value = obj;
        document.statusrecovery.submit();
    }


    function regdate(obj, a) {
        document.regdatefrm.etracker.value = obj;
        document.regdatefrm.submit();
    }


    function delsectionvalid() {
        var g = confirm("Are you sure to delete?");
        if (!g) {
            return false;
        }
        return true;
    }


    function validateFounderItemDesc() {
        flag = 0;
        flag1 = 0;
        for (var i = 0; i < document.frmregistration.length; i++) {
            cntrtype = document.frmregistration.elements[i].type;
            current = document.frmregistration.elements[i];
            if (cntrtype == "checkbox" &&
                document.frmregistration.elements[i].name !== "best_contact_way") {
                if (document.frmregistration.elements[i].checked) {
                    document.frmregistration.HID.value = current.name;
                    flag = 1;
                }
            }
        }
        if (flag == 0) {
            alert("Please select an item type");
            return false;
        }
        if (document.frmregistration.txtfirstname.value === "" ||
            document.frmregistration.txtfirstname.value == "First Name*") {
            alert("Please Enter First Name");
            return false;
        } else if (document.frmregistration.txtlastname.value === "" ||
            document.frmregistration.txtlastname.value == "Last Name*") {
            alert("Please Enter Last Name");
            return false;
        } else if (document.frmregistration.txtaddress.value === "" ||
            document.frmregistration.txtaddress.value == "Address 1*") {
            alert("Please Enter Address1");
            return false;
        } else if (document.frmregistration.txtcity.value === "" ||
            document.frmregistration.txtcity.value == "City*") {
            alert("Please Enter City");
            return false;
        } else if (document.frmregistration.select_state.value === "" ||
            document.frmregistration.select_state.value == "State*") {
            alert("Please Enter State");
            return false;
        } else if (document.frmregistration.txtzipcode.value === "" ||
            document.frmregistration.txtzipcode.value == "Zip*") {
            alert("Please Enter Zip Code");
            return false;
        } else if (document.frmregistration.txtphone.value === "" ||
            document.frmregistration.txtphone.value == "Phone*") {
            alert("Please Enter Phone Number");
            return false;
        } else if (document.frmregistration.txtphone.value !== "" &&
            document.frmregistration.txtphone.value !== "Phone*") {
            var ph_no = document.frmregistration.txtphone.value;
            if (ph_no.length < 10) {
                alert("Invalid Phone no. It should be 10 digit");
                document.frmregistration.txtphone.focus();
                return false;
            }
        }
        if (document.frmregistration.txtemail.value === "" ||
            document.frmregistration.txtemail.value == "Email Address*") {
            alert("Please Enter Email Address");
            return false;
        } else {
            var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
            var returnval = emailfilter.test(document.frmregistration.txtemail.value);
            if (returnval === false) {
                alert("Please Enter a valid Email-Id.");
                document.frmregistration.txtemail.select();
                return false;
            }
        }
        for (var i = 0; i < document.frmregistration.length; i++) {
            cntrtype = document.frmregistration.elements[i].type;
            if (cntrtype == "checkbox" &&
                document.frmregistration.elements[i].name == "best_contact_way") {
                if (document.frmregistration.elements[i].checked) {
                    flag1 = 1;
                }
            }
        }
        if (flag1 == 0) {
            alert("Please select your contact preference");
            return false;
        }
        return true;
    }


    function validcontact() {
        if (document.contactus_frm.txt_name.value === "" ||
            document.contactus_frm.txt_name.value == "Your Name*") {
            alert("Please Enter your name.");
            document.contactus_frm.txt_name.focus();
            return false;
        }
        if (document.contactus_frm.txt_email.value === "" ||
            document.contactus_frm.txt_name.value == "Your Email address*") {
            alert("Please Enter your emailid.");
            document.contactus_frm.txt_email.focus();
            return false;
        } else {
            var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
            var returnval = emailfilter.test(document.contactus_frm.txt_email.value);
            if (returnval == false) {
                alert("Please Enter a valid Email-Id.");
                document.contactus_frm.txt_email.select();
                return false;
            }
        }
        if (document.contactus_frm.txt_subject.value === "" ||
            document.contactus_frm.txt_subject.value == "Subject*") {
            alert("Please Enter your Subject.");
            document.contactus_frm.txt_subject.focus();
            return false;
        }
        if (document.contactus_frm.txt_message.value === "" ||
            document.contactus_frm.txt_message.value == "Message*") {
            alert("Please Enter your Message.");
            document.contactus_frm.txt_message.focus();
            return false;
        }
        return true;
    }


    function changeBoxLogin() {
        document.getElementById("div5").style.display = "none";
        document.getElementById("div6").style.display = "block";
        document.getElementById("txtpass").select();
        document.getElementById("txtpass").focus();
    }


    function restoreBoxLogin() {
        if (document.getElementById("txtpass").value === "") {
            document.getElementById("div5").style.display = "block";
            document.getElementById("div6").style.display = "none";
        }
    }


    function validatelogin() {
        if (trimMe(document.frmlogin.txtuser.value) === "" ||
            trimMe(document.frmlogin.txtuser.value) == "Email address") {
            alert("Please Enter Username.");
            document.frmlogin.txtuser.focus();
            document.frmlogin.txtuser.select();
            return false;
        }
        if (document.getElementById("div6").style.display == "none") {
            if (trimMe(document.frmlogin.txt_password.value) === "" ||
                trimMe(document.frmlogin.txt_password.value) == "Password") {
                alert("Please Enter Password.");
                document.frmlogin.txt_password.focus();
                document.frmlogin.txt_password.select();
                return false;
            }
        }
        return true;
    }


    function validateForgot() {
        if (trimMe(document.frmforgot_pass.txtuser.value) === "" ||
            document.frmforgot_pass.txtuser.value == "Enter your email address*") {
            alert("Please specify Username");
            document.frmforgot_pass.txtuser.focus();
            document.frmforgot_pass.txtuser.select();
            return false;
        }
        var id = document.frmforgot_pass.txtuser.value;
        if (id.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) !== -1) {
            return true;
        } else {
            alert("Invalid Username!");
            document.frmforgot_pass.txtuser.focus();
            document.frmforgot_pass.txtuser.select();
            return false;
        }
        return true;
    }