/*

	GIft Baskets and More Javascript 
	
*/

//
//Declare Global variables
//

var numPages = 2

//
//Remove Status Text
//

var statusmsg=""

function nostatus(){
window.status=statusmsg
return true

}


function showrows(i,j){
	
	document.getElementById("picrow" + i).className="formShow";
	document.getElementById("picrow" + j).className="formShow";

}

function switchpics(showing,going){

	if(showing < going){
		row1 = showing;
		row2 = showing +1;
		row3 = going ;
		row4 = going +1;
		document.getElementById("picrow" + row1).className="formHide";
		document.getElementById("picrow" + row2).className="formHide";
		document.getElementById("picrow" + row3).className="formShow";
		document.getElementById("picrow" + row4).className="formShow";
	}else{
		row1 = going - 1;
		row2 = going;
		row3 = showing -1;
		row4 = showing;
		document.getElementById("picrow" + row3).className="formHide";
		document.getElementById("picrow" + row4).className="formHide";
		document.getElementById("picrow" + row1).className="formShow";
		document.getElementById("picrow" + row2).className="formShow";
	}
}



//
//open popup windows
//

var newwindow;

function openwin(url,w,h)
{
	newwindow=window.open(url,'GBandMore','height='+h+',width='+w+',left=100,top=100,resizable=no,scrollbars=no,toolbar=no,status=no');
	if (window.focus) {newwindow.focus()}
}

//
//Check Order Form for Validity
//

var numPages = 3;

function changePage(step,newclass){	
	i=1;
	while (i<=numPages){
			document.getElementById("formtitle" + i).className="formHide";
			document.getElementById("formpage" + i).className="formHide";
			i++;
	}
	document.getElementById("formtitle" + step).className=newclass;
	document.getElementById("formpage" + step).className=newclass;
}

function showFrame(element,newclass){
	document.getElementById(element).className=newclass;
}

function showPic(pic1,pic2){
	document.getElementById(pic1).className="formHide";
	document.getElementById(pic2).className="formShow";
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;   
}

function IsEmail(sText){
	var testresults;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})$/i ;
	
	//old end of filter : \.([a-z]{2,6}(?:\.[a-z]{2})?)
	
	if (filter.test(sText)){
		testresults=true;
	}else{
		testresults=false;
	}
	return testresults;
}

function firstformok() {
	 title1=document.getElementById("title").value;
	 fname1=document.getElementById("firstname").value;
	 lname1=document.getElementById("lastname").value;
	 email1=document.getElementById("email").value;
	 street1=document.getElementById("street1").value;
	 street2=document.getElementById("street2").value;
	 city1=document.getElementById("city").value;
	 state1=document.getElementById("state").value;
	 zip1=document.getElementById("zipcode").value;
	 phone1=document.getElementById("phoneac").value;
	 phone12=document.getElementById("phonedig").value;
	 fax1=document.getElementById("faxac").value;
	 fax12=document.getElementById("faxdig").value;
	 	 
	 if (fname1 == ""){
	 	alert("You must fill in your First Name!");
	 	return false;
	 }else if (lname1 == ""){
	 	alert("You must fill in your Last Name!");
	 	return false;
	 }else if (email1 == ""){
	 	alert("You must fill in your Email Address!");
	 	return false;
	 }else if (street1 == ""){
	 	alert("You must fill in your Address!");
	 	return false;
	 }else if (city1 == ""){
	 	alert("You must fill in your City!");
	 	return false;
	 }else if (state1 == ""){
	 	alert("You must fill in your State!");
	 	return false;
	 }else if (zip1 == ""){
	 	alert("You must fill in your Zip Code!");
	 	return false;
	 }else if (phone1 == ""){
	 	alert("You must fill in your Phone Area Code!");
	 	return false;
	 }else if (phone12 == ""){
	 	alert("You must fill in your Phone Number!");
	 	return false;
	 }else{
	 	SetCookie('fullname',title1+" "+fname1+" "+lname1,'1','/','','');
	 	SetCookie('street1',street1,'1','/','','');
	 	if (street2 != ""){
	 		SetCookie('street2',street2,'1','/','','');
	 	}else{
	 		SetCookie('street2'," ",'1','/','','');
	 	}
	 	SetCookie('city',city1,'1','/','','');
	 	SetCookie('state',state1,'1','/','','');
	 	if (fax1 != ""){
	 		SetCookie('fax',"("+fax1+") "+fax12,'1','/','','');
	 	}else{
	 		SetCookie('fax'," ",'1','/','','');
	 	}
	 	if ((IsNumeric(zip1)) && (zip1.length >= 5) && (zip1.length <= 9)){
	 		SetCookie('zipcode',zip1,'1','/','','');
	 		if ((IsNumeric(phone1)) && (phone1.length == 3)){
	 			if ((IsNumeric(phone12)) && (phone12.length >= 7)&& (phone12.length <= 8)){
	 				SetCookie('phone',"("+phone1+") "+phone12,'1','/','','');
	 				if (IsEmail(email1)){
	 					changePage('2','formShow');
	 					SetCookie('email',email1,'1','/','','');
	 					return true;
	 				}else{
	 					alert("Email address is incorrect form");
	 					return false;
	 				}
	 			}else{ 
	 				alert("Phone number must be 7 numbers");
	 				return false;
	 			}
	 		}else{
	 			alert("Area code must be 3 numbers");
	 			return false;
	 		}
	 	}else{
	 		alert("Zip Code must be between 5 & 9 numbers");
	 		return false;
	 	}
	 }
	 
}

