function setStateFields(formid,value) { if(value == 'United States') { document.getElementById('usstate').style.display=''; document.getElementById('intlstate').style.display='none'; document.getElementById('canprov').style.display='none'; document.getElementById('bcc').style.display = 'none'; } else if(value == 'Canada') { document.getElementById('canprov').style.display=''; document.getElementById('intlstate').style.display='none'; document.getElementById('usstate').style.display='none'; document.getElementById('bcc').style.display = ''; getCountryCode(document.forms[formid].bcountry[document.forms[formid].bcountry.selectedIndex].value,'',formid); } else { document.getElementById('intlstate').style.display=''; document.getElementById('canprov').style.display='none'; document.getElementById('usstate').style.display='none'; document.getElementById('bcc').style.display = ''; getCountryCode(document.forms[formid].bcountry[document.forms[formid].bcountry.selectedIndex].value,'',formid); } } function setShipStateFields(formid,value) { if(value == 'United States') { document.getElementById('shipusstate').style.display=''; document.getElementById('shipintlstate').style.display='none'; document.getElementById('shipcanprov').style.display='none'; document.getElementById('shipbcc').style.display = 'none'; } else if(value == 'Canada') { document.getElementById('shipcanprov').style.display=''; document.getElementById('shipintlstate').style.display='none'; document.getElementById('shipusstate').style.display='none'; document.getElementById('shipbcc').style.display = ''; getCountryCode(document.forms[formid].scountry[document.forms[formid].scountry.selectedIndex].value,'',formid); } else { document.getElementById('shipintlstate').style.display=''; document.getElementById('shipcanprov').style.display='none'; document.getElementById('shipusstate').style.display='none'; document.getElementById('shipbcc').style.display = ''; getCountryCode(document.forms[formid].scountry[document.forms[formid].scountry.selectedIndex].value,'',formid); } } function checkPayInfo() { var err_read = ""; var error_fields = new Array(); if (document.forms['processpayment'].cc_name.value == "") { err_read += "You must provide your name as it appears on your credit card.\n"; error_fields[error_fields.length] = "cc_name"; } if (document.forms['processpayment'].cc_num.value == "") { err_read += "You must provide your credit card number.\n"; error_fields[error_fields.length] = "cc_num"; } if (document.forms['processpayment'].cc_sec_code.value == "") { err_read += "You must provide your security code.\n"; error_fields[error_fields.length] = "cc_sec_code"; } if (err_read == "") { document.forms['processpayment'].submit(); } else { err_read = "We found the following omissions in your form: \n" + err_read; var thefield = error_fields[0]; alert(err_read); document.forms['processpayment'][thefield].focus(); } } // end function function checkUser(formid,the_email) { if(document.forms[formid].sameinfobox.checked == true) { sameinfo("billinginfo"); } // alert(formid); // return; var err_read = ""; var error_fields = new Array(); var statefrom; if (document.forms[formid].bfirstname.value == "") { err_read += "You must provide your first name.\n"; error_fields[error_fields.length] = "bfirstname"; } if (document.forms[formid].blastname.value == "") { err_read += "You must provide your last name.\n"; error_fields[error_fields.length] = "blastname"; } var emailok = ""; var the_at = the_email.indexOf("@"); var the_dot = the_email.lastIndexOf("."); var a_space = the_email.indexOf(" "); if ((the_at != -1) && (the_at != 0) && (the_dot != -1) && (the_dot > the_at +1) && (the_dot < the_email.length -1) && (a_space == -1)) { emailok == "1"; } else { emailok == ""; err_read += "Your email address is not in the correct format.\n"; error_fields[error_fields.length] = "bemail"; } if (!document.forms[formid].bcountry.selectedIndex > 0){ err_read += "You must provide your Country\n"; error_fields[error_fields.length] = "bcountry"; } n = document.forms[formid].bcountry.selectedIndex; if (document.forms[formid].baddress1.value == "") { err_read += "You must provide your address.\n"; error_fields[error_fields.length] = "baddress1"; } if (document.forms[formid].bcity.value == "") { err_read += "You must provide your city.\n"; error_fields[error_fields.length] = "bcity"; } if (document.forms[formid].bcountry[n].value == "United States"){ statefrom = "us_state"; //set flag to let php know where billing state field is comming from if (!document.forms[formid].us_state.selectedIndex > 0){ err_read+= "You must indicate your State.\n"; error_fields[error_fields.length] = "us_state"; } } if (document.forms[formid].bcountry[n].value == "Canada"){ statefrom = "can_prov"; //set flag to let php know where billing state field is comming from if (!document.forms[formid].can_prov.selectedIndex > 0){ err_read += "You must indicate your Province.\n"; error_fields[error_fields.length] = "can_prov"; } } if (document.forms[formid].bcountry[n].value != "Canada" && document.forms[formid].bcountry[n].value != "United States" ){ statefrom = "intl_state"; //set flag to let php know where billing state field is comming from if (document.forms[formid].intl_state.value == "") { err_read += "You must provide your Province/Region/State information\n"; error_fields[error_fields.length] = "intl_state"; } } if (document.forms[formid].bzipcode.value == "") { err_read += "You must provide your postal code.\n"; error_fields[error_fields.length] = "bzipcode"; } if (document.forms[formid].bphone.value == "") { err_read += "You must provide your phone.\n"; error_fields[error_fields.length] = "bphone"; } // SHIPPING CHECK if (document.forms[formid].sfirstname.value == "") { err_read += "You must provide the shippng first name.\n"; error_fields[error_fields.length] = "sfirstname"; } if (document.forms[formid].slastname.value == "") { err_read += "You must provide shipping last name.\n"; error_fields[error_fields.length] = "slastname"; } if (!document.forms[formid].scountry.selectedIndex > 0){ err_read += "You must provide the shipping Country\n"; error_fields[error_fields.length] = "scountry"; } n = document.forms[formid].scountry.selectedIndex; if (document.forms[formid].saddress1.value == "") { err_read += "You must provide the shipping address.\n"; error_fields[error_fields.length] = "saddress1"; } if (document.forms[formid].scity.value == "") { err_read += "You must provide the shipping city.\n"; error_fields[error_fields.length] = "scity"; } if (document.forms[formid].scountry[n].value == "United States"){ shipstatefrom = "ship_us_state"; //set flag to let php know where billing state field is comming from if (!document.forms[formid].ship_us_state.selectedIndex > 0){ err_read+= "You must indicate the shipping State.\n"; error_fields[error_fields.length] = "ship_us_state"; } } if (document.forms[formid].scountry[n].value == "Canada"){ shipstatefrom = "ship_can_prov"; //set flag to let php know where billing state field is comming from if (!document.forms[formid].ship_can_prov.selectedIndex > 0){ err_read += "You must indicate the shipping Province.\n"; error_fields[error_fields.length] = "ship_can_prov"; } } if (document.forms[formid].scountry[n].value != "Canada" && document.forms[formid].scountry[n].value != "United States" ){ shipstatefrom = "ship_intl_state"; //set flag to let php know where billing state field is comming from if (document.forms[formid].ship_intl_state.value == "") { err_read += "You must provide the shipping Province/Region/State information\n"; error_fields[error_fields.length] = "ship_intl_state"; } } if (document.forms[formid].szipcode.value == "") { err_read += "You must provide the shipping postal code.\n"; error_fields[error_fields.length] = "szipcode"; } if (document.forms[formid].sphone.value == "") { err_read += "You must provide the shipping phone.\n"; error_fields[error_fields.length] = "sphone"; } if (err_read == "") { document.forms[formid].state.value = statefrom; document.forms[formid].shipstate.value = shipstatefrom; document.forms[formid].submit(); } else { err_read = "We found the following omissions in your form: \n" + err_read; var thefield = error_fields[0]; alert(err_read); document.forms[formid][thefield].focus(); } } // end check user form function sameinfo(formid) { // alert(document.forms[formid].bcountry.options.selectedIndex); document.forms[formid].sfirstname.value = document.forms[formid].bfirstname.value; document.forms[formid].slastname.value = document.forms[formid].blastname.value; var sx = document.forms[formid].bcountry.options.selectedIndex; document.forms[formid].scountry.options[sx].selected = true; var xx = document.forms[formid].us_state.options.selectedIndex; document.forms[formid].ship_us_state.options[xx].selected = true; var cx = document.forms[formid].can_prov.options.selectedIndex; document.forms[formid].ship_can_prov.options[cx].selected = true; document.forms[formid].ship_intl_state.value = document.forms[formid].intl_state.value; document.forms[formid].szipcode.value = document.forms[formid].bzipcode.value; document.forms[formid].saddress1.value = document.forms[formid].baddress1.value; document.forms[formid].saddress2.value = document.forms[formid].baddress2.value; document.forms[formid].scity.value = document.forms[formid].bcity.value; document.forms[formid].sphone.value = document.forms[formid].bphone.value; document.forms[formid].sphone_countrycode.value = document.forms[formid].bphone_countrycode.value; setShipStateFields("billinginfo",document.forms[formid].bcountry.options[sx].value); } // end set shipping info var req2; //variable used to establish an XML Http Request object //this javascript function establishes a socket connection in which //php script communication takes place - it passes user input and //communicates back XML document results built by the php script function loadXMLDoc2(url) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req2 = new XMLHttpRequest(); req2.onreadystatechange = processReqChange2; req2.open("GET", url, true); req2.send(null); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { req2 = new ActiveXObject("Microsoft.XMLHTTP"); if (req2) { req2.onreadystatechange = processReqChange2; req2.open("GET", url, true); req2.send(); } } } //this JavaScript function processes the response from the php //script - basically it parses the XML response into useable strings function processReqChange2() { // only if req2 shows "complete" if (req2.readyState == 4) { //redyState of 4 siginifies a completed script if (req2.status == 200) { //status of 200 means that we have no errors in communication //we are assigning our xml document to an object so that //we can parse the individual tags into useable variables response = req2.responseXML.documentElement; // alert(response); method = response.getElementsByTagName('method')[0].firstChild.data; //this is the name of the original calling function result = response.getElementsByTagName('result')[0].firstChild.data; //this is the name of the country code formid = response.getElementsByTagName('formid')[0].firstChild.data; //this is the name of the country code // alert(result); //now that we have parsed the data we must pass it back to our original calling function by using the eval method. eval(method + '(\'\', result, formid)'); }else{ //if status not 200 then we need to alert the error alert("There was a problem retrieving the XML data:\n" + req2.statusText); } } //end our "only process when finished" check } //end processing function function getCountryCode(input, response, formid) { if (response != ''){ if(response != 0) { //we found a match in our database document.forms[formid].bphone_countrycode.value = "+" + response; } }else{ //initial function call url = '_actions/getcountrycode.php?var=' + input +'&f='+formid; // alert(url); loadXMLDoc2(url); } } function toggleDiv(divid) { // alert(divid); // return; var thisdiv = document.getElementById(divid); if(thisdiv.style.display == "none") { thisdiv.style.display = ""; sameinfo("billinginfo"); } else { thisdiv.style.display = "none"; sameinfo("billinginfo"); } }