var http 				= createRequestObject();
if (navigator.appVersion.indexOf("MSIE") != -1)
{
	var version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (version < 8)
	{
		document.write('<span class="warning" align="center">Warning: Your browser is not fully supported, certain functions may not work as expected. Please upgrade to the latest Internet Explorer or Firefox version (free on internet)</span>');
	}
}
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

function go_to(step_no)
{
	var step_to_show;
	var titles = Array("-","Client information","Neck Length","Neck Circumference","Bone Structure","Horizontal body shape","Vertical body shape","Shoulders type","Face shape","Prominent features");
	for (i=1; i<10; i++)
	{
		step_to_show	= "step"+i;
		if (i == step_no)
		{
			document.getElementById("StepTitle").innerHTML			= titles[i];
			document.getElementById(step_to_show).style.display	= "block";
		}
		else
			document.getElementById(step_to_show).style.display	= "none";
	}
}

function go_to_update(step_no)
{
	var step_to_show;
	var titles = Array("-","Client information","Neck Circumference","Horizontal body shape","Face shape","Prominent features");
	for (i=1; i<6; i++)
	{
		step_to_show	= "step"+i;
		if (i == step_no)
		{
			document.getElementById("StepTitle").innerHTML			= titles[i];
			document.getElementById(step_to_show).style.display	= "block";
		}
		else
			document.getElementById(step_to_show).style.display	= "none";
	}
}

function go_to_sub(step_no)
{
	var step_to_show;
	for (i=1; i<5; i++)
	{
		step_to_show	= "step9_"+i;
		if (i == step_no)
			document.getElementById(step_to_show).style.display	= "block";
		else
			document.getElementById(step_to_show).style.display	= "none";
	}
}