function secondformok() {
	 title2=document.getElementById("titled").value;
	 fname2=document.getElementById("firstnamed").value;
	 lname2=document.getElementById("lastnamed").value;
	 street1d=document.getElementById("street1d").value;
	 street2d=document.getElementById("street2d").value;
	 city2=document.getElementById("cityd").value;
	 state2=document.getElementById("stated").value;
	 zip2=document.getElementById("zipcoded").value;
	 
	 if (fname2 == ""){
	 	alert("You must fill in Recipient's First Name!");
	 	return false;
	 }else if (lname2 == ""){
	 	alert("You must fill in Recipient's Last Name!");
	 	return false;
	 }else if (street1d == ""){
	 	alert("You must fill in Recipient's Address!");
	 	return false;
	 }else if (city2 == ""){
	 	alert("You must fill in Recipient's City!");
	 	return false;
	 }else if (state2 == ""){
	 	alert("You must fill in Recipient's State!");
	 	return false;
	 }else if (zip2 == ""){
	 	alert("You must fill in Recipient's Zip Code!");
	 	return false;
	 }else{
	 	fullnamed = title2+" "+fname2+" "+lname2;
	 	SetCookie('fullnamed',fullnamed,'1','/','','');
	 	SetCookie('street1d',street1d,'1','/','','');
	 	if (street2d != ""){
	 		SetCookie('street2d',street2d);
	 	}else{
	 		SetCookie('street2d'," ",'1','/','','');
	 	}
	 	SetCookie('cityd',city2,'1','/','','');
	 	SetCookie('stated',state2,'1','/','','');
	 	if ((IsNumeric(zip2)) && (zip2.length >= 5) && (zip2.length <= 9)){
	 		changePage('3','formShow');
	 		SetCookie('zipcoded',zip2,'1','/','','');
	 		return true;
	 	}else{
	 		alert("Zip Code must be between 5 and 9 numbers");
	 		return false;
	 	}
	 }

}

function thirdformok() {
	 qmaxchars = 300;
	 rmaxchars = 150;
	 q = eval(document.getElementById("comments").value.length);
	 r = eval(document.getElementById("card").value.length);
	 occasion=document.getElementById("occasion").value;
	 card=document.getElementById("card").value;
	 comments=document.getElementById("comments").value;
	 cost=document.getElementById("cost").value;
	 readinfo=document.getElementById("readinfo").checked;
	 
	 
	 if (readinfo == "false"){
	 	alert("Please read the Price information sheet");
	 	return false;	 	
	 }
	 if (occasion == ""){
	 	alert("Please enter the Occasion for the Basket");
	 	return false;
	 }else if (cost == ""){
	 	alert("Please enter a Maximum Basket Cost");
	 	return false;
	 }else if (comments == ""){
	 	alert("Please enter some information about recipient");
	 	return false;
	 }else{	
		if (IsNumeric(cost)){
			if(q < qmaxchars){
				if (r < rmaxchars){
	 				SetCookie('occasion',occasion,'1','/','','');
					SetCookie('cost',cost,'1','/','','');
				 	SetCookie('card',card,'1','/','','');
	 				SetCookie('comments',comments,'1','/','','');
					submitit();
				}else{
					alert('Too much data in the text box! Please remove at least'+ (r - maxchars) + ' characters');
					return false;
				}
			}else{
				alert('Too much data in the text box! Please remove at least'+ (q - maxchars) + ' characters');
				return false;
			} 
		}else{
			alert("Basket Cost must be a Number");
			return false;
		}
	 }

}

function submitit(){
	document.getElementById("GBForm").submit();
}

function finalformok(){
	document.getElementById("gborderform").submit();
}

function submittoccprocessing(){
	document.getElementById("linkpointform").submit();
}

var sURL = "http://www.gbandmore.com/index.html";

function doLoad()
{
    // the timeout value should be the same as in the "refresh" meta-tag
    setTimeout( "refresh()", 2*1 );
}

function refresh()
{
    //  This version of the refresh function will cause a new
    //  entry in the visitor's history.  It is provided for
    //  those browsers that only support JavaScript 1.0.
    //
    window.location.href = sURL;
}

function formok(){

	maxchars = 300;
	var q = eval(document.getElementById("comments").value.length);
	email = document.getElementById("email").value;

	fname = document.getElementById("firstname").value;
	lname = document.getElementById("lastname").value;
	
	if (fname == ""){
		alert("You must fill in your First Name!");
		return false;
	}else if (lname == ""){
		alert("You must fill in your Last Name!");
		return false;
	}else{
		if (IsEmail(email)){
			if(q < qmaxchars){
				return true;
			}else{
				alert('Too much data in the text box! Please remove at least'+ (q - maxchars) + ' characters');
				return false;
			}
		}else{
			alert("Email address is incorrect form");
			return false;
		}

	}

}
