function getclickM() {
monthlystats = document.clickstats.clickM.options[document.clickstats.clickM.selectedIndex].value;
location.href = "index.php?modID=clicks&" + monthlystats;
}
function getclickW() {
weeklystats = document.clickstats.clickW.options[document.clickstats.clickW.selectedIndex].value;
location.href = "index.php?modID=clicks&" + weeklystats;
}

function getsalesM() {
monthlystats = document.salesstats.salesM.options[document.salesstats.salesM.selectedIndex].value;
location.href = "index.php?modID=sales&" + monthlystats;
}

function getsalesW() {
weeklystats = document.salesstats.salesW.options[document.salesstats.salesW.selectedIndex].value;
location.href = "index.php?modID=sales&" + weeklystats;
}

function todayStats() {
location.href = "index.php?modID=clicks&" + todaydate;
}
function weekStats() {
location.href = "index.php?modID=clicks&" + weekdate;
}
function monthStats() {
location.href = "index.php?modID=clicks&" + monthdate;
}
function getclicksheet(feedauth)
{
window.open ("clicksheet.php?" + feedauth, 'newWin', 'scrollbars=no,status=no,width=350,height=365,left = 230,top = 35');
}


function getprodfeed(feedauth)
{
window.open ("http://www.myshop.com/" + feedauth, 'newWin', 'scrollbars=no,status=no,width=350,height=365,left = 230,top = 35');
}
function getclicksheet(feedauth)
{
window.open ("clicksheet.php?" + feedauth, 'newWin', 'scrollbars=no,status=no,width=350,height=365,left = 230,top = 35');
}

// Various Scripts pertaining to the pages.


// product invite to friend pop-up
function invite(theurl)
{
window.open (theurl, 'newWin', 'scrollbars=no,status=no,width=250,height=520,left = 230,top = 35');
}

// help window pop-up
function gethelp()
{
window.open("help/login.php", 'newWin', 'scrollbars=no,status=no,width=350,height=400,left = 230,top = 35');
}

// category list pop up
var newwindow = '';
function catList(catId, searchType)
{
var catIdvars = "";
if(searchType == "cstmSearch") {
catIdvars = "searchID=" + catId;
} else {
catIdvars = "categoryID=" + catId;
}

	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = "tplates/catItemList.php?" + catIdvars;
	}
	else
	{

		newwindow=window.open("tplates/catItemList.php?" + catIdvars,'name','scrollbars=yes,status=no,height=480,width=210');

		if (!newwindow.opener) 
            newwindow.opener = self;
	}
	if (window.focus) {
      newwindow.focus();
      }
      return;
}


function showProd(prodID)
{
  opener.location.href = "../index.php?productID=" + prodID;
}


function getupdated()
{
window.open ("tplates/mailingsignup.php", 'newWin', 'scrollbars=no,status=no,width=350,height=480,left = 180,top = 25');
}

function getusrpass()
{
window.open ("affmainincs/usrforgotusrpass.php", 'newWin', 'status=no,width=350,height=300,left = 180,top = 25');
}

// cart script used in cart.php to update item quantity on select
function UpdateQty(item, ioption)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;
document.location.href = 'cart.php?action=update_item&productID=' +itemId+ '&qty=' +newQty+ '&productOptions=' +ioption;
}

// cart script used in cart.php to update item option on select
function UpdateOption(ioption, itemsId, oldoption, oldqty)
{
itemId = itemsId;
newquantity = oldqty;
newoption = ioption.options[ioption.selectedIndex].value; 				
document.location.href = 'cart.php?action=update_option&productID='+itemId+'&productOptions='+newoption+'&prevoption='+oldoption+'&qty='+newquantity;
}
var submitcount=0;

function checkFields() {
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert(jsString07);
      return false;
      }
}   
   
function checkaffinfo() {
    var string0 = document.orderform.firstname.value;
    var string1 = document.orderform.lastname.value;
    var string2 = document.orderform.street.value;
    var string3 = document.orderform.zipcode.value;
    var string4 = document.orderform.city.value;
    var string5 = document.orderform.state.value;
    var string6 = document.orderform.email.value;
    var string7 = document.orderform.tel.value; 
    var string8 = document.orderform.celtel.value;
    var string9 = document.orderform.username.value;
    var string10 = document.orderform.password.value; 
    var string11 = document.orderform.emailconfirm.value;
    var string12 = document.orderform.companyname.value;
    var string13 = document.orderform.vatnum.value;
    var string14 = document.orderform.website.value;
    var illegalChars = /[\W_]/; // allow only letters and numbers

    var goodEmail = document.orderform.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.pt)|(\..{2,2}))$)\b/gi);
 
/*   
    if (!document.orderform.ttall) {
      alert('Your cart is empty.');
      return;
  }  
      var ttaltrim = document.MYFORM.ttall.value
      var ttaltrim = ttaltrim.replace(" €", "");
      var newttrim = ttaltrim;                                
    if (newttrim <= 11.43){
      alert('Sorry, minimum order is 7.23 This does not include shipping fees');
      return;
  } 

*/  
    if (!goodEmail){
      alert(jsString02);
      document.orderform.email.value = "na@na.com";
      document.orderform.emailconfirm.value = "na@na.com";
      location.href="#persdata";
      return;
  }
  
    if ((string0.length <= 2) || (string1.length <= 2)){
      alert(jsString01);
      location.href="#persdata";
      return;
  } 
      if (string2.length <= 1) {
      alert(jsString03);
      document.orderform.street.value = "00na";
      location.href="#persdata";
      return;
  }
      if (string3.length <= 3) {
      alert(jsString04);
      location.href="#persdata";
      return;
  }   
      if ((string4.length <= 3) && (string5.length <= 3)){
      alert(jsString05);
      location.href="#persdata";
      return;
  }
      if ((string7.length <= 2) && (string8.length <= 2)){
      alert(jsString06);
      document.orderform.tel.value = "00na";
      location.href="#persdata";
      return;
  }
      if (string6 != string11){
      alert(jsString09);
      location.href="#persdata";
      return;
  }


    if ((string9.length < 4) || (string9.length > 12) || (string9 == "")) {
      alert(jsString10);
      location.href="#persdata";
      return;
    }

    if(illegalChars.test(string9)) {
      alert(jsString11);
      location.href="#persdata";
      return;
    }

    if ((string10.length < 4) || (string10.length > 12) || (string10 == "")) {
      alert(jsString12);
      location.href="#persdata";
      return;
    }

    if(illegalChars.test(string10)) {
      alert(jsString13);
      location.href="#persdata";
      return;
    }


    if(document.orderform.usertype.value == "wsaleID"){
    if(string12.length < 3) {
      alert(jsString14);
      location.href="#persdata";
      return;
    }
    if(string13.length < 3) {
      alert(jsString15);
      location.href="#persdata";
      return;
    }
    }

    if(document.orderform.usertype.value == "affltID"){
    if(string14.length < 3) {
      alert(jsString16);
      location.href="#persdata";
      return;
    }
    }
  
document.orderform.submit();
}

function printorderinfo(){
text=document.orderinfo.S1.value;
print(text);
}

function getSearch(){
text = document.getElementById("searchID").value;
location.href = "index.php?searchID=" + text;
}

function handleEnter(field, event) {
  var keyCode = event.keyCode ? event.keyCode : 
                event.which ? event.which : event.charCode;
  if (keyCode == 13) {
    getSearch();
    return false;
  }
  else
    return true;
}