function check_form(check,return_me)
{
	var	errors					= '';
	var stepToShow			= '';

	if (check.FirstName.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors					= errors + '<br>- Enter your First name in step 1';
	}
	if (check.LastName.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Last name in step 1';
	}
	if (check.StreetAddress.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Street Address in step 1';
	}
	if (check.City.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your City/Town in step 1';
	}
	if (check.Client_Country.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Country in step 1';
	}
	if (check.Postcode.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Postcode in step 1';
	}
	if (validatePhone(check.Phone.value) == false)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter a valid Phone number in step 1.';
	}
	if (check.email.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Email address in step 1';
	}
	else
	{
		if (checkemail(check.email.value) != true)
		{
			if (stepToShow == '')
				stepToShow		= 1;
			errors	= errors + '<br>- Enter a valid Email address in step 1';
		}
	}
	if (check.Ht_pick.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Height in step 1';
	}
	if (check.Wt_pick.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Weight in step 1';
	}
	if (check.Age.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Age in step 1';
	}
	if (check.BraCup.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Bra Cup Size in step 1';
	}
	if (getCheckedValue(check.NL_pick) == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Select your Neck Length in step 2';
	}
	if (getCheckedValue(check.Neck_Type) == "")
	{
		if (stepToShow == '')
			stepToShow		= 3;
		errors		= errors + '<br>- Select your Neck Thickness in step 3';
	}
	if (getCheckedValue(check.BS_pick) == "")
	{
		if (stepToShow == '')
			stepToShow		= 4;
		errors		= errors + '<br>- Select your Bone Structure in step 4';
	}
	if (getCheckedValue(check.HorT) == "")
	{
		if (stepToShow == '')
			stepToShow		= 5;
		errors		= errors + '<br>- Select your Horizontal Body Shape in step 5';
	}
	if (getCheckedValue(check.VerT) == "")
	{
		if (stepToShow == '')
			stepToShow		= 6;
		errors		= errors + '<br>- Select your Vertical Body Shape in step 6';
	}
	if (getCheckedValue(check.ShldT) == "")
	{
		if (stepToShow == '')
			stepToShow		= 7;
		errors		= errors + '<br>- Select your Shoulders Type in step 7';
	}
	if (getCheckedValue(check.FaceS) == "")
	{
		if (stepToShow == '')
			stepToShow		= 8;
		errors			= errors + '<br>- Select your Face Shape in step 8';
	}

	if ((check.NL_pick.value == 'Long') && (check.Neck_Type.value == 'Thick'))
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors			= errors + '<br>- Long and Thick Neck is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if ((check.NL_pick.value == 'Short') && (check.Neck_Type.value == 'Thin'))
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Short and Thin Neck is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if ((getCheckedValue(check.HorT) == 'Oval' || getCheckedValue(check.HorT) == 'Diamond') && check.Wt_pick.value != "Substancially Overweight")
	{
		if (stepToShow == '')
			stepToShow		= 5;
		errors					= errors + '<br>- Oval or Diamond Horizontal body shape is only possible with Substancially Overweight weight selection.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if ((getCheckedValue(check.HorT) == 'Rectangle') && (getCheckedValue(check.ShldT) == 'Average Tapered'))
	{
		if (stepToShow == '')
			stepToShow		= 7;
		errors		= errors + '<br>- Rectangle Body Type and Average Tapered Shoulders is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if ((getCheckedValue(check.HorT) == 'Rectangle') && (getCheckedValue(check.ShldT) == 'Average Sloped'))
	{
		if (stepToShow == '')
			stepToShow		= 7;
		errors		= errors + '<br>- Rectangle Body Type and Average Sloped Shoulders is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}

	if ((getCheckedValue(check.HorT) == 'Triangle') && (check.ShldT.value == 'Broad Square'))
	{
		if (stepToShow == '')
			stepToShow		= 7;
		errors		= errors + '<br>- Triangle Horizontal Body Shape and Broad Squuare Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if ((getCheckedValue(check.HorT) == 'Triangle') && (check.ShldT.value == 'Broad Tapered'))
	{
		if (stepToShow == '')
			stepToShow		= 7;
		errors		= errors + '<br>- Triangle Horizontal Body Shape and Broad Tapered Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}

	if (getCheckedValue(check.none3) == "")
	{
		if (check.Heavy_Legs.checked)
		{
			if (check.Thin_Legs.checked)
			{
				if (stepToShow == '')
					stepToShow		= 9;
				errors			= errors + '<br>- Heavy Lower Legs and Thin Legs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
			}
		}
	}
	if (getCheckedValue(check.none3) == "")
	{
		if (check.Saddle_Bags.checked)
		{
			if (check.Thick_Thighs.checked)
			{
				if (stepToShow == '')
					stepToShow		= 9;
				errors			= errors + '<br>- Saddle Bags and Thick Thighs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
			}
		}
	}
	if (getCheckedValue(check.none1) == "")
	{
		if ((check.Thin_Arms.checked == true) && (check.Heavy_Arms.checked == true))
		{
			if (stepToShow == '')
				stepToShow		= 9;
			errors					= errors + '<br>- Heavy Arms and Aged Arms is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
		}
	}
	if (getCheckedValue(check.none2) == "")
	{
		if ((check.Large_Bottom.checked == true) && (check.Flat_Bottom.checked == true))
		{
			if (stepToShow == '')
				stepToShow		= 9;
			errors					= errors + '<br>- Flat Bottom and Large Bottom is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
		}
	}
	if (getCheckedValue(check.none3) == "")
	{
		if ((check.Thin_Legs.checked == true) && (check.Thick_Thighs.checked == true))
		{
			if (stepToShow == '')
				stepToShow		= 9;
			errors					= errors + '<br>- Thin Legs and Thick Thighs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
		}
	}

	if (errors != '')
	{
		go_to(stepToShow);
		$.prompt("Please correct the following errors to continue with the checkout:" + errors);
		if (return_me == '1')
			return false;
	}
	else
		check_Email(check.email.value);
}

function check_update_form(check,updated)
{
	var	errors					= '';
	var stepToShow			= '';

	if (check.StreetAddress.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Street Address in step 1';
	}
	if (check.City.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your City/Town in step 1';
	}
	if (check.Client_Country.value < 1)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Country in step 1';
	}
	if (check.Postcode.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Postcode in step 1';
	}
	if (validatePhone(check.Phone.value) == false)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter a valid Phone number in step 1.';
	}
	if (check.email.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Email address in step 1';
	}
	else
	{
		if (checkemail(check.email.value) != true)
		{
			if (stepToShow == '')
				stepToShow		= 1;
			errors	= errors + '<br>- Enter a valid Email address in step 1';
		}
	}

	if (check.Wt_pick.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Weight in step 1';
	}
	if (check.Age.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Age in step 1';
	}
	if (check.BraCup.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Bra Cup Size in step 1';
	}
	if (getCheckedValue(check.Neck_Type) == "")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Neck Thickness in step 2';
	}
	if (getCheckedValue(check.HorT) == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Select your Horizontal Body Shape in step 3';
	}
	if (getCheckedValue(check.FaceS) == "")
	{
		if (stepToShow == '')
			stepToShow		= 3;
		errors		= errors + '<br>- Select your Face Shape in step 4';
	}

	if ((check.NL_pick.value == 'Long') && (check.Neck_Type.value == 'Thick'))
		errors		= errors + '<br>- Long and Thick Neck is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if ((check.NL_pick.value == 'Short') && (check.Neck_Type.value == 'Thin'))
		errors		= errors + '<br>- Short and Thin Neck is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if ((getCheckedValue(check.HorT) == 'Rectangle') && (check.ShldT.value == 'Average Tapered'))
		errors		= errors + '<br>- Rectangle Body Type and Average Tapered Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if ((getCheckedValue(check.HorT) == 'Rectangle') && (check.ShldT.value == 'Average Sloped'))
		errors		= errors + '<br>- Rectangle Body Type and Average Sloped Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if ((getCheckedValue(check.HorT) == 'Triangle') && (check.ShldT.value == 'Broad Square'))
		errors		= errors + '<br>- Triangle Horizontal Body Shape and Broad Squuare Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if ((getCheckedValue(check.HorT) == 'Triangle') && (check.ShldT.value == 'Broad Tapered'))
		errors		= errors + '<br>- Triangle Horizontal Body Shape and Broad Tapered Shoulders are not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	if (getCheckedValue(check.none1) == "")
	{
		if ((check.Thin_Arms.checked == true) && (check.Heavy_Arms.checked == true))
			errors		= errors + '<br>- Heavy Arms and Aged Arms is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if (getCheckedValue(check.none2) == "")
	{
		if ((check.Large_Bottom.checked == true) && (check.Flat_Bottom.checked == true))
			errors		= errors + '<br>- Flat Bottom and Large Bottom is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if (getCheckedValue(check.none3) == "")
	{
		if ((check.Thin_Legs.checked == true) && (check.Thick_Thighs.checked == true))
			errors		= errors + '<br>- Thin Legs and Thick Thighs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
	}
	if (getCheckedValue(check.none3) == "")
	{
		if (check.Heavy_Legs.checked)
		{
			if (check.Thin_Legs.checked)
				errors			= errors + '<br>- Heavy Lower Legs and Thin Legs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
		}
	}
	if (getCheckedValue(check.none3) == "")
	{
		if (check.Saddle_Bags.checked)
		{
			if (check.Thick_Thighs.checked)
				errors			= errors + '<br>- Saddle Bags and Thick Thighs is not a valid combination.<br>&nbsp;&nbsp;&nbsp;&nbsp;Please change one of these selections';
		}
	}

	if (errors != '')
		$.prompt("Please correct the following errors to continue with the checkout:" + errors);
	else
		document.data_form.submit();
}

function checkemail(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		return true;
	else
		return false;
}

function getCheckedValue(radioObj)
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++)
	{
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function get_discount(coupon_code)
{
	http.open('get', '/get_discount.php?coupon_code='+coupon_code);
  http.onreadystatechange = handleDiscountResponse;
  http.send(null);
}

function handleDiscountResponse()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if (response != "")
		{
			document.getElementById('your_price').innerHTML = "Your Style Solutions Price: " + response;
		}
	}
}

function activate_me()
{
	var license_key	= document.getElementById('license_key').value;
	http.open('get', '/check_key.php?license_key='+license_key);
  http.onreadystatechange = handleLicenseResponse;
  http.send(null);
}

function handleLicenseResponse()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if (response != 'ok')
			$.prompt("You have entered an invalid license key.");
		else
			document.activate.submit();
	}
}

