// JavaScript Document

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/" +"; domain=signdealers.com";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function init() {
	//for (var i=1;i<3;i++) {
		//var x = Cookies['signtype' + i];
				//if (x) alert('Cookie signtype' + i + '\nthat you set on a previous visit, is still active.\nIts value is ' + x);
		var x = Cookies['signtype'];
		var y = Cookies['orderpref'];
		var z = Cookies['designpref'];
		var xdone = false;
		var ydone = false;
		var zdone = false;
		
		if (x) {
			//alert('Cookie signtype' + '\nthat you set on a previous visit, is still active.\nIts value is ' + x);
			//document.sdsearch.signtype[0].checked = true;							
			for (i=0;i<document.sdsearch.signtype.length;i++) {
				if (document.sdsearch.signtype[i].value == x) {
				//user_input = document.forms[0].radios[i].value;
					document.sdsearch.signtype[i].checked = true;
					xdone = true;
				}//if
			}//for	
			if(xdone == false) {
				document.sdsearch.signtype[0].checked = true;
			}
		} else {
			document.sdsearch.signtype[0].checked = true;
		}//x
		
		if (y) {
			for (i=0;i<document.sdsearch.orderpref.length;i++) {
				if (document.sdsearch.orderpref[i].value == y) {
					document.sdsearch.orderpref[i].checked = true;
					ydone = true;
				}//if
			}//for
			if(ydone == false) {
				document.sdsearch.orderpref[0].checked = true;
			}
		} else {
			document.sdsearch.orderpref[0].checked = true;
		}//y	
		
		if (z) {
			for (i=0;i<document.sdsearch.designpref.length;i++) {
				if (document.sdsearch.designpref[i].value == z) {
					document.sdsearch.designpref[i].checked = true;
					zdone = true;
				}//if
			}//for	
			if(zdone == false) {
				document.sdsearch.designpref[0].checked = true;
			}
		} else {
			document.sdsearch.designpref[0].checked = true;
		}//z
	//}
}

//window.onload = function () {
	//if (self.init)
		//init();
//}

/* COOKIES */

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();


function validateAndSubmit (myForm, myAction) {

var thisorderpref = "0_nopref" //default was 0_ph
var thisdesignpref = "d_nopref" //default was d_off
var thissigntype = "banners" //default

var orderprefno = 0;
var designprefno = 0;

formok = "yes"; 
 
  if(formok == "yes") {
	
	for (i=0;i<myForm.orderpref.length;i++){
		if (myForm.orderpref[i].checked==true){
			thisorderpref = myForm.orderpref[i].value;
			orderprefno = i;
		break //exist for loop, as target acquired.
		}
	}
	
	for (i=0;i<myForm.designpref.length;i++){
		if (myForm.designpref[i].checked==true){
			thisdesignpref = myForm.designpref[i].value;
			designprefno = i;
		break //exist for loop, as target acquired.
		}
	}
	
	for (i=0;i<myForm.signtype.length;i++){
		if (myForm.signtype[i].checked==true){
			var thissigntype = myForm.signtype[i].value;
		break //exist for loop, as target acquired.
		}
	}
	
	//var newurl = thisorderpref + "/" + thisdesignpref + "/" + thissigntype + "/index.html";
	if(thisorderpref=="o_onl"){
		thisorderpref = "orderonline";
	}
	if(thisdesignpref=="d_onl"){
		thisdesignpref = "designonline";
	}
	 
	var newurl = ""; //init
	
	if(thisorderpref=="o_nopref"){
		if(thisdesignpref=="d_nopref"){
			newurl = thissigntype + ".html";
		} else {
			newurl = thisdesignpref + "/" + thissigntype + ".html";
		} //END thisdesignpref
		
	} else {
		if(thisdesignpref=="d_nopref"){
			newurl = thisorderpref + "/" + thissigntype + ".html";
		} else {
			newurl = thisorderpref + "/" + thisdesignpref + "/" + thissigntype + ".html";
		} //END thisdesignpref
	} //END thisorderpref
	
	
	
	
		
	window.location = newurl;

  }//formok == yes
} //validateAndSubmit