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('newQuantityInput_' + i).value; if(quantity === '' || isNaN(quantity) || quantity < 1) { document.getElementById('newQuantityInput_' + i).value = prevQuantity; document.getElementById('newQuantityInput_' +i).focus(); ALERT_GREY_OUT('Please input QUANTITY: 1 - 999.'); } else { var unitPriceElem = document.getElementById('unitPriceSpan_' + i); var unitPrice = parseFloat(GET_ELEM_TEXT(unitPriceElem)); if(document.getElementById('unitPriceIncSpan_' + i)) { var unitPriceIncElem = document.getElementById('unitPriceIncSpan_' + i); 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('itemTotalSpan_' + i); REPLACE_ELEM_TEXT(itemTotalElem, itemTotal); get_url += '&quantity=' + quantity + '&time-stamp=' + new Date().getTime(); AJAX_GET_URL(get_url, update_url, null); } } function post_billing_info_form(post_url, update_url, invoiceNumber, amountToPay) { document.getElementById('buyNow').disabled = 1; var month = document.getElementById('creditCardExpMonthInput').value; if(month.length === 1) month = '0' + month; var year = document.getElementById('creditCardExpYearInput').value; if(year.length === 1) year = '0' + year; var expDateInput = month + '/' + year; var paramsJavascript = "'amountToPay=' + " + amountToPay + " + '&creditCardNumberInput=' + encodeURIComponent(document.getElementById('creditCardNumberInput').value)" + " + '&expDateInput=' + '" + expDateInput + "'" + " + '&billingFirstNameInput=' + encodeURIComponent(document.getElementById('billingFirstNameInput').value)" + " + '&billingLastNameInput=' + encodeURIComponent(document.getElementById('billingLastNameInput').value)" + " + '&billingZipCodeInput=' + encodeURIComponent(document.getElementById('billingZipCodeInput').value)" + " + '&invoiceNumber=' + " + invoiceNumber + ';'; AJAX_POST_URL(post_url, paramsJavascript, update_url, null); } function post_contact_info_form(post_url, update_url) { var customerIsTextOkElem = document.getElementById('customerIsTextOkInput'); if(customerIsTextOkElem !== null && customerIsTextOkElem.checked) var customerIsTextOk = 1; else var customerIsTextOk = 0; 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)" + " + '&customerIsTextOkInput=' + '" + customerIsTextOk + "'" + " + '&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 post_deposit_change(post_url, update_url) { var isDepositOnly = 0; if(document.getElementById('isDepositOnly').checked) isDepositOnly = 1; var paramsJavascript = "'isDepositOnly=' + " + isDepositOnly + ';'; 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_credit_card_number(input) { if(isNaN(input)) input = input.replace(/\D/g, ''); if(input === '') return false; var sum = 0; var odd = input.length % 2; for(var i = 0; i < input.length; i++) { digit = parseInt(input.charAt(i)); sum += odd ? digit : ((digit * 2 > 9) ? digit * 2 - 9 : digit * 2); odd = !odd; } return (sum % 10 === 0) ? true : false; } 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_billing_info_form() { var creditCardElem = document.getElementById('creditCardNumberInput'); var isValidCreditCardNumber = screen_credit_card_number(creditCardElem.value); if(isValidCreditCardNumber === false) { creditCardElem.focus(); ALERT_GREY_OUT('Please ENTER A VALID CREDIT CARD NUMBER'); return false; } var expMonthElem = document.getElementById('creditCardExpMonthInput'); if(expMonthElem.value === '' || (isNaN(expMonthElem.value) || expMonthElem.value > 12 || expMonthElem.value < 1)) { expMonthElem.focus(); expMonthElem.value = ''; ALERT_GREY_OUT('Please ENTER CREDIT CARD EXP. MONTH'); return false; } var expYearElem = document.getElementById('creditCardExpYearInput'); if(expYearElem.value === '' || isNaN(expYearElem.value)) { expYearElem.focus(); expYearElem.value = ''; ALERT_GREY_OUT('Please ENTER CREDIT CARD EXP. YEAR'); return false; } var currTime = new Date(); var currMonth = currTime.getMonth() + 1; var currYear = currTime.getFullYear().toString().slice(2); if((expYearElem.value < currYear) || (expYearElem.value === currYear && expMonthElem.value < currMonth)) { expMonthElem.focus(); ALERT_GREY_OUT('Please ENTER A VALID CREDIT CARD EXP. DATE'); return false; } var firstNameElem = document.getElementById('billingFirstNameInput'); 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('billingLastNameInput'); lastNameElem.value = SCREEN_NAME(lastNameElem.value); if(lastNameElem.value === '') { lastNameElem.focus(); lastNameElem.value = ''; ALERT_GREY_OUT('Please ENTER LAST NAME'); return false; } var zipCode = document.getElementById('billingZipCodeInput').value; if(zipCode.match(/^[0-9]{9}$/)) { zipCode = zipCode.substring(0, 5) + '-' + zipCode.substring(5, 9); document.getElementById('billingZipCodeInput').value = zipCode; } if(zipCode.match(/^[0-9]{5}$/) === null && zipCode.match(/^[0-9]{5}\-[0-9]{4}$/) === null) { document.getElementById('billingZipCodeInput').focus(); document.getElementById('billingZipCodeInput').value = ''; ALERT_GREY_OUT('Please ENTER BILLING ZIP CODE'); return false; } 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 addrLine1 = screen_address(addr1Elem.value); if(addrLine1 === '') { 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 post_form_shop(post_url, update_url, i, name_id) { var cg_options = ''; var genderInputMaleElem = document.getElementById('genderMaleInput_' + i); if(genderInputMaleElem) { if(genderInputMaleElem.checked) var genderInput = 'Male'; else var genderInput = 'Female'; var heightFeet = document.getElementById('heightFeetInput_' + i).value; var heightInches = document.getElementById('heightInchesInput_' + i).value; var weight = document.getElementById('weightInput_' + i).value; cg_options = genderInput + ': ' + heightFeet + '&#039; ' + heightInches + '&quot;, ' + weight + ' lbs'; } var textInputOptions = ''; for(var j = 1; j < 4; j++) { var textInputElem = document.getElementById('textInput_' + i + '_' + j); if(textInputElem) { var textInputLabelElem = document.getElementById('textInputLabel_' + i + '_' + j); var textInputLabelStr = textInputLabelElem.innerText || textInputLabelElem.textContent; if(textInputOptions !== '') { textInputOptions += ' ; ' ; } textInputOptions += textInputLabelStr + ' ' + quote_encode(textInputElem.value); } else { break; } } var selectInputOptions = ''; for(j = 1; j < 10; j++) { var selectInputElem = document.getElementById('selectInput_' + i + '_' + j); if(selectInputElem) { if(selectInputOptions !== '') { selectInputOptions += ' ; ' ; } selectInputOptions += selectInputElem.options[selectInputElem.selectedIndex].text; } else { break; } } textInputOptions = quote_encode(textInputOptions); selectInputOptions = quote_encode(selectInputOptions); var paramsJavascript = "'name_id=' + PHP_RAWURLENCODE('" + name_id + "')" + " + '&cg_options=' + PHP_RAWURLENCODE('" + cg_options + "')" + " + '&textInputOptions=' + PHP_RAWURLENCODE('" + textInputOptions + "')" + " + '&selectInputOptions=' + PHP_RAWURLENCODE('" + selectInputOptions + "')" + " + '&quantity=' + document.getElementById('quantityInput_" + i + "').value;"; AJAX_POST_URL(post_url, paramsJavascript, update_url, null); } function update_grad_item_price(itemCount, standardPrice) { var priceElem = document.getElementById('itemPrice_' + itemCount); var priceStr = priceElem.innerText || priceElem.textContent; var price = parseFloat(priceStr); var priceChange; var priceChangeTotal = 0.0; for(var i = 1; i < 16; i++) { var selectInputElem = document.getElementById('selectInput_' + itemCount + '_' + 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) { var genderMaleInputElem = document.getElementById('genderMaleInput_' + i); if(genderMaleInputElem) { var genderFemaleInputElem = document.getElementById('genderFemaleInput_' + i); if(!genderMaleInputElem.checked && !genderFemaleInputElem.checked) { genderMaleInputElem.focus(); ALERT_GREY_OUT('Please select GENDER'); return false; } var heightFeetInputElem = document.getElementById('heightFeetInput_' + i); var heightInchesInputElem = document.getElementById('heightInchesInput_' + i); if(heightFeetInputElem.selectedIndex === 0 || heightInchesInputElem.selectedIndex === 0) { heightFeetInputElem.focus(); ALERT_GREY_OUT('Please select HEIGHT: feet and inches'); return false; } var weightInputElem = document.getElementById('weightInput_' + i); if(weightInputElem.value === '' || isNaN(weightInputElem.value) || weightInputElem.value < 50) { weightInputElem.value = ''; weightInputElem.focus(); ALERT_GREY_OUT('Please input WEIGHT: 49 - 999'); return false; } } for(var j = 1; j < 4; j++) { var textInputElem = document.getElementById('textInput_' + i + '_' + j); if(textInputElem) { textInputElem.value = SCREEN_NAME(textInputElem.value); if(textInputElem.value === '') { textInputElem.focus(); textInputElem.value = ''; var textInputLabelElem = document.getElementById('textInputLabel_' + i + '_' + j); var textInputLabelStr = textInputLabelElem.innerText || textInputLabelElem.textContent; textInputLabelStr = textInputLabelStr.substring(0, textInputLabelStr.length - 1).toUpperCase(); var msg = 'Please ENTER ' + textInputLabelStr; ALERT_GREY_OUT(msg); return false; } } else { break; } } for(j = 1; j < 16; j++) { var selectInputElem = document.getElementById('selectInput_' + i + '_' + j); if(selectInputElem) { if(selectInputElem.selectedIndex === 0) { selectInputElem.focus(); var msg = 'Please ' + selectInputElem.options[0].text.toUpperCase(); ALERT_GREY_OUT(msg); return false; } } else { break; } } var quantityElem = document.getElementById('quantityInput_' + i); 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, updatePage) { var schoolNameInputElem = document.getElementById('schoolNameInput'); var schoolNameValue = schoolNameInputElem.options[schoolNameInputElem.selectedIndex].value; var isChangeSchool = 1; if(schoolNameValue === '------------------------------------') { schoolNameInputElem.selectedIndex = 0; isChangeSchool = 0; } if(isChangeSchool) { var get_url = 'http://' + host + '/process/select-school.php?school-name=' + PHP_RAWURLENCODE(schoolNameValue); if(updatePage === '') var update_url = 'http://' + host + '/shop.html'; else var update_url = 'http://' + host + '/' + updatePage; AJAX_GET_URL(get_url, update_url, null); } } 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'; } } window.onload = function() { var links = document.getElementsByTagName('a'); for(var i =0 ; i < links.length; i++) { if(links[i].className.match('newWindow')) { links[i].onclick = function() { window.open(this.href); return false; }; } } }; 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); } } function PHP_RAWURLENCODE(input) { input = (input + '').toString(); return encodeURIComponent(input).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A') }