function LogIn()
{
	var username	= document.getElementById('username-field').value;
	var password	= document.getElementById('password-field').value;
	if (document.getElementById('remember_me').checked)
		var remember= 1;
	else
		var remember= 0;
	http.open('get', '/check_user.php?username='+username+'&password='+password+'&remember='+remember);
  http.onreadystatechange = handleLoginResponse;
  http.send(null);
}

function handleLoginResponse()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if (response == 'error')
			$.prompt("You have entered an invalid username or password. Please try again.");
		else
			window.location	= response;
//
//			window.location	= response;
	}
}

function LogInPage()
{
	var username	= document.getElementById('Paymentusername').value;
	var password	= document.getElementById('Paymentpassword').value;
	var remember	= 0;
	http.open('get', '/check_user.php?username='+username+'&password='+password+'&remember='+remember);
  http.onreadystatechange = handleLogInPageResponse;
  http.send(null);
}

function handleLogInPageResponse()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if (response == 'error')
			$.prompt("You have entered an invalid username or password. Please try again.");
		else
			window.location	= response;
	}
}

function addToFavorites(my_favorites)
{
	//full list submited
	http.open('get', '/add_to_favorites.php?favorites='+my_favorites);
  http.onreadystatechange = handleFavoritesResponse;
  http.send(null);
}

