// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var curr_lb_div;
var is_modal = false;

function ShowLightBox(lb_div, isModal)
{
    document.getElementById(lb_div).style.display='block';
    document.getElementById('fade').style.display='block';
    curr_lb_div = lb_div;
    if (isModal)
        is_modal = true;
    else is_modal = false;
}

function HideLightBox()
{
    if (document.getElementById(curr_lb_div))
    {
         document.getElementById(curr_lb_div).style.display='none';
         document.getElementById('fade').style.display='none';
         document.getElementById(curr_lb_div).innerHTML = '';
         curr_lb_div = '';
				 
    }
}
function emptyLabel(span_name) {
	if (document.getElementById(span_name)) {
		document.getElementById(span_name).innerHTML='';
	}
}

function getHTTPObject(){
   if (window.ActiveXObject) 
       return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
       return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

function loadOverlay(x){
	if (x == 6) {
		document.getElementById('children_overlay').style.width = '800px';
	}
	else if (x==2) {
		document.getElementById('children_overlay').style.width = '500px';
	}
	else {
		document.getElementById('children_overlay').style.width = '400px';
	}
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "../Library/Scripts/overlay/getOverlay.php?x=" + x, true);
        httpObject.send(null); 
				httpObject.onreadystatechange = setOutput;
        
    }
}
// Change the value of the outputText field
function setOutput(){
    if(httpObject.readyState == 4){
        document.getElementById('children_overlay').innerHTML = httpObject.responseText;
    }
 
}

function copyInfo() {
	if (document.form_checkout.copy_info.checked == 1) {
		document.form_checkout.firstname2.value = document.form_checkout.firstname.value;
		document.form_checkout.lastname2.value = document.form_checkout.lastname.value;
		document.form_checkout.email2.value = document.form_checkout.email.value;
		document.form_checkout.address12.value = document.form_checkout.address1.value;
		document.form_checkout.address22.value = document.form_checkout.address2.value;
		document.form_checkout.city2.value = document.form_checkout.city.value;
		document.form_checkout.state2.value = document.form_checkout.state.value;
		document.form_checkout.country2.value = document.form_checkout.country.value;
		document.form_checkout.zip2.value = document.form_checkout.zip.value;
		document.form_checkout.phone2.value = document.form_checkout.phone.value;		
		emptyLabel('firstnameSpan2');
		emptyLabel('lastnameSpan2');
		emptyLabel('emailSpan2');
		emptyLabel('address1Span2');
		emptyLabel('citySpan2');
		emptyLabel('stateSpan2');
		emptyLabel('countrySpan2');
		emptyLabel('zipSpan2');
		emptyLabel('phoneSpan2');		
	}
}

function brandOverlay(x, brand) {
	document.getElementById('children_overlay').style.width = '400px';
	httpObject2 = getHTTPObject();
	if (httpObject2 != null) {
			httpObject2.open("GET", "../Library/Scripts/overlay/getOverlay.php?x=" + x + "&brand=" + brand, true);
			httpObject2.send(null); 
			httpObject2.onreadystatechange = setOutput2;
	}
}
// Change the value of the outputText field
function setOutput2(){
    if(httpObject2.readyState == 4){
        document.getElementById('children_overlay').innerHTML = httpObject2.responseText;
    }
 
}

function showNext(pid,str) { 
	xmlHttp=getHTTPObject();
	if (xmlHttp != null) {
			xmlHttp.open("GET", "../Library/Scripts/getImage.php?q="+str+"&pid="+pid, true);
			xmlHttp.send(null); 
			xmlHttp.onreadystatechange = setOutput3;
	}
}

function setOutput3() {
    if(xmlHttp.readyState == 4){
				 var result = xmlHttp.responseText.split("|");
	 document.getElementById("thumb_"+result[3]).style.backgroundImage ='url(../Library/Images/Product/th/'+ result[1] +')';
	 document.getElementById("full_image").innerHTML= "<a href='javascript:showNext(" +  result[3] +", " + result[2] + ");'><img src='../Library/Images/Product/" + result[0] + "' width='300' style='padding-bottom: 10px;' /></a> ";
    }
}

