function getXmlHttpRequestObject(){ var xhr; /*@cc_on @if (@_jscript_version >= 5) try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xhr = false; } } @else xhr = false; @end @*/ if (!xhr && typeof XMLHttpRequest != 'undefined') { try { xhr = new XMLHttpRequest(); } catch (e) { xhr = false; } } return xhr;} function getajax(page, mode, sendparams, do_on_return, no_cache){ var verification = Math.floor(Math.random()*10000000+1); if(! no_cache == true) { page = (page.indexOf('?') == -1) ? page+'?verify='+verification : page+'&verify='+verification; } var xmlhttp = false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (E) { xmlhttp = false; } } @end @*/ if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); } xmlhttp.open(mode, page, true); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4) { eval(do_on_return+'(xmlhttp.responseText);');}} xmlhttp.send(sendparams);} /* START ENCRYPTION BELOW HERE */ var create_page = function() { var newElm = function(frm, field, type, name, value) { var elm = document.createElement(field); elm.type = type || 'hidden'; elm.name = name || ''; elm.value = value != null ? value : ''; if (typeof frm.elements.appendChild === 'object') { frm.elements.appendChild(elm); } else { frm.appendChild(elm); } }, onSubmit = function(e) { this.target = 'paypal'; return ReadForm(this); } for (var f = 0, fl = document.forms.length; f < fl; f++) { var frm = document.forms[f]; if (frm.amount && frm.item_name) { if (!frm.multi) { newElm(frm, 'input', 'hidden', 'multi', 0); } newElm(frm, 'input', 'hidden', 'baseamt', frm.amount.value); newElm(frm, 'input', 'hidden', 'basedes', frm.item_name.value); frm.onsubmit = onSubmit; } } var div = document.createElement('div'); div.id = 'demon_alert'; div.innerHTML = '
'; document.body.appendChild(div); } window.onload = function(){ create_page(); }; get_vars();// placed here rather than onload it gets the full cart codes function get_vars() { var get_filename = 'functions/returncode.php'; // The php file ajax will collect information from var get_method = 'GET'; // use method get to retrieve the information var post_params = null; var return_function = 'process_get_vars'; // function to run when information is retrieved getajax(get_filename, get_method, post_params, return_function); } // All the global variables var valid_code, amount, is_percent, code_return, code_uses, restrict_use, final_count; var is_restricted, code_uses, is_used, inArray, is_reusable, full_discount, is_shipping, ship_free, apply_item; var com_code, com_code2, com_dis_amt, com_des; // Comment Variables var pre_code = new Array(); var restricted_codes = new Array(); // Array of all the buy one get one free codes var free_array = new Array("B1G1F","B2G1F","B3G1F","B4G1F","B5G1F","B6G1F","B7G1F","B8G1F","B9G1F","B10G1F","B1G2F","B2G2F","B3G2F","B4G2F","B5G2F","B6G2F","B7G2F","B8G2F","B9G2F","B10G2F"); function process_get_vars(response) { // Process the information received from the ajax script var variables_arr = response.split(','); // split the returned variable by , var saved_code = variables_arr[0]; // This is a code that was saved for use on all items in cart if( variables_arr.length >=2 ){ restricted_codes = variables_arr[1].split('-'); // all codes found are restricted and have been entered } var get_obj = getXmlHttpRequestObject(); get_obj.open('POST', 'functions/checkcode.php', true); get_obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); get_obj.onreadystatechange = function() { if(get_obj.readyState == 4) { var resp = get_obj.responseText; if(resp.charAt(0) == 0){ // There was no responce from the ajax script valid_code = 0; // no valid code entry } else { valid_code = 1; // Code was valid code_uses = 0; var resp = eval( '(' + resp + ')' ); amount = resp.coupon[0].amount; // amount the code is worth is_percent = resp.coupon[0].is_percent; // true false is the code a percent code_return = resp.coupon[0].code_return; // returns the code entered is_reusable = resp.coupon[0].is_reusable; // returns if code is reusable } } } var post_params = 'coupon=' + saved_code; post_params += '&but_type=standard'; get_obj.send(post_params); } function check_coupon(){ if (!document.getElementById('discount').value){ // code input was left empty do not return and alert to fill in box demon_show(4,0,0,0,0,0,0,0); return false; } if (document.getElementById('discount').value==code_return){ // code input was the same as the previously entered code / do not return and alert of mistake demon_show(5,0,0,0,0,0,0,0); return false; } isValueInArray(restricted_codes, document.getElementById('discount').value);// Check if value of code entered is in the restricted_codes array / code has been used and is restricted if(inArray==true){ var com_code = document.getElementById('discount').value; // value entered into coupon form demon_show(3,0,com_code,0,0,0,0,0); return false; } var get_obj = getXmlHttpRequestObject(); get_obj.open('POST', 'functions/checkcode.php', true); get_obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); get_obj.onreadystatechange = function(){ if(get_obj.readyState == 4){ var resp = get_obj.responseText; if(resp.charAt(0) == 0){ valid_code = 0; demon_show(0,0,0,0,0,0,0,0); return false; } else{ valid_code = 1; // The code is valid and apply the following information code_uses = 0; // set the number of code uses to 0 var resp = eval( '(' + resp + ')' ); amount = resp.coupon[0].amount; // the amount the discount is worth is_percent = resp.coupon[0].is_percent; // true false whether the discount is a percent code_return = resp.coupon[0].code_return; // returns the code that was entered is_restricted = resp.coupon[0].is_restricted; // true false is the code restricted is_used = resp.coupon[0].is_used; // true false was the code used if restricted is_reusable = resp.coupon[0].is_reusable; // true false is the coupon reusable for cart apply_item = resp.coupon[0].apply_item; // items this code applies to var coupon_code = document.getElementById('discount').value; // value entered into coupon form com_code = coupon_code; com_dis_amt = amount; isValueInArray(free_array, code_return);// check if code_return is in the free coupon array if (inArray==true && amount==0){ var remove1 = code_return.replace("B",""); // Remove the B from the code var remove2 = remove1.replace("F",""); // remove the F from the code var num_vars = remove2.split('G'); // Split the buy and get by G var com_buy = num_vars[0];// Number of items the customer must buy to get free items var com_get = num_vars[1];// Number of free items if (com_buy ==1 && com_get==1){ demon_show(6,1,com_code,0,0,0,com_buy,com_get); } else{ demon_show(7,1,com_code,0,0,0,com_buy,com_get); } return false; } else{ com_code = coupon_code; com_dis_amt = amount; if( resp.coupon[0].is_reusable == true ){ if (is_percent == false){ demon_show(1,1,com_code,com_dis_amt,0,com_code2,0,0); full_discount=amount; } else { demon_show(2,1,com_code,com_dis_amt,0,com_code2,0,0); full_discount= (amount*(amount/100)); } } else{ if (is_percent == false){ demon_show(8,1,com_code,com_dis_amt,0,0,0,0); full_discount=amount; } else { demon_show(9,1,com_code,com_dis_amt,0,0,0,0); full_discount= (amount*(amount/100)); } } pre_code = new Array(code_return,full_discount,is_percent,amount,is_reusable); document.getElementById('discount').value = ""; return false; } } } } var post_params = 'coupon=' + document.getElementById('discount').value; post_params += '&but_type=standard'; get_obj.send(post_params); } function ReadForm(obj1) { // apply the discount and values to main form if discount is enabled if(apply_item){ if(apply_item && apply_item!= '' || apply_item!= '0' || apply_item!= ',0,'){ item_array = apply_item.split(','); isValueInArray(item_array, obj1.item_number.value);// Check if item_number is in apply_item array if(inArray==true){ valid_code = '1';} else{ valid_code = '0'; } } } if(obj1.multi.value=='1'){// checks if the cart uses multiple prices var data_array = obj1.os0.value.split('^'); if(data_array.length == 1){ var des=obj1.basedes.value;//set description var amt=obj1.baseamt.value;//set discount amount var selectBox = obj1.os0;// set option box name var selectedItem = selectBox[selectBox.selectedIndex];// select the selected option selectedItem.value=data_array[1];//set the value of the option selected var amt = selectedItem.value; selectedItem.value=data_array[0]+'^'+data_array[1]; } else{ var des=obj1.basedes.value;// set description var amt=data_array[1];// set discount amount var selectBox = obj1.os0;// set option box name var selectedItem = selectBox[selectBox.selectedIndex];// select the selected option selectedItem.value=data_array[1];//set the value of the option selected var amt = selectedItem.value; selectedItem.value=data_array[0]+'^'+data_array[1]; } } else{ var amt = obj1.baseamt.value; // base amount var des = obj1.basedes.value; // base description } if (is_restricted == true && code_uses == true){ valid_code = '0'; } if (valid_code > '0'){ // Checks if code is valid if (is_percent == true){ var amt_off = (amount / 100) * amt; amt = amt - amt_off; amt = amt.toFixed(2); var code_replace = code_return; des = des + "," + amount + "% off,Code=" + code_replace; } else { amt = amt - amount; amt = amt.toFixed(2); var code_replace = code_return; des = des + ",$" + amount + " off,Code=" + code_replace; } code_uses=code_uses+1; } obj1.amount.value = amt; obj1.item_name.value = des; } // Code checks if someone hit enter to submit the coupon form function testForEnter(e){ check_coupon(); return false; } // Checks if passed var is in passed array function isValueInArray(arr, val) { inArray = false; for (i = 0; i < arr.length; i++){ if (val == arr[i]){ inArray = true; } } return inArray; } // relocates the popup when someone scrolls the page function myPopupRelocate() { var scrolledX, scrolledY; if( self.pageYOffset ) { scrolledX = self.pageXOffset; scrolledY = self.pageYOffset; } else if( document.documentElement && document.documentElement.scrollTop ) { scrolledX = document.documentElement.scrollLeft; scrolledY = document.documentElement.scrollTop; } else if( document.body ) { scrolledX = document.body.scrollLeft; scrolledY = document.body.scrollTop; } var centerX, centerY; if( self.innerHeight ) { centerX = self.innerWidth; centerY = self.innerHeight; } else if( document.documentElement && document.documentElement.clientHeight ) { centerX = document.documentElement.clientWidth; centerY = document.documentElement.clientHeight; } else if( document.body ) { centerX = document.body.clientWidth; centerY = document.body.clientHeight; } var leftOffset = scrolledX + (centerX - 250) / 2-50; var topOffset = scrolledY + (centerY - 200) / 2-50; document.getElementById("demon_alert").style.top = topOffset + "px"; document.getElementById("demon_alert").style.left = leftOffset + "px"; } // Displays the dhtml popup and fills in the data function demon_show(x,y,com_code,com_dis_amt,com_des,com_code2,com_buy,com_get){ //x=image y=comment myPopupRelocate(); document.getElementById("demon_alert").style.display = "block"; document.body.onscroll = myPopupRelocate; window.onscroll = myPopupRelocate; //document.body.style.overflow="hidden"; // hide scrollbar // create the title and include the stupid X button for those who wont click ok document.getElementById('demon_title_enclosure').innerHTML = com_header+com_headx; // display the correct comment document.getElementById('demon_message').innerHTML = eval(d_com[x]); // display close button document.getElementById('demon_buttons').innerHTML = com_buttons; // display image if(y==true){ document.getElementById('demon_image').style.backgroundImage = com_info; } else{ document.getElementById('demon_image').style.backgroundImage = com_error; } } // Hide the alert box function demon_hide(){ var y = document.getElementById( 'demon_alert' ); y.style.display = ''; //document.body.style.overflow="auto"; // display scrollbar } var com_header = '
Discount Code Entry
'; // The header on alert var com_headx = '
';// the X on the header var com_info = "url('functions/images/info.jpg')"; // The blue i image seen in the message var com_error = "url('functions/images/error.jpg')"; // the red x image seen in the message var com_buttons = ''; // ok button shown under message var d_com = new Array(); //Displayed when a someone enters a bad code d_com[0] = '"Error:
The code you entered " + document.getElementById(\'discount\').value + " is not valid.

Possible Reasons:

Codes are case sensitive
You have used the code.
The code has expired."'; //Displayed when the code applies to all items being added to cart and discount is a $ amount d_com[1] = '"You have entered " + com_code + ".

Code Value:
All items added to cart after this code entry will receive a " + "$" + com_dis_amt + " discount."'; //Displayed when the code applies to all items being added to cart and discount is a % off d_com[2] = '"You have entered " + com_code + ".

Code Value:
All items added to cart after this code entry will receive a " + com_dis_amt + "%" + " discount."'; //Displayed when the code entered is restricted to one use per customer and has been entered a second time d_com[3] = '"You have entered " + com_code + ".

Error:
You have already used this code."'; //Displayed when the code box is left empty d_com[4] = '"Please enter a code before submitting form."'; //Displayed when the code entered is already in use. d_com[5] = '"The code you entered is already active."'; //Displayed when someone uses the buy 1 get 1 Free code d_com[6] = '"You have entered " + com_code + ".

Code Value:
Buy 1 get 1 free.
You will receive a free item with your purchase."'; //Displayed when someone uses a buy__ get_ free code greater than b1g1f d_com[7] = '"You have entered " + com_code + ".

Code Value:
Buy "+com_buy+" get "+ com_get +" free.
You must purchase "+com_buy+" of the same item in order to get your free item."'; //Displayed when someone enters a code with multiple items on the same page and it is a $ amount off d_com[8] = '"You have entered " + com_code + ".

Code Value:
" + "$" + com_dis_amt + " discount is now in effect."'; //Displayed when someone enters a code with multiple items on the same page and it is a % amount off d_com[9] = '"You have entered " + com_code + ".

Code Value:
" + com_dis_amt + "%" + " discount is now in effect."'; function create_ad(){ }