function handleFavoritesResponse()
{
	//Empty
}

function showDescription(cat)
{
	http.open('get', '/getGarmentDescription.php?cat='+cat);
  http.onreadystatechange = handleDescriptionResponse;
  http.send(null);
}
function handleDescriptionResponse()
{
	if(http.readyState == 4)
	{
		document.getElementById('overview_loading').style.display = "none";

		var Overviews																					= http.responseText.split('|');

		if (Overviews[4] == "m12_1")
		{
			document.getElementById('OverviewTable').style.display 	= "none";
			document.getElementById('Paragraphs').style.display 		= "block";
		}
		else
		{
			document.getElementById('OverviewTable').style.display 	= "block";
			document.getElementById('Paragraphs').style.display 		= "none";
		}

		document.getElementById('PersonalTitle').innerHTML		= Overviews[0];
		document.getElementById('PersonalOverview').innerHTML	= Overviews[1];
		document.getElementById('GeneralTitle').innerHTML			= Overviews[2];
		document.getElementById('GeneralOverview').innerHTML	= Overviews[3];
	}
	if(http.readyState == 1)
	{
		document.getElementById('OverviewTable').style.display = "none";
		document.getElementById('overview_loading').style.display = "block";
	}
}

function check_Email(email)
{
	http.open('get', '/check_registered_mail.php?email='+email);
  http.onreadystatechange = handlecheck_EmailResponse;
  http.send(null);
}

function handlecheck_EmailResponse()
{
	if(http.readyState == 4)
	{
		if (http.responseText == "error")
			$.prompt("A user with the given email address is already registered.<br>If you have forgotten your password please use the link Retrive Password in the left menu.");
		else
			document.data_form.submit();
	}
}

function setMerchatType(doSignUp)
{
	http.open('get', '/setMerchatType.php?doSignUp='+doSignUp);
  http.onreadystatechange = handlesetMerchatTypeResponse;
  http.send(null);
}

