function MM_reloadPage(init) {  //Updated by PVII. Reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}

function MM_showHideLayers() { //v3.0A Modified by Al Sparber and Massimo Foti for NN6 Compatibility
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function submitForm() {
// this function is to redirect the user to the coordinates

var loc 			= "product.cgi?";
var product			= "product=";
var cor_product 		= document.form1.coordinate_product_id.value;
var cart			= "&cart_id=";
var cart_id			= document.form1.cart_id.value;
loc += product += cor_product += cart += cart_id;
location.href = loc;
}
function submit_cat(){
var loc 	= "cat.cgi?";
var cart	= "cart_id=";
var cart_id	= document.form1.cart_id.value;
loc += cart += cart_id;
location.href = loc;
}
function tester(formstring)
{


  /*check through all the fields*/

  creditcard_no_testlength = document.formtest.creditcard_no.value.length  ;
  name_testlength = document.formtest.name.value.length  ;
  address_testlength = document.formtest.address.value.length  ;
  phone_testlength = document.formtest.phone.value.length  ;
  e_mail_testlength = document.formtest.e_mail.value.length  ;
  name_on_card_testlength = document.formtest.name_on_card.value.length  ;


  if(eval(creditcard_no_testlength) < 1)
  {
  alert("please enter your credit card number");
  return (false);
  }

  if(eval(name_testlength) < 1)
  {
  alert("please enter your name");
  return (false);
  }

  if(eval(address_testlength) < 1)
  {
  alert("please enter your address");
  return (false);
  }

  if(eval(phone_testlength) < 1)
  {
  alert("please enter your telephone number");
  return (false);
  }

  if(eval(e_mail_testlength) < 1)
  {
  alert("please enter your email address");
  return (false);
  }

  if(eval(name_on_card_testlength) < 1)
  {
  alert("please enter name on credit card");
  return (false);
  }

  /*********end check*************/

    possible_NaN_at_start = new String(parseInt(formstring.charAt(0)));

    if((parseInt(formstring.charAt(0)) == 0) || (possible_NaN_at_start.indexOf("NaN")!=-1))
    {
    window.alert("invalid credit card number");
    return (false);
    }


    for(i=0;i<formstring.length;i++)
    {
		possible_NaN = new String(parseInt(formstring.charAt(i)));

		if((possible_NaN.indexOf("NaN")!=-1) && (formstring.charAt(i)!= " "))
		{
			window.alert("numbers only please in credit card field");
			return (false);
		}
    }

    formstring = strip(formstring);

    if(formstring.length < 1)
    {
    alert("please enter a value");
    return(false);
    }

    if(isCreditCard(formstring) == true)
    {
      /*alert("valid card number");*/
      return (true);
    }

    else
    {
       alert("not valid card number");
       return (false);
    }
}

function strip(val)
 {
 	val = "" + val;
	if (!val)
	return "";
	var result = "";

	for (i=0;i<val.length;i++)
	{
		character = val.charAt(i);
		if ("0123456789".indexOf(character) != -1)
		result += character;
	}

	 return result;
 }


function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);
}

function checkdetails() {


	if(attic.name.value == "")
		{
		alert("Please enter a name.");
		attic.name.focus();
		return false;
		}
    else if(attic.address.value == "")
	{
		alert("Please enter an address.");
		attic.address.focus();
		return false;
		}
	else if(attic.telephone.value == "")
	{
		alert("Please enter a Telephone Number.");
		attic.telephone.focus();
		return false;
		}
	else if(attic.age_of_house.value == "")
	{
		alert("Please enter the age of the hosue.");
		attic.age_of_house.focus();
		return false;
		}
	else if(attic.sidetoside.value == "")
	{
		alert("Please select House size from side to side.");
		attic.sidetoside.focus();
		return false;
		}
	else if(attic.fronttoback.value == "")
	{
		alert("Please select House size from front to back.");
		attic.fronttoback.focus();
		return false;
		}
	else if(attic.roofheight.value == "")
	{
		alert("Please select size of roof from space in the middle.");
		attic.roofheight.focus();
		return false;
		}
	else
		{
  		return emailCheck(attic.email.value);
        }
}

