var http_request = http_set_request(); var isDebug = 0; function AJAX_GET_URL(get_url, update_url, response_url) { get_url = url_add_timestamp(get_url); update_url = url_add_timestamp(update_url); if(isDebug) { alert('get_url: ' + get_url); alert('update_url: ' + update_url); alert('response_url: ' + response_url); } http_request.open('get', get_url, true); http_request.onreadystatechange = function() { update_page(update_url, response_url); }; http_request.send(null); } function AJAX_POST_URL(post_url, paramsJavascript, update_url, response_url) { var params = eval(paramsJavascript); post_url = url_add_timestamp(post_url); update_url = url_add_timestamp(update_url); if(isDebug) { alert('post_url: ' + post_url); alert('update_url: ' + update_url); alert('response_url: ' + response_url); alert('params: ' + params); } http_request.open('post', post_url, true); http_request.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); http_request.setRequestHeader('content-length', params.length); http_request.setRequestHeader('connection', 'close'); http_request.onreadystatechange = function() { update_page(update_url, response_url); }; http_request.send(params); } function http_set_request() { try { http_request = new XMLHttpRequest(); } catch(trymicrosoft) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch(othermicrosoft) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { http_request = null; } } } return http_request; } function update_page(update_url, response_url) { if(http_request.readyState == 4) { if(http_request.status == 200) { if(isDebug) { alert('http_request.responseText: ' + http_request.responseText); } if(http_request.responseText) { window.location = response_url; } else { window.location = update_url; } } else { alert('Error! REQUEST status is [' + http_request.status + '].'); } } } function url_add_timestamp(url) { if(url.match(/#.*$/)) { var url_1 = url.match(/^.*#/).toString(); url_1 = url_1.substring(0, url_1.length - 1); var url_2 = url.match(/#.*$/).toString(); if(url_1.match(/.*\?.*/)) url_1 += '&timestamp=' + new Date().getTime(); else url_1 += '?timestamp=' + new Date().getTime(); url = url_1 + url_2; } else { if(url.match(/.*\?.*/)) url += '&timestamp=' + new Date().getTime(); else url += '?timestamp=' + new Date().getTime(); } return url; } function ajax_update_cart_item(get_URL, update_URL, i, prevQuantity) { var quantity = document.getElementById(i + '_newQuantityInput').value; if(quantity == '' || isNaN(quantity) || quantity < 1) { document.getElementById(i + '_newQuantityInput').value = prevQuantity; document.getElementById(i + '_newQuantityInput').focus(); ALERT_GREY_OUT('Please input QUANTITY: 1 - 999.'); } else { var unitPriceElem = document.getElementById(i + '_unitPriceSpan'); var unitPrice = parseFloat(GET_ELEM_TEXT(unitPriceElem)); if(document.getElementById(i + '_unitPriceIncSpan')) { var unitPriceIncElem = document.getElementById(i + '_unitPriceIncSpan'); var unitPriceInc = parseFloat(GET_ELEM_TEXT(unitPriceIncElem)); } else { var unitPriceInc = unitPrice; } var itemTotal = unitPrice + ((quantity - 1) * unitPriceInc); itemTotal = PHP_NUMBER_FORMAT(itemTotal, 2, '.', ','); var itemTotalElem = document.getElementById(i + '_itemTotalSpan'); REPLACE_ELEM_TEXT(itemTotalElem, itemTotal); get_URL += '&quantity=' + quantity + '&time-stamp=' + new Date().getTime(); AJAX_GET_URL(get_URL, update_URL, null); } } function post_contact_info_form(post_URL, update_URL) { var paramsJavascript = "'customerFirstNameInput=' + encodeURIComponent(document.getElementById('customerFirstNameInput').value)" + " + '&customerLastNameInput=' + encodeURIComponent(document.getElementById('customerLastNameInput').value)" + " + '&customerEmailInput=' + encodeURIComponent(document.getElementById('customerEmailInput').value)" + " + '&customerPhone1Input=' + encodeURIComponent(document.getElementById('customerPhone1Input').value)" + " + '&customerPhone2Input=' + encodeURIComponent(document.getElementById('customerPhone2Input').value)" + " + '&customerAddr1Input=' + encodeURIComponent(document.getElementById('customerAddr1Input').value)" + " + '&customerAddr2Input=' + encodeURIComponent(document.getElementById('customerAddr2Input').value)" + " + '&customerCityInput=' + encodeURIComponent(document.getElementById('customerCityInput').value)" + " + '&customerStateInput=' + encodeURIComponent(document.getElementById('customerStateInput').value)" + " + '&customerZipCodeInput=' + encodeURIComponent(document.getElementById('customerZipCodeInput').value);"; AJAX_POST_URL(post_URL, paramsJavascript, update_URL, null); } function screen_address(input) { input = input.replace(/^\s+|\s+$/g, ''); input = input.replace(/ +/, ' '); if(input.match(/^[a-zA-Z0-9]+([a-zA-Z0-9 '\-\.,#]|( & ))*$/)) return input; else return ''; } function screen_email(input) { input = input.replace(/^\s+|\s+$/g, ''); input = input.toLowerCase(); if(input.match(/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/)) return input; else return ''; } function validate_paypal_form(total, merchantPhone) { if(total > 500) { if(merchantPhone == '-1') { var msg = "Your order is over $500!\n\nPlease place your order over the phone.\n\nThanks"; } else { var msg = "Your order is over $500!\n\nPlease place your order over the phone.\nYou can call us at " + merchantPhone + ".\n\nThanks"; } ALERT_GREY_OUT(msg); return false; } else { return true; } } function validate_contact_info_form() { var firstNameElem = document.getElementById('customerFirstNameInput'); firstNameElem.value = SCREEN_NAME(firstNameElem.value); if(firstNameElem.value == '') { firstNameElem.focus(); firstNameElem.value = ''; ALERT_GREY_OUT('Please ENTER FIRST NAME.'); return false; } var lastNameElem = document.getElementById('customerLastNameInput'); lastNameElem.value = SCREEN_NAME(lastNameElem.value); if(lastNameElem.value == '') { lastNameElem.focus(); lastNameElem.value = ''; ALERT_GREY_OUT('Please ENTER LAST NAME.'); return false; } var emailElem = document.getElementById('customerEmailInput'); var email = screen_email(emailElem.value); if(email == '') { document.getElementById('customerEmailInput').focus(); document.getElementById('customerEmailInput').value = ''; ALERT_GREY_OUT('Please ENTER EMAIL.'); return false; } var phone1Elem = document.getElementById('customerPhone1Input'); if(phone1Elem.value.length != 3 || (isNaN(phone1Elem.value))) { phone1Elem.focus(); phone1Elem.value = ''; ALERT_GREY_OUT('Please ENTER AREA CODE.'); return false; } var phone2Elem = document.getElementById('customerPhone2Input'); phone2Elem.value = phone2Elem.value.replace(/-/, ''); if(phone2Elem.value.length != 7 || (isNaN(phone2Elem.value))) { phone2Elem.focus(); phone2Elem.value = ''; ALERT_GREY_OUT('Please ENTER PHONE.'); return false; } addr1Elem = document.getElementById('customerAddr1Input'); var addressLine1 = screen_address(addr1Elem.value); if(addressLine1 == '') { addr1Elem.focus(); addr1Elem.value = ''; ALERT_GREY_OUT('Please ENTER ADDRESS LINE 1.'); return false; } var city = document.getElementById('customerCityInput').value; if(city == '') { document.getElementById('customerCityInput').focus(); document.getElementById('customerCityInput').value = ''; ALERT_GREY_OUT('Please ENTER CITY.'); return false; } if(document.getElementById('customerStateInput').selectedIndex == 0) { document.getElementById('customerStateInput').focus(); ALERT_GREY_OUT('Please SELECT STATE.'); return false; } var zipCode = document.getElementById('customerZipCodeInput').value; if(zipCode.match(/^[0-9]{9}$/)) { zipCode = zipCode.substring(0, 5) + '-' + zipCode.substring(5, 9); document.getElementById('customerZipCodeInput').value = zipCode; } if(zipCode.match(/^[0-9]{5}$/) == null && zipCode.match(/^[0-9]{5}\-[0-9]{4}$/) == null) { document.getElementById('customerZipCodeInput').focus(); document.getElementById('customerZipCodeInput').value = ''; ALERT_GREY_OUT('Please ENTER ZIP CODE.'); return false; } return true; } function quote_encode(input) { input = input.replace(/(')/g, '&#039;'); input = input.replace(/(\")/g, '&quot;'); return input; } function quote_decode(input) { input = input.replace(/__#039__/g, '&#039;'); input = input.replace(/__QUOT__/g, '&quot;'); return input; } function post_form_shop(post_url, update_url, i, itemType, name_id_qe, textInputLabel1, textInputLabel2, textInputLabel3) { var cg_options = ''; var genderInputMaleElem = document.getElementById(i + '_genderMaleInput'); if(genderInputMaleElem) { if(genderInputMaleElem.checked) var genderInput = 'Male'; else var genderInput = 'Female'; var heightFeet = document.getElementById(i + '_heightFeetInput').value; var heightInches = document.getElementById(i + '_heightInchesInput').value; var weight = document.getElementById(i + '_weightInput').value; cg_options = genderInput + ': ' + heightFeet + '&#039; ' + heightInches + '&quot;, ' + weight + ' lbs'; } var textInputOptions = ''; for(j = 1; j < 3; j++) { var textInputElem = document.getElementById(i + '_textInput' + j); if(textInputElem) { var textInputLabel = 'textInputLabel' + j; textInputLabel = eval(textInputLabel); if(textInputOptions != '') { textInputOptions += ' ; ' ; } textInputOptions += textInputLabel + ' ' + quote_encode(textInputElem.value); } else { break; } } var selectInputOptions = ''; for(j = 1; j < 10; j++) { var selectInputElem = document.getElementById(i + '_selectInput' + j); if(selectInputElem) { if(selectInputOptions != '') { selectInputOptions += ' ; ' ; } selectInputOptions += selectInputElem.options[selectInputElem.selectedIndex].text; } else { break; } } textInputOptions = quote_encode(textInputOptions); selectInputOptions = quote_encode(selectInputOptions); var paramsJavascript = "'itemType=' + encodeURIComponent('" + itemType + "')" + "+ '&name_id=' + encodeURIComponent('" + name_id_qe + "')" + " + '&cg_options=' + encodeURIComponent('" + cg_options + "')" + " + '&textInputOptions=' + encodeURIComponent('" + textInputOptions + "')" + " + '&selectInputOptions=' + encodeURIComponent('" + selectInputOptions + "')" + " + '&quantity=' + encodeURIComponent(document.getElementById('" + i + "_quantityInput').value)"; AJAX_POST_URL(post_url, paramsJavascript, update_url, null); } function update_grad_item_price(itemCount, standardPrice) { var priceElem = document.getElementById(itemCount + '_itemPrice'); var price = parseFloat(priceElem.innerHTML); var priceChange; var priceChangeTotal = 0.0; for(i = 1; i < 10; i++) { var selectInputElem = document.getElementById(itemCount + '_selectInput' + i); if(selectInputElem) { priceChange = parseFloat(selectInputElem.options[selectInputElem.selectedIndex].value); if(isNaN(priceChange)) { priceChange = 0.0; } priceChangeTotal += priceChange; } else { break; } } var newPrice = parseFloat(standardPrice) + priceChangeTotal; newPrice = PHP_NUMBER_FORMAT(newPrice, 2, '.', ','); REPLACE_ELEM_TEXT(priceElem, newPrice); } function validate_form_shop(i, textInputLabel1, textInputLabel2, textInputLabel3) { var genderMaleInputElem = document.getElementById(i + '_genderMaleInput'); if(genderMaleInputElem) { var genderFemaleInputElem = document.getElementById(i + '_genderFemaleInput'); if(!genderMaleInputElem.checked && !genderFemaleInputElem.checked) { genderMaleInputElem.focus(); ALERT_GREY_OUT('Please select GENDER: Male or Female.'); return false; } var heightFeetInputElem = document.getElementById(i + '_heightFeetInput'); var heightInchesInputElem = document.getElementById(i + '_heightInchesInput'); if(heightFeetInputElem.selectedIndex == 0 || heightInchesInputElem.selectedIndex == 0) { heightFeetInputElem.focus(); ALERT_GREY_OUT('Please select HEIGHT: feet and inches.'); return false; } var weightInputElem = document.getElementById(i + '_weightInput'); if(weightInputElem.value == '' || isNaN(weightInputElem.value) || weightInputElem.value < 50) { weightInputElem.value = ''; weightInputElem.focus(); ALERT_GREY_OUT('Please input WEIGHT: 49 - 999.'); return false; } } for(j = 1; j < 4; j++) { var textInputElem = document.getElementById(i + '_textInput' + j); if(textInputElem) { textInputElem.value = SCREEN_NAME(textInputElem.value); if(textInputElem.value == '') { textInputElem.focus(); textInputElem.value = ''; var textInputLabel = 'textInputLabel' + j; textInputLabel = eval(textInputLabel); var msg = 'Please ENTER ' + textInputLabel.substring(0, textInputLabel.length - 1).toUpperCase(); if(msg.charAt(msg.length - 1) != '.') msg += '.'; ALERT_GREY_OUT(msg); return false; } } else { break; } } for(j = 1; j < 10; j++) { var selectInputElem = document.getElementById(i + '_selectInput' + j); if(selectInputElem) { if(selectInputElem.selectedIndex == 0) { selectInputElem.focus(); var msg = 'Please ' + selectInputElem.options[0].text.toUpperCase(); if(msg.charAt(msg.length - 1) != '.') msg += '.'; ALERT_GREY_OUT(msg); return false; } } else { break; } } var quantityElem = document.getElementById(i + '_quantityInput'); if(quantityElem.value == '' || isNaN(quantityElem.value) || quantityElem.value < 1) { quantityElem.value = 1; quantityElem.focus(); ALERT_GREY_OUT('Please input QUANTITY: 1 - 999.'); return false; } return true; } function filter_school(host) { var schoolNameValue = document.getElementById('schoolNameInput').options[document.getElementById('schoolNameInput').selectedIndex].value; var schoolNameInputElem = document.getElementById('schoolNameInput'); var isChangeSchool = 1; if(schoolNameValue == '------------------------------------') { schoolNameInputElem.selectedIndex = 0; isChangeSchool = 0; } if(isChangeSchool) { var get_URL = 'http://' + host + '/process/select-school.php?school-name=' + encodeURIComponent(quote_encode(schoolNameValue)); var update_URL = 'http://' + host + '/shop.html'; var response_URL = null; AJAX_GET_URL(get_URL, update_URL, response_URL); } } function quote_encode(input) { input = input.replace(/'/g, '__#039__'); input = input.replace(/"/g, '__QUOT__'); return input; } function ALERT_GREY_OUT(message) { GREY_OUT(true, {'zindex':'50', 'bgcolor':'#333333', 'opacity':'70'}); alert(message); GREY_OUT(false); } function CLEAR_ELEM_TEXT(elem) { if(elem != null) { if(elem.childNodes) { for(var i = 0; i < elem.childNodes.length; i++) { var childNode = elem.childNodes[i]; elem.removeChild(childNode); } } } } function GET_ELEM_TEXT(elem) { var text = ''; if(elem != null) { if(elem.childNodes) { for(var i = 0; i < elem.childNodes.length; i++) { var childNode = elem.childNodes[i]; if(childNode.nodeValue != null) { text = text + childNode.nodeValue; } } } } return text; } function REPLACE_ELEM_TEXT(elem, text) { if(elem != null) { CLEAR_ELEM_TEXT(elem); var newNode = document.createTextNode(text); elem.appendChild(newNode); } } function SCREEN_NAME(input) { input = input.replace(/^\s+|\s+$/g, ''); input = input.replace(/ +/, ' '); if(input.match(/^[a-zA-Z]+([a-zA-Z '\-\.,]|( & ))*$/)) return input; else return ''; } function GREY_OUT(vis, options) { var options = options || {}; var zindex = options.zindex || 50; var opacity = options.opacity || 70; var opaque = (opacity / 100); var bgcolor = options.bgcolor || '#000000'; var dark=document.getElementById('darkenScreenObject'); if(!dark) { var tbody = document.getElementsByTagName('body')[0]; var tnode = document.createElement('div'); tnode.style.position='absolute'; tnode.style.top='0px'; tnode.style.left='0px'; tnode.style.overflow='hidden'; tnode.style.display='none'; tnode.id='darkenScreenObject'; tbody.appendChild(tnode); dark=document.getElementById('darkenScreenObject'); } if(vis) { if( document.body && ( document.body.scrollWidth || document.body.scrollHeight )) { var pageWidth = document.body.scrollWidth+'px'; var pageHeight = document.body.scrollHeight+'px'; } else if(document.body.offsetWidth) { var pageWidth = document.body.offsetWidth+'px'; var pageHeight = document.body.offsetHeight+'px'; } else { var pageWidth='100%'; var pageHeight='100%'; } dark.style.opacity=opaque; dark.style.MozOpacity=opaque; dark.style.filter='alpha(opacity='+opacity+')'; dark.style.zIndex=zindex; dark.style.backgroundColor=bgcolor; dark.style.width= pageWidth; dark.style.height= pageHeight; dark.style.display='block'; } else { dark.style.display='none'; } } function PHP_NUMBER_FORMAT(n, c, d, t) { if(n > 999) { c = (c >= 0) ? c : 2; d = d || '.'; t = t || ','; nInteger = Math.floor(n); nDecimal = (n - nInteger).toFixed(c); var rev_nInteger = nInteger.toString().split('').reverse(); var new_nInteger = new Array(); var new_nDecimal = nDecimal.toString().substr(1); for(var i = rev_nInteger.length; i > 0; i--) { if(i % 3) { new_nInteger.push(rev_nInteger.pop()); } else { new_nInteger.push(t); new_nInteger.push(rev_nInteger.pop()); } } newValue = new_nInteger.join('') + new_nDecimal; return newValue; } else { return n.toFixed(c); } }