function handlesetMerchatTypeResponse()
{
	if(http.readyState == 4)
	{
		temp 							= http.responseText.split('|');

		if (temp[0] == "error")
		{
			if (temp[2] == "doSignUp")
			{
				checkSignUp(document.data_form);
			}
			else
			{
				$.prompt("You have entered an invalid authorisation code");
				document.getElementById('ResellerType').innerHTML	= temp[1];
				document.getElementById('Email').readOnly					= false;
			}
		}
		else
		{
			if (temp[0] != "")
			{
				var email					= temp[0];
				var merchant_type	= temp[1];
				document.getElementById('Email').readOnly					= false;
				document.getElementById('Email').value						= email;
				document.getElementById('Email').readOnly					= true;
				document.getElementById('ResellerType').innerHTML	= merchant_type;

				if (temp[2] == "doSignUp")
					checkSignUp(document.data_form);
			}
		}
	}
}

function checkSignUp(check)
{
	var	errors					= '';

	if (check.FirstName.value.length < 2)
		errors		= errors + '<br>- Enter your First Name';
	if (check.LastName.value.length < 2)
		errors		= errors + '<br>- Enter your Last Name';
	if (check.StreetAddress.value.length < 2)
		errors		= errors + '<br>- Enter your Street Address';
	if (check.City.value.length < 2)
		errors		= errors + '<br>- Enter your City/Town';
	if (check.Client_Country.value == "-")
		errors		= errors + '<br>- Select your Country';
	if (validatePhone(check.Phone.value) == false)
		errors		= errors + '<br>- Enter a valid Phone number.';
	if (check.Email.value.length < 2)
		errors		= errors + '<br>- Enter your Email address';
	else
	{
		if (checkemail(check.Email.value) != true)
			errors	= errors + '<br>- Enter a valid Email address';
	}
	if (check.paypal.value.length < 2)
		errors		= errors + '<br>- Enter your Email address for the paypal account';
	else
	{
		if (checkemail(check.paypal.value) != true)
			errors	= errors + '<br>- Enter a valid Email address for the paypal account';
	}

	if (errors != '')
		$.prompt("Please correct the following errors to continue with the sign up:" + errors);
	else
		checkMerchantEmail(check.Email.value);
}

function checkAskQuestion(check)
{
	var	errors					= '';

	if (check.Name.value.length < 2)
		errors		= errors + '<br>- Enter your Name';
	if (check.Email.value.length < 2)
		errors		= errors + '<br>- Enter your Email address';
	else
	{
		if (checkemail(check.Email.value) != true)
			errors	= errors + '<br>- Enter a valid Email address';
	}
	if (check.Enquery.value.length < 2)
		errors		= errors + '<br>- Enter your Enquery';

	if (errors != '')
		$.prompt("Please correct the following errors to send us a question:" + errors);
	else
		check.submit();
}

function checkMerchantEmail(email)
{
	http.open('get', '/checkMerchantEmail.php?email='+email);
  http.onreadystatechange = handlecheckMerchantEmailResponse;
  http.send(null);
}

function handlecheckMerchantEmailResponse()
{
	if(http.readyState == 4)
	{
		if (http.responseText == "error")
			$.prompt("A user with the given email address is already registered.<br>If you have forgotten your password please contact us for password retrieval.");
		else
			document.data_form.submit();
	}
}
function submit_form(f_action, cart_id)
{
	document.getElementById("submit_type").value			= f_action;
	document.getElementById("cart_id").value					= cart_id;
	document.cart.submit();
}
function copy_form_values(radio_val)
{
	if (radio_val == "yes")
	{
		document.getElementById("show_table").style.display	= "none";
	}
	else
	{
		document.getElementById("show_table").style.display	= "inline";
		document.getElementById("sfirst_name").value				= '';
		document.getElementById("slast_name").value					= '';
		document.getElementById("semail").value							= '';
		document.getElementById("saddress").value						= '';
		document.getElementById("ssuburb").value						= '';
		document.getElementById("spostcode").value					= '';
		document.getElementById("sphone").value							= '';
		document.getElementById("scountry").selectedIndex		= 0;
		document.getElementById("sstate").selectedIndex			= 0;
		document.getElementById("sstate").value							= '';
	}
}

