// JavaScript


/*
 * CanKoozie.com Shopping System
 * Main JavaScript
 *
*/

function info(int_pid){

    window.open("info.php?x="+int_pid, "productInfo", "toolbar=no,directories=no,menubar=no,location=no,height=300,width=400,left=150,top=100");
    

}

function add(int_field,int_pid){
    pqty = parseInt(document.getElementById(int_field).value);
    if(document.URL.indexOf("blank-koozies") != -1 && pqty < 50){
        alert("50 is the minimum order. Please update your quantity.");
    }else{
    if(pqty!==NaN){
     document.forms[0].x.value=pqty+":"+int_pid;
     document.forms[0].submit();
    }else{
      e = document.getElementById(int_field);
      e.style.backgroundColor='#FF0000';
      alert("Invalid Quantity, Please type a number and try again.");
      e.select();
    }
    }

}

function del(){
  if(is_checked()){
    document.forms[0].submit();
  }else{
    alert("No Item(s) selected to delete...");
  }
}

function upd(){
   if(is_checked()){
    document.forms[0].x.value='1';
    document.forms[0].submit();
   }else{
    alert("No Item(s) selected to update...");
   }
}

function is_checked(){
  i = 0;
  flag = false;
  for(;i<document.forms[0].elements.length; i++){
    e = document.forms[0].elements[i];
    if(e.type=='checkbox' && e.checked==true){
      flag = true;
      break;
    }
  }
  return flag;
}

function checkout(){
  location.href='./index.php?x=4';
}

var all_selected = false;

function select_all(){
    for(i=0;i<document.forms[0].elements.length;i++){
      e = document.forms[0].elements[i];
      if(e.type=='checkbox'){
        if(!all_selected){
         e.checked='checked';
        }else{
         e.checked='';
        }
      }
      
    }
    all_selected = all_selected ? false : true;

}

function populate_shipping(){
  f = document.forms[0];
  f.s_fname.value = f.b_fname.value;
  f.s_lname.value = f.b_lname.value;
  f.s_address.value = f.b_address.value;
  f.s_city.value = f.b_city.value;
  f.s_state.value = f.b_state.value;
  f.s_zip.value = f.b_zip.value;
  f.s_country.selectedIndex = f.b_country.selectedIndex;
  f.s_phone.value = f.b_phone.value;
}

function validate_checkout(){
  i=0;
  flag = true;
  for(;i<document.forms[0].elements.length;i++){
    e = document.forms[0].elements[i];
    if(e.type=='text' && e.value.length<=0 && e.disabled==false){
      e.style.border='1px solid #F00';
      e.style.backgroundColor='#FFC';
      flag = false;
      break;
    }else{
      if(!e.disabled){
       e.style.border='';
       e.style.backgroundColor='#FFF';
      }
    }
    if(e.name=='b_country'||e.name=='s_country'){
     if(e[e.selectedIndex].value == 'void'){
      e.style.backgroundColor='#FFC';
      flag = false;
      break;
     }else{
      e.style.backgroundColor='#FFF';
     }
    }
 }
 if(!flag){ alert("You have not provided sufficient data in the highlighted fields."); }
 else{ document.forms[0].submit(); }
}

function paypal(){
    f = document.forms[0];
    f.ccardnum.disabled='disabled';
    f.ccardnum.backgroundColor='#CCC';
    f.exp_year.disabled='disabled';
    f.exp_year.backgroundColor='#CCC';
    f.exp_month.disabled='disabled';
    f.exp_month.backgroundColor='#CCC';
    f.verif.disabled='disabled';
    f.verif.backgroundColor='#CCC';
}

      
function ccard(){
    f = document.forms[0];
    f.ccardnum.disabled='';
    f.ccardnum.backgroundColor='#FFF';
    f.exp_year.disabled='';
    f.exp_year.backgroundColor='#FFF';
    f.exp_month.disabled='';
    f.exp_month.backgroundColor='#FFF';
    f.verif.disabled='';
    f.verif.backgroundColor='#FFF';

}

function MM_random(){ //v.1
  var images = new Array();
  images[0] = bp + "index/img/coronacanfoam.png";
  images[1] = bp + "index/img/licensedbeerkoozies.png";
  images[2] = bp + "index/img/licensedcancoolers.png";
  images[3] = bp + "index/img/licensedcancovers.png";
  images[4] = bp + "index/img/beerkoozies.png";
  var i = Math.floor(images.length*Math.random());
  
  if(navigator.appName.toLowerCase().indexOf("microsoft")!=-1){
    //alert("adding filter");
    document.write("<img src='../index/img/pixel.gif' style=\"filter:progid:DXImageTransform.Microsoft."+
                   "AlphaImageLoader(src='"+images[i]+"', sizingMethod='image');\""+
                   " />");
  }else{
    document.write("<img src='"+images[i]+"' alt='' />");
  }
}

 
  
