// JavaScript Document

function GetElementById(ename)
{
	var obj;
	
	if (document.all)
	{
		eval("obj = document.all[\"" + ename + "\"]");
	}
	else if (document.layers)
	{		
		eval("obj = document.layers[\"" + ename + "\"]");
	}
	else if (document.getElementById)
	{	
		eval ("obj = document.getElementById (\"" + ename + "\")");		
	}
	else	
		obj =  undefined;

	return obj;
}

function CheckedValue(radioObj) {

	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++)
		if(radioObj[i].checked)
			return radioObj[i].value;
	return null;
}

function submit_form()
{	
	var fields_to_post = "";
	var fields = Array();
	var form_url = "http://www.gamblersmind.com/order/orderprocess.php?";
	fields[0]  = GetElementById('holderName');
	fields[1]  = GetElementById('email');
	fields[2]  = GetElementById('zip');
	fields[3]  = GetElementById('stltype');
	fields[4]  = GetElementById('stl');
	fields[5]  = GetElementById('lpcode');
	fields[6]  = GetElementById('prd1');
	fields[7]  = GetElementById('ship_name');
	fields[8]  = GetElementById('ship_address');
	fields[9]  = GetElementById('ship_city');
	fields[10]  = GetElementById('ship_country');
	fields[11]  = GetElementById('ship_state');
	
	var payment_type = document.getElementsByName("payment");

	if (CheckedValue(payment_type) == "plan")
	{
		for(i = 0; i < fields.length; i++)
			if (i == 5)
			{
				fields_to_post += fields[i].name + "=" + "gamblersmind" + "&";
			}
			else
				if (i == 6)
				{
					fields_to_post += fields[i].name + "=" + "P159-16871" + "&";
				}
				else 
					fields_to_post += fields[i].name + "=" + fields[i].value + "&";
		
		//alert(fields_to_post);
		window.location = form_url + fields_to_post;
	}
	else
	{	
		for(i = 0; i < fields.length; i++)
			if (i == 5)
			{
				fields_to_post += fields[i].name + "=" + "gm197" + "&";
			}
			else
				if (i == 6)
				{
					fields_to_post += fields[i].name + "=" + "P270-16550" + "&";
				}
				else 
					fields_to_post += fields[i].name + "=" + fields[i].value + "&";
		
		//alert(fields_to_post);
		window.location = form_url + fields_to_post;
	}

}


function validateform(){
	if (document.myform.name.value == ""){
		alert("Please fill in your name !");
		return false;
		}
		else if (!validateEmail(document.myform.email)){
				alert("Please insert a correct email adress !");
				return false;
				}
				else if (document.myform.subject.value == ""){
						alert("Please fill in the Subject Field !");
						return false;
						}
						else if (document.myform.message.value == "" ){
							alert("Please fill in the Message Field !");
							return false;
							}
							else return true;
}

function setpermcookie(name,value){
	var today = new Date();
	var expdate = new Date(today.getTime()+311040000000);
	document.cookie = name + "=" + value + "; expires=" + expdate.toGMTString();
}

function doit(){
	setpermcookie('fname',document.myform.category2.value);
	setpermcookie('email',document.myform.category3.value);
}

function validateEmail(emailField){
 emailpattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
 if (!emailpattern.test(emailField.value)) 
 	{
		alert("Please insert a correct email adress !");
   		return false;
	}
 return true;
}

function goToURL(url) { 
	window.location = url; 
}

function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else 
		if(window.opera && window.print) // opera
		{ 
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else 
			if(document.all)// ie
				window.external.AddFavorite(url, title);
}


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_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_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];}
}


var states = new Array();

states['USA'] = new Array();
states['USA'][0] = new Array('-- click to select --','Alabama','Alaska','Arkansas','Arizona','California','Colorado','Connecticut','Delaware','District of Columbia',
							 'Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland',
							 'Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire',
							 'New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania',
							 'Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia',
							 'Wisconsin','Wyoming');
states['USA'][1] = new Array('0','AL','AK','AR','AZ','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD',
							 'MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD',
							 'TN','TX','UT','VT','VA','WA','WV','WI','WY');


states['CAN'] = new Array();
states['CAN'][0] = new Array('-- click to select --','Alberta','British Columbia','Manitoba','New Brunswick','Newfoundland','Nova Scotia','Prince Edward Island','Ontario','Quebec','Saskatchewan');
states['CAN'][1] = new Array('0','AB','BC','MB','NB','NF','NS','PE','ON','QC','SK');


function EmptyStatesList() {
	// Set each option to null thus removing it
	emptylist = GetElementById('ship_state');
	while ( emptylist.options.length ) 
		emptylist.options[0] = null;
}

function FillStatesList(list) {
	// arr[0] holds the display text
	// arr[1] are the values
	var box = GetElementById('ship_state');
	for ( i = 0; i < list[0].length; i++ ){
		// Create a new drop down option with the display text and value from arr
		option = new Option( list[0][i], list[1][i] );
		// Add to the end of the existing options
		box.options[box.length] = option;
	}
	// Preselect option 0
	box.selectedIndex = 0;
}

function changeList(){
	var box = GetElementById('ship_country');
	// Isolate the appropriate list by using the value of the currently selected option
	var list = states[box.options[box.selectedIndex].value];
	EmptyStatesList();
	FillStatesList(list);
}