function RetrievePass()
{
	var txt = 'Forgot your password?:<br /><br /><span style="font-weight:normal;">Enter your e-mail address bellow and we will send you a link where you can reset your password.</span><br /><br /><input type="text" id="emailAddress" name="emailAddress" value="" style="width:280px;" />';

	function mysubmitfunc(v,m,f){
      an = m.children('#emailAddress');
      if(f.emailAddress == ""){
            an.css("border","solid #ff0000 1px");
            return false;
      }
			http.open('get', '/SendPassReset.php?email='+f.emailAddress);
			http.onreadystatechange = handlecheckResetResponse;
			http.send(null);
      return true;
	}

	$.prompt(txt,{
      submit: mysubmitfunc,
      buttons: { Ok:true }
	});
}

function handlecheckResetResponse()
{
	if(http.readyState == 4)
	{
		if (http.responseText == "error")
			$.prompt("We haven't found your email address in our database, Please try again.");
		else
			$.prompt("The link has been sent to the given email address.<br />Please follow the instructions from the mail to reset your password.");
	}
}
function updateRegions(country,text_width)
{
	http.open('get', '/getRegions.php?country='+country+'&text_width='+text_width);
  http.onreadystatechange = handleupdateRegionsResponse;
  http.send(null);
}

function handleupdateRegionsResponse()
{
	if(http.readyState == 4)
		document.getElementById("RegionsHolder").innerHTML = http.responseText;
//	if(http.readyState == 1)
//		document.getElementById("RegionsHolder").innerHTML = '<img src="/images/ajax-loader.gif" alt="Updating..." style="padding-left:15px; padding-top:5px;">';
}


function updateBillingStates()
{
	var country			= document.getElementById("country").value;
	http.open('get', '/getCheckoutRegions.php?country='+country+'&field=state');
  http.onreadystatechange = handleupdateBillingStatesResponse;
  http.send(null);
}

function handleupdateBillingStatesResponse()
{
	if(http.readyState == 4)
		document.getElementById("RegionsHolder").innerHTML = http.responseText;
}

function updateShippingStates()
{
	var country			= document.getElementById("scountry").value;
	http.open('get', '/getCheckoutRegions.php?country='+country+'&field=sstate');
  http.onreadystatechange = handleupdateShippingStatesResponse;
  http.send(null);
}

function handleupdateShippingStatesResponse()
{
	if(http.readyState == 4)
		document.getElementById("SRegionsHolder").innerHTML = http.responseText;
}

function  validateNumeric(strValue)
{
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
  return objRegExp.test(strValue);
}
function  validatePhone(strValue)
{
//  var objRegExp  =  /[0-9\.\-\+\/ ]$/;
//  return objRegExp.test(strValue);
	return true;
}
function popitup(url) {
	newwindow=window.open(url,'name','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=640,height=498,left = 320,top = 263');
	if (window.focus) {newwindow.focus()}
	return false;
}

function check_help_form(check,return_me)
{
	var	errors					= '';
	var stepToShow			= '';

	if (check.FirstName.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors					= errors + '<br>- Enter your First name in step 1';
	}
	if (check.LastName.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Last name in step 1';
	}
	if (check.StreetAddress.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Street Address in step 1';
	}
	if (check.City.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your City/Town in step 1';
	}
	if (check.Client_Country.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Country in step 1';
	}
	if (check.Postcode.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Postcode in step 1';
	}
	if (validatePhone(check.Phone.value) == false)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter a valid Phone number in step 1.';
	}
	if (check.email.value.length < 2)
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Enter your Email address in step 1';
	}
	else
	{
		if (checkemail(check.email.value) != true)
		{
			if (stepToShow == '')
				stepToShow		= 1;
			errors	= errors + '<br>- Enter a valid Email address in step 1';
		}
	}
	if (check.Age.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Age in step 1';
	}
	if (check.BraCup.value == "-")
	{
		if (stepToShow == '')
			stepToShow		= 1;
		errors		= errors + '<br>- Select your Bra Cup Size in step 1';
	}

	if (check.head_and_neck.value == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Please select a head and neck photo in step 2';
	}
	if (check.full_length_front.value == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Please select a full length photo: front in step 2';
	}
	if (check.full_length_back_1.value == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Please select a full Length photo: back 1 in step 2';
	}
	if (check.full_length_back_2.value == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Full Length photo: back 2 in step 2';
	}
	if (check.full_length_side.value == "")
	{
		if (stepToShow == '')
			stepToShow		= 2;
		errors		= errors + '<br>- Full Length photo: side in step 2';
	}

	if (errors != '')
	{
		help_go_to(stepToShow);
		$.prompt("Please correct the following errors to continue with the checkout:" + errors);
	}
	else
	{
		var step_to_show;
		for (i=1; i<4; i++)
		{
			step_to_show	= "step"+i;
			document.getElementById(step_to_show).style.display	= "none";
		}
		$.fn.colorbox({width:"50%", inline:true, href:"#popup"});
	}
}

