// JavaScript Document
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.id; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function GetXmlHttpObject()
{
	var xmlHttp = null;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

function checkout(boolean)
{
	if (boolean)
	{
		if (confirm("You have one or more products or services that we do not ship out.\n                           Do you want to continue?"))
		{
			window.location = 'checkout.php';
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{	
		window.location = 'checkout.php';
		return true;
	}
}


function clear_notification()
{
	var container = document.getElementById("notification");
	container.style.visibility = 'hidden';
	container.style.display = 'none';
}
function show_notification()
{
	var container = document.getElementById("notification");
	container.style.visibility = 'visible';
	container.style.display = 'block';
}

function resetSession()
{
	window.location = 'step1.php?reset';
}

function validate(password, passwordconfirm, accountemail)
{
	var passed;
	
	MM_validateForm('accountemail','','RisEmail','password','','R','passwordconfirm','','R');

	if (password == passwordconfirm)
	{
		if (accountemail)
		{
			//MM_validateForm('password','','R','passwordconfirm','','R');
			passed = document.MM_returnValue;
		}
	
		if (document.MM_returnValue)
		{
			passed = true;
		}
	}
	else
	{
		alert("The following error(s) occurred:\n- Passwords do not match.");
		passed = false;
	}

	if(passed)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function enable_add()
{

	var button = document.getElementById("add_button");
	button.disabled = false;

}



function validate_options()
{
	var group = document.product_form.designoptions;
	
	if (!group.checked)
	{
		bool = false;
	}
	else
	{
		return true;
	}
	
	for(i = 0; i < group.length; i++)
	{
		if(!group[i].checked)
		{
			bool = false;
		}
		else
		{
			return true;
		}
	}
	
	if (!bool)
	{
		alert("You must choose one of the design options.");
		return false;
	}	
}
	
function validate_continue()
{
	var checkbox = document.getElementById("terms");
	if(checkbox.checked == false)
	{
		alert("You must accept Terms and Conditions to continue...")
		return false;
	}
	else
	{
		return true;
	}
	
}

function cancel_order(order_id)
{
	if(confirm("Are you sure you want to cancel this order?"))
	{
		window.location = 'actions.php?action=cancel_order&order_id=' + order_id;
	}
	else
	{
		return false;
	}	
}	

function reorder(array)
{
	window.location = 'actions.php?action=reorder&items=' + array;
}

function session_logout()
{
	window.location = 'actions.php?action=session_logout';
}

function check_product(id, name)
{
	var template = name.indexOf("Design");
	var design = name.indexOf("template");
		
	if (template != -1 || design != -1)
	{
		if(confirm("This product is associated other products in your shopping cart."))
		{
			window.location = "actions.php?action=delete_from_cart&id=" + id;
		}
	}
	else
	{
		window.location = "actions.php?action=delete_from_cart&id=" + id;
	}
}

function show_event_details(event_id)
{
	var clientHeight = document.body.clientHeight;
	var clientWidth = document.body.clientWidth;
	
	var top = (clientHeight / 2) - 125;
	var left = (clientWidth / 2) - 225;
	
	var win = document.getElementById('window');
	
	win.style.top = top + 'px';
	win.style.left = left + 'px';
	win.style.display = 'block';
	win.style.visibility = 'visible';
	
	load_event_details(event_id);
}
function ajax(update,parameters)
{
	request = GetXmlHttpObject();
	
	if (request == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var url = "actions.php";
	url = url + "?" + parameters;
		
	request.open("GET",url,true);
	
	request.onreadystatechange = function() 
	{ 
		if (request.readyState == 4)
		{ 
			document.getElementById(update).innerHTML = request.responseText;
		}
	}
		
	request.send(null);
}
function load_event_details(event_id)
{
	ajax("window", 'action=load_event_details&event_id=' + event_id);
}

/*function sameasbilling()
{
	var name document.getElementById("b_name");
	var initial document.getElementById("b_initial");
	var lastname document.getElementById("b_lastname");
	var company document.getElementById("b_company");
	var address document.getElementById("b_address");
	var address2 document.getElementById("b_address2");
	var city document.getElementById("b_city");
	var state document.getElementById("b_state");
	var country document.getElementById("b_country");
	var zipcode document.getElementById("b_zipcode");
	var phone document.getElementById("b_phone");
	var email document.getElementById("b_email");
}*/