var wasTabX = 1;

function showInfoTab(x)
{
 var tabID = "tab" + wasTabX;
 var divID = "tab_content" + wasTabX;
 document.getElementById(tabID).className = "tabB";
 document.getElementById(divID).className = "tabContentB";

 wasTabX = x;

 tabID = "tab" + wasTabX;
 divID = "tab_content" + wasTabX;
 document.getElementById(tabID).className = "tabF";
 document.getElementById(divID).className = "tabContentF";
}

function togglePrices(obj)
{
 if(!document.getElementById('authLetter0').checked)
 {
  //loop, show prices for authentic
  for(var i=1; i<5; i++)
  {
   var basicID = "custom_price_" + i + "_basic";
   var authID = "custom_price_" + i + "_auth";
   if(document.getElementById(basicID))
   { document.getElementById(basicID).style.display = 'none'; }
   if(document.getElementById(authID))
   { document.getElementById(authID).style.display = ''; }
  }
 }
 else
 {
  //loop, show prices for basic
  for(var i=1; i<5; i++)
  {
   var basicID = "custom_price_" + i + "_basic";
   var authID = "custom_price_" + i + "_auth";
   if(document.getElementById(basicID))
   { document.getElementById(basicID).style.display = ''; }
   if(document.getElementById(authID))
   { document.getElementById(authID).style.display = 'none'; }
  }
 }
}

function checkOrder()
{
 var orderOK = "Y";
 var itemSize = '';

 if(document.getElementById("selSize"))
 {
  if(document.getElementById("selSize").selectedIndex==0)
  { alert("Please select a size."); 
    orderOK = '';  }
  else
  { itemSize = document.getElementById("selSize")[document.getElementById("selSize").selectedIndex].value; }
 }

 if(orderOK)
 { 
  if(itemSize)
  { for(i=0; document.getElementById('patch'+i); i++)
    { document.getElementById('patch'+i).value = document.getElementById('patch'+i).value + " " + itemSize; }}
  if(document.getElementById('authLetter0'))
  {
   if(!document.getElementById('authLetter0').checked)
   // get correct pricing for authentic
   {
    var numAuth = 0;
    if(document.getElementById('custom1'))
    { if(document.getElementById('custom1').checked)
      { numAuth++; }}
    if(document.getElementById('custom2'))
    { if(document.getElementById('custom2').checked)
      { numAuth++; }}
    if(numAuth > 0)
    { if(numAuth==2)
      { numAuth = authNumber2Cost; }
      else
      { numAuth = authNumber1Cost; }
      numAuth = numAuth.toFixed(2);
      document.getElementById('hdnAuthNumber').disabled = false;
      document.getElementById('hdnAuthNumber').value = "Yes (+$" + numAuth + ")"; 
    }
   }
   var ltrAuth = 0;
   if(document.getElementById('custom3'))
   { if(document.getElementById('custom3').checked)
     { ltrAuth++; }}
   if(document.getElementById('custom4'))
   { if(document.getElementById('custom4').checked)
     { ltrAuth++; }}
   if(ltrAuth > 0)
   { if(ltrAuth==2)
     { ltrAuth = authLetter2Cost; }
     else
     { ltrAuth= authLetter1Cost; }
     ltrAuth = ltrAuth.toFixed(2);
     document.getElementById('hdnAuthLetter').disabled = false;
     document.getElementById('hdnAuthLetter').value = "Yes (+$" + ltrAuth + ")"; 
   }
  }
  else
  {
   if(document.getElementById('hdnAuthLetter'))
   {
    document.getElementById('hdnAuthLetter').disabled = true;
   }
   if(document.getElementById('hdnAuthNumber'))
   {
    document.getElementById('hdnAuthNumber').disabled = true;
   }
  }
  document.getElementById('formOrder').submit();
 }
}

function displayCheckboxNotice(x)
{
 var obj = document.getElementById("custom"+x+"txt");
 if(obj.disabled == true)
 {
  alert("Please check the box to select this customization,\nthen enter a value in this field.");
 }
}

function toggleBox(x)
{
 if(x == 'cust_tac_agreed')
 {
  var cbObj = document.getElementById(x);
  if(cbObj.checked)
  { cbObj.checked = false; }
  else
  { cbObj.checked = true; }
 } 
 else 
 {
  var cbObj = document.getElementById("custom"+x);
  if(cbObj.checked)
  { cbObj.checked = false;
    if(x < 10) {  lockInputField(x);  }}
  else
  { cbObj.checked = true;
    if(x < 10) {  
     unlockInputField(x); 
     document.getElementById("custom"+x+"txt").focus(); }}
 }
}

function toggleInputField(obj, x)
{
 if(obj.checked)
 { unlockInputField(x);
   document.getElementById("custom"+x+"txt").focus(); }
 else
 { lockInputField(x); }
}

function lockInputField(x)
{
 var txtID = "custom" + x + "txt"; 
 document.getElementById(txtID).value = '';
 document.getElementById(txtID).disabled = true;
}

function unlockInputField(x)
{
 var txtID = "custom" + x + "txt"; 
 document.getElementById(txtID).disabled = false;
}

function showCustomizationOptions() {
 if(document.getElementById('fb_iframe_holder'))
 { document.getElementById('fb_iframe_holder').style.display = 'none'; }
 var divObj = document.getElementById('item_order_custom_fields');
 divObj.style.height = "1000px";
}

