// -------------------------------------------------------------------
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];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

// -------------------------------------------------------------------
function getCookie(name){

     // Simply retreives a cookie

var cname = name + "=";
var dc = document.cookie;
     if (dc.length > 0) {
          begin = dc.indexOf(cname);
          if (begin != -1) {
               begin += cname.length;
               end = dc.indexOf(";", begin);
               if (end == -1) end = dc.length;
               return unescape(dc.substring(begin, end));
          }
     }
return null;
}

// -------------------------------------------------------------------
function GoTo(thisURL) {
     self.location = thisURL;
}

// -------------------------------------------------------------------
function openWindow(url, w, h) {
  var options = "width=" + w + ",height=" + h + ",";
  options += "resizable=no,scrollbars=yes,status=no,";
  options += "menubar=no,toolbar=no,location=no,directories=no";
  var newWin = window.open(url, 'newWin', options);
  newWin.focus();
}

// -------------------------------------------------------------------
function OpenWindow(thisURL) {
     var x = 465;
     var y = 465;
     var gWin = window.open(thisURL,'GraphicWindow',
     'width='+x+',height='+y+',resizable=0,scrollbars=0');
}

// -------------------------------------------------------------------
function formReset(){
     for(i = 0; i < document.forms[0].elements.length; i++){
          var inType = document.forms[0].elements[i].type;
          if(inType == "text"){
               document.forms[0].elements[i].value = "";
          }
     }
}

function checkName(form, val){
    form.elements[val].value = form.elements[val].value.replace("'", "");
}

// -------------------------------------------------------------------
function qtyCheck(){

var qtySelected = parseInt(0);
var sizeAvailable = false;
var availableQty = parseInt(1);
var setupSet = false;

 for(a = 0; a < document.forms.length; a++){
     for(i = 0; i < document.forms[a].elements.length; i++){
          var fieldName = document.forms[a].elements[i].name;
          if(fieldName.substring(0,4) == "SIZE"){
               sizeAvailable = true;
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    qtySelected += parseInt(fieldValue);
               }
          }
          if((fieldName.substring(0,8) == "QUANTITY")&&(!sizeAvailable)){
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    qtySelected += parseInt(fieldValue);
               }
          }
          if(fieldName.substring(0,12) == "OPTION|setup"){
               var setupSet = document.forms[a].elements[i].options[1].selected;
               //alert(setupSet);
               //return false;
          }

          if(fieldName == "min_qty"){
               var fieldValue = parseInt(document.forms[a].elements[i].value);
               if(fieldValue > 0){
                    availableQty = parseInt(fieldValue);
               }
          }
     }
 }
 if((qtySelected == 0)&&(sizeAvailable)){
     alert("You have not entered a quantity for the size of an item to add to the cart?");
     return false;
 }
 if((qtySelected == 0)&&(!sizeAvailable)){
     alert("You have not entered a quantity for an item to add to the cart?");
     return false;
 }

 if((qtySelected < availableQty)&&(setupSet)){
     alert("You must purchase a minimum quantity of " + availableQty + " for this item");
     return false;
 }
 if(qtySelected < availableQty){
     alert("You must purchase a minimum quantity of " + availableQty + " for this item");
     return false;
 }


return true;
}


// -------------------------------------------------------------------
var browser=navigator.appName;
var version=navigator.appVersion;

function random_image(number) {
	rnd = Math.random();
	rnd = Math.ceil(rnd * number);
	str_rnd = rnd.toString();
	if (browser.indexOf("Microsoft") >= 0) {
	    if (version.indexOf("3.") >= 0 || version.indexOf("2.") >= 0) {
			document.Top_Header.src = "../source/kid_"+ str_rnd + ".jpg";
		}
		else {
			document.images['Top_Header'].src = "../source/kid_"+ str_rnd + ".jpg";
		}
	}
	else {
		document.images['Top_Header'].src = "../source/kid_"+ str_rnd + ".jpg";
	}
}	

// -------------------------------------------------------------------

function navigate(command){

var linkURL = "store.php";
var task = "?view_cart=yes"
if(command == "checkout"){
     task = "?checkout=yes"
}
linkURL += task + "&return_url=" + escape(document.location);

document.location = linkURL;
return false;
}

// -------------------------------------------------------------------
// This function allows you to set the value in another field
// 		where ff - fieldname to set
//			 val - value to set to
//			 par - optional parameter to allow setting from a window.
//					In that case, you would set par to 'opener'.
//			 att - optional parameter to allow setting other attributes.
//					default is 'value'
function SetAnItem(ff,val,par,att) {
  var strval = val.toString();
  var strParam = "value";
  if(att != ""){
  	strParam = att;
  }
  if(par != ""){
  	eval(par+'.document.getElementById("'+ff+'").'+strParam+' = strval'); 
  }else{
  	eval('document.getElementById("'+ff+'").'+strParam+' = strval'); 
  }
}
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=453,height=337');
self.name = "mainWin";
}
function stripIt(x){
x.value = x.value.replace(/['"]/g,'');
};
//-->


