
	// Will either be 'http:' or 'https:'
urlSecure = window.parent.document.location.protocol;
	// Generate proper URL.
urlSite   = urlSecure + '//' + document.domain;
d=document;

function CreateXmlHttpObject2()
{var XMLHTTP=false;
 if (window.XMLHttpRequest) // if Mozilla, Safari etc
    {XMLHTTP = new XMLHttpRequest();
	}
 else if (window.ActiveXObject)
    { // if IE
     try {XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP")
         } 
     catch (e)
         {try {XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
              }
          catch (e){}
         }
    }
 return XMLHTTP;
}


// Function to display product swatch colors.
function thumbToMain(thumbnail_img, main_img) {	
var mainDiv=d.getElementById('imageMain'),color=urlSite+'/'+thumbnail_img,
fill_span=d.getElementById('restore'),image=d.getElementById('MainImage');

	mainDiv.innerHTML='<img src="'+color+'" width="375" height="350" />';
	fill_span.innerHTML = ' <a href="javascript: defaultMain(\'' + main_img + '\');">Restore product image</a>';	
	fill_span.style.visibility = 'visible';
}
function defaultMain(main_img) {
var mainDiv=d.getElementById('imageMain'),fill_span=d.getElementById('restore'),image=d.getElementById('MainImage');
		// Hide the 'restore' span.
	fill_span.style.visibility = 'hidden';	
	mainDiv.innerHTML='<img src="'+main_img+'" alt="" id="MainImage" border="0" />';				
}
function changeColorSelector(ind,collection,type,color,brand)
{var size=document.getElementById('sizeSelector_'+ind);
 if (color == 'any')
    {color = 'any'
    }
 ajaxobt1 = CreateXmlHttpObject2();
 var url1 = urlSite+'/includes/do_colorSelector.php?collection='+collection+'&type='+type+'&size='+size.options[size.selectedIndex].value+'&indopt='+ind+'&color='+color+'&brand='+brand;
 ajaxobt1.open('GET',url1,'true');
 ajaxobt1.onreadystatechange=function ()
                         {if (ajaxobt1.readyState!=4)
                             {document.getElementById('contColorSelector_'+ind).innerHTML="Loading colors...";
                             }
                          if (ajaxobt1.readyState==4)
                             {if (ajaxobt1.status==200)
                                 { var results=ajaxobt1.responseText;
                                   document.getElementById('contColorSelector_'+ind).innerHTML =results;
		                         }
                      	      else
                                 {document.getElementById('contColorSelector_'+ind).innerHTML="<strong>Error!</strong>";
                                 }
                             }
						 };
 ajaxobt1.send(null);
}
function changePriceByColorSelector(ind,type,collection,size,brand)
{ajaxobt2 = CreateXmlHttpObject2();
 var s1 = document.getElementById('colorSelector_'+ind);
 var size = document.getElementById('sizeSelector_'+ind); 
 
 var url2 = urlSite+'/includes/do_priceByColorSelector.php?collection='+collection+'&type='+type+'&size='+size.options[size.selectedIndex].value+'&indopt='+ind+'&color='+s1.options[s1.selectedIndex].value+'&brand='+brand;
 ajaxobt2.open('GET',url2,'true');
 ajaxobt2.onreadystatechange=function ()
                         {if (ajaxobt2.readyState!=4)
                             {document.getElementById('price_'+ind).innerHTML="Loading...";
                             }
                          if (ajaxobt2.readyState==4)
                             {if (ajaxobt1.status==200)
                                 { var results=ajaxobt2.responseText;
                                   document.getElementById('price_'+ind).innerHTML =results;
		                         }
                      	      else
                                 {document.getElementById('price_'+ind).innerHTML="<strong>Error!</strong>";
                                 }
                             }
						 };
 ajaxobt2.send(null);
}
function closeCartResume()
{var div1 = document.getElementById('scAdded');
 document.body.removeChild(div1);
//div1.setAttribute ('style','visibility:hidden');
// div1.style='visibility:hidden';
}
function validateFieldsEmpty()
{var frm = document.getElementById('addForm');//Gets the form
 var qtyPosEle = document.getElementById('qtyPosiblesElements').value;
 var ctrlSend = 0;
 for (i=0;i<qtyPosEle;i++)
     {//validates if the a size is selected
	  //=============================================
	  var sizeSelectorTmp = document.getElementById('sizeSelector_'+i);
	  if (sizeSelectorTmp.options[sizeSelectorTmp.selectedIndex].value!='')
	     {var colorSelectorTmp = document.getElementById('colorSelector_'+i);
          if (colorSelectorTmp.options[colorSelectorTmp.selectedIndex].value != '')
		     {if (document.getElementById('qtyEle_'+i).value > 0)
			     {ctrlSend=1;
				 }
			 }
		 }
	 }
	 
	 
 if (ctrlSend==0)
    {alert ('Please select at least one element with size, color and quantity');
	}
 else
    {frm.submit();
	}
}
function changeFinalPriceByTaxAndShipMethod()
{
ajaxobt3 = CreateXmlHttpObject2();
 var sShip = document.getElementById('ship_id');
 var sTax = document.getElementById('state_tax');
		// Tax is now nonexistant, so we'll just take the value.
	var idTax = sTax.value;
	
		// If tax is to be selected, uncomment this, and
		// comment the line above.
		// var idTax = sTax.options[sTax.selectedIndex].value;
 var idShip = sShip.options[sShip.selectedIndex].value;
 var baseprice = document.getElementById('elements_price_subtotal').value;
 
 var url3 = urlSite+'/includes/do_finalPriceByTaxAndShip.php?baseprice='+baseprice+'&idtax='+idTax+'&idship='+idShip;
 ajaxobt3.open('GET',url3,'true');
 ajaxobt3.onreadystatechange=function ()
                         {if (ajaxobt3.readyState!=4)
                             {document.getElementById('total_price').innerHTML="Waiting for total...";
                             }
                          if (ajaxobt3.readyState==4)
                             {if (ajaxobt3.status==200)
                                 { var results=ajaxobt3.responseText;
                                   document.getElementById('total_price').innerHTML = results;
		                         }
                      	      else
                                 {document.getElementById('total_price').innerHTML="<strong>Error!</strong>";
                                 }
                             }
						 };
 ajaxobt3.send(null);
 baseprice = null;
 idShip=null;
 idTax=null;
 sShip=null;
 sTax=null;
}