function hideCustomizationOptions() {
 if(document.getElementById('fb_iframe_holder'))
 { document.getElementById('fb_iframe_holder').style.display = ''; }
 // hide customizations box
 if(document.getElementById('item_order_custom_fields'))
 { document.getElementById('item_order_custom_fields').style.height = "0px"; }

 // reset all customization fields
 if(document.getElementById('cust_tac_agreed'))
 { document.getElementById('cust_tac_agreed').checked = false; }
 for(var i=1; i<5; i++)
 {
  var oID1 = "custom" + i;
  var oID2 = "custom" + i + "txt";
  if(document.getElementById(oID1))
  { document.getElementById(oID1).checked = false; }
  if(document.getElementById(oID2))
  { document.getElementById(oID2).value = "";
    document.getElementById(oID2).disabled = true; }
 }
 for(i=10; document.getElementById('custom'+i); i++)
 {
  document.getElementById('custom'+i).checked = false;
 }
 if(document.getElementById('authLetter0'))
 { document.getElementById('authLetter0').checked = true; }

 if(document.getElementById('divCustomizationInfo'))
 { document.getElementById('divCustomizationInfo').innerHTML = "Your jersey is not currently customized."; }
}



function saveCustomizationOptions() {
 // make sure some customization fields were selected, if not, just close area
 var hasCustomizations = 0;
 for(var x=1; x<5; x++)
 {
  if(document.getElementById("custom"+x))
  { if(document.getElementById("custom"+x).checked)
    { hasCustomizations++; }
  }
 }

 //check for patches selected and added to item
 for(i=10; document.getElementById('custom'+i); i++)
 {
  if(document.getElementById('custom'+i).checked)
  { hasCustomizations++; }
 }
 
 if(hasCustomizations > 0)
 {
  // make sure each checked box has a corresponding value selected
  var errors = "";

  for(var x=1; x<5; x++)
  {
   if(document.getElementById("custom"+x))
   { if(document.getElementById("custom"+x).checked)
     { 
      var ciTxt = document.getElementById("custom"+x+"txt").value;
      ciTxt = ciTxt.replace(/^\s*/, "").replace(/\s*$/, "");
      if(!ciTxt)
      { errors += "Please enter a value for " + document.getElementById("custom"+x).name.replace(/vwattr..has/,'') + " or uncheck this box.\n"; }      
     }
   }
  }

  if(errors)
  {
   alert(errors);
  }
  else
  {
   // make sure that T&C were agreed to
   if(document.getElementById('cust_tac_agreed').checked)
   {
    // hide customizations box
    document.getElementById('item_order_custom_fields').style.height = "0px";

    // display data from customization fields on order form
    var custTxt = '';
    for(var i=1; i<5; i++)
    {
     var oID2 = "custom" + i + "txt";
     if(document.getElementById(oID2))
     { if(document.getElementById(oID2).value)
       { custTxt += document.getElementById(oID2).name.replace(/vwattr../,'') + ":<b> " + document.getElementById(oID2).value + "</b><br>"; }
     }
    }
    for(i=10; document.getElementById('custom'+i); i++)
    {
     if(document.getElementById('custom'+i).checked)
     { custTxt += "Add <b>" + document.getElementById('patchname'+i).value + "</b> patch<br>"; }
    }
    // set for basic or authentic lettering
    if(document.getElementById('authLetter0').checked) 
    { custTxt += "Lettering Style: <b>Basic</b><br>"; }
    else
    { custTxt += "Lettering Style: <b>Authentic</b><br>"; }

    document.getElementById('divCustomizationInfo').innerHTML = custTxt;
    }
    else
    {
     alert("You must agree to the terms outlined in Step 3 to customize your item.\n\nPlease check the box labeled 'I UNDERSTAND' in Step 3.");
    }
   }
  }
  else
  {
   hideCustomizationOptions();
  }
}


function addScript(url) {
 var s = document.createElement("script");
 s.type = "text/javascript";
 s.src = url;
 document.getElementsByTagName("head")[0].appendChild(s);
}

function addToWishlist(pageID,pageName,imgLoc)
{
 pageName = pageName.replace("&","and");
 var strLocation = "http://ydesigns.biz/tools/wishlist/v2/addlist.php?"+
				  "storeID=yhst-7223899490465&pageID="+pageID+"&pageName="+pageName+"&imgLoc="+imgLoc;
 var yhst7223899490465popup = window.open(strLocation,"yhst7223899490465popup","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width=305,height=540");
 yhst7223899490465popup.focus();
}

function readReviews(itemID,itemImage,itemName,storeIcon)
{
	eval("var reviewpopup = window.open('http://ydesigns.biz/365i/reviews/soccer-en/index.php?storename=WorldSoccerShop.com&ID="+itemID+"&itemImage="+itemImage+"&itemName="+itemName+"&storeIcon="+storeIcon+"','review_popup','menubar=no,scrollbars=1,width=500,height=420,resizable=yes')");
	reviewpopup.focus();
}

function writeReviews(itemID,itemImage,itemName,storeIcon)
{
	eval("var reviewpopup = window.open('http://ydesigns.biz/365i/reviews/soccer-en/write.php?storename=WorldSoccerShop.com&ID="+itemID+"&itemImage="+itemImage+"&itemName="+itemName+"&storeIcon="+storeIcon+"','review_popup','menubar=no,scrollbars=1,width=500,height=640,resizable=yes')");
	reviewpopup.focus();
}


