// 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=137lawyers.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['practicearea'];
		var y = Cookies['name'];
		var z = Cookies['phone'];
		var a = Cookies['email'];
		//var b = Cookies['description'];
		var xdone = false;
		var ydone = false;
		var zdone = false;
		var adone = false;
		//var bdone = 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.practicearea.length;i++) {
				if (document.sdsearch.practicearea[i].value == x) {
				//user_input = document.forms[0].radios[i].value;
					document.sdsearch.practicearea[i].checked = true;
					xdone = true;
				}//if
			}//for	
			if(xdone == false) {
				document.sdsearch.practicearea[0].checked = true;
			}
		} else {
			document.sdsearch.practicearea[0].checked = true;
		}//x
		
		if (y) {
			if (document.sdsearch.name.value == "") {
				//user_input = document.forms[0].radios[i].value;
					document.sdsearch.name.value = y;
					ydone = true;
			}//if
		} else {
			//document.sdsearch.orderpref[0].checked = true;
		}//y	
		
		if (z) {
			if (document.sdsearch.phone.value == "") {
				//user_input = document.forms[0].radios[i].value;
					document.sdsearch.phone.value = z;
					zdone = true;
			}//if
		} else {
			//document.sdsearch.designpref[0].checked = true;
		}//z
		
		if (a) {
			if (document.sdsearch.email.value == "") {
				//user_input = document.forms[0].radios[i].value;
					document.sdsearch.email.value = a;
					adone = true;
			}//if
		} else {
			//document.sdsearch.designpref[0].checked = true;
		}//a
		
	
		
	//}
}

//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) {

formok = "yes"; 
 
  if(formok == "yes") {
	
	
	
	for (i=0;i<myForm.practicearea.length;i++){
		if (myForm.practicearea[i].checked==true){
			var thispracticearea = myForm.practicearea[i].value;
		break //exist for loop, as target acquired.
		}
	}
	
	//var newurl = thisorderpref + "/" + thisdesignpref + "/" + thissigntype + "/index.html";
	
	var newurl = thispracticearea + ".html";
		
	window.location = newurl;

  }//formok == yes
} //validateAndSubmit