function check_Help_Email(email)
{
	http.open('get', '/check_registered_mail.php?email='+email);
  http.onreadystatechange = handlecheck_Help_EmailResponse;
  http.send(null);
}

function handlecheck_Help_EmailResponse()
{
	if(http.readyState == 4)
	{
		if (http.responseText == "error")
			$.prompt("A user with the given email address is already registered.<br>If you have forgotten your password please use the link Retrive Password in the left menu.");
		else
		{
			var step_to_show;
			for (i=1; i<4; i++)
			{
				step_to_show	= "step"+i;
				document.getElementById(step_to_show).style.display	= "none";
			}
			$.fn.colorbox({width:"50%", inline:true, href:"#popup"});
		}
	}
}
function help_go_to(step_no)
{
	var step_to_show;
	for (i=1; i<4; i++)
	{
		step_to_show	= "step"+i;
		if (i == step_no)
			document.getElementById(step_to_show).style.display	= "block";
		else
			document.getElementById(step_to_show).style.display	= "none";
	}
}

function submit_help(addStyleGuide)
{
	document.getElementById("addstyleguide").value					= addStyleGuide;
	$.fn.colorbox.close();
	document.getElementById("main_container").style.display	= "inline";
	UberUpload.linkUpload();
}

function goToHelp()
{
	document.data_form.action		= '/saveHelpData.php';
	document.data_form.onsubmit	= '';
	document.data_form.submit();
}

function help_go_to_sub(step_no)
{
	var step_to_show;
	for (i=1; i<5; i++)
	{
		step_to_show	= "step6_"+i;
		if (i == step_no)
			document.getElementById(step_to_show).style.display	= "block";
		else
			document.getElementById(step_to_show).style.display	= "none";
	}
}

function signUp()
{
	var errors = '';
	if (document.getElementById("newsletter-field").value.length < 2)
		errors		= errors + '<br>- Enter your Email';
	else
	{
		if (checkemail(document.getElementById("newsletter-field").value) != true)
			errors	= errors + '<br>- Enter a valid Email address';
	}

	if (errors != '')
		$.prompt("Please correct the following errors to continue:" + errors);
	else
	{
		http.open('get', '/NewsletterSignup.php?email='+document.getElementById("newsletter-field").value);
	  http.onreadystatechange = handlesignUpResponse;
	  http.send(null);
	}
}

function handlesignUpResponse()
{
	if(http.readyState == 4)
		$.prompt(http.responseText);
}

function CheckFrienForm()
{
	var errors 	= '';
	var check		= document.tellAfriend;
	if (check.YourName.value.length < 2)
		errors		= errors + '<br>- Enter your Name';
	if (check.FriendsFirstName.value.length < 2)
		errors		= errors + '<br>- Enter your Friends First Name';
	if (check.FriendsEmail.value.length < 2)
		errors		= errors + '<br>- Enter your Friends Email';
	else
	{
		if (checkemail(check.FriendsEmail.value) != true)
			errors	= errors + '<br>- Enter a valid Email address';
	}
	if (errors != '')
		$.prompt("Please correct the following errors to continue:" + errors);
	else
	{
		check.submit();
	}

}