$().ready(function() 
{
	$("#frmRegion").validate(
	{
		errorLabelContainer: $("#diverror"),
		rules: 
		{
			region: {required: true}
		},
		messages: 
		{
			region: "Please choose a region<br/>"
		}
	});
	$("#frmOrder").validate(
	{
		errorLabelContainer: $("#diverror"),
		rules: 
		{
			name: "required",
			surname: "required",
			city: "required",
			phone_day: "required",
			phone_eve: "required",
			mobile: "required",
			postal: "required",
			code: "required",
			state: "required",
			email: {
				required: true,
				email: true
			},
			region: {required: true},
			best_time: {required: true},
			country: {required: true},
			method : "required",
			card_type : "required",
			card_name : "required",
			card_number : {   required: true,  creditcard: true  },
			exp_date: {  required: true }
			//cvc : "required"
		},
		messages: 
		{
			name: "Please enter your name<br/>",
			surname: "Please enter your surname<br/>",
			email: "Please enter a valid email<br/>",
			region: "Please choose a region<br/>",
			city: "Please enter your city<br/>",
			phone_day: "Please enter your Phone (day)<br/>",
			phone_eve: "Please enter your Phone (eve)<br/>",
			mobile: "Please enter your mobile nr.<br/>",
			best_time: "Please choose a best time<br/>",
			country: "Please choose a country<br/>",
			postal: "Please enter your postal address<br/>",
			code: "Please enter your postal code<br/>",
			state: "Please enter your state/province<br/>",
			method : "Please choose a payment type.<br/>",
			card_type : "Please choose a card type.<br/>",
			card_name : "Please enter a card holder name.<br/>",
			card_number : "Please enter a valid card number.<br/>",
			//cvc : "Please enter your cvc code.<br/>",
			exp_date : "Please type in an expiry date.<br/>"
			//cvc : "Please enter your cvc code.<br/>"
		}
	});
	$("#frmRegister").validate(
	{
		errorLabelContainer: $("#diverror"),
		rules: 
		{
			name: "required",
			surname: "required",
			city: "required",
			phone_day: "required",
			phone_eve: "required",

			postal: "required",
			code: "required",
			state: "required",
			email: {
				required: true,
				email: true
			},
			region: {required: true},
			best_time: {required: true},
			country: {required: true},
			password: {
				required: true,
				minlength: 5
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#password"
			},
			mobile: "required"
		},
		messages: 
		{
			name: "Please enter your name<br/>",
			surname: "Please enter your surname<br/>",
			email: "Please enter a valid email<br/>",
			region: "Please choose a region<br/>",
			city: "Please enter your city<br/>",
			phone_day: "Please enter your Phone (day)<br/>",
			phone_eve: "Please enter your Phone (eve)<br/>",
			best_time: "Please choose a best time<br/>",
			country: "Please choose a country<br/>",
			postal: "Please enter your postal address<br/>",
			code: "Please enter your postal code<br/>",
			state: "Please enter your state/province<br/>",
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long"
			},
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				equalTo: "Please enter the same password as above"
			},

			mobile: "Please enter your mobile nr.<br/>"
		}
	});
	$("#phone_day").mask("(9)99 999 9999");
	$("#phone_eve").mask("(9)99 999 9999");
	$("#mobile").mask("(9)99 999 9999");
});
function selectPack(checkb)
{
	if($('input[@name='+checkb+']:checked').size() != 0)
	{
		//make all other packs not checkable
		$(".packdisplay").addClass("grayedout");
		$("#pack_"+checkb).removeClass("grayedout");
		$(".packcheck").attr('disabled', true);
		$("#c"+checkb).removeAttr('disabled');		
	}
	else 
	{
		//make all other packs checkable
		$(".packdisplay").removeClass("grayedout");
		$(".packcheck").removeAttr('disabled');		
	}
}
function credShow()
{

	if(document.getElementById("method").value == "Credit Card" || document.getElementById("method").value == "Credit Card")
	{
		$("#credit_details").show();
		$("#card_name").rules("add", {required: true, messages: { required: "Please enter a card holder name.<br/>" }});
		$("#card_type").rules("add", {required: true, messages: { required: "Please choose a card type.<br/>" }});
		$("#card_number").rules("add", { required: true, creditcard: true , messages: { required: "Please type in a valid card number.<br/>" }});
		$("#exp_date").rules("add", {required: true, messages: { required: "Please type in an expiry date.<br/>" }});
		//$("#exp_year").rules("add", {required: true, messages: { required: "Please type in an expiry date.<br/>" }});
		$("#cvc").rules("add", {required: true, messages: { required: "Please enter your cvc code.<br/>" }});
	}				
	else
	{
		$("#credit_details").hide();
		$("#card_name").rules("remove");
		$("#card_type").rules("remove");
		$("#card_number").rules("remove");
		$("#exp_date").rules("remove");
		//$("#exp_year").rules("remove");
		$("#cvc").rules("remove");
	}
}
var countries = ['Malaysia','Ukraine','Venezuela','Turkey','Thailand','Taiwan','Switzerland','Slovak Republic','Singapore','Russian Federation','Poland','Philippines','Panama','Morocco','Mexico','Macau','Lithuania','Latvia','Korea','Japan','Jamaica','Israel','Indonesia','India','Iceland','Hong Kong','Estonia','Czech Republic','Cyprus','Croatia','Colombia','China','Chile','Brazil','Argentina','United States','South Africa','Botswana','Lesotho','Namibia','Swaziland','Australia','Canada','Ireland','Austria','Belgium','Denmark','France','Greece','Italy','Luxemburg','Nederland', 'Portugal','Spain','Sweden','Finland','New Zealand','England','Wales','Scotland'];
var codes = ['60','380','58','90','66','886','41','421','65','7','48','63','570','212','52','853','370','371','82','81','1','972','62','91','354','852','372','420','357','385','57','86','56','55','54','1','27','267','266','264','268','61', '1','353','43','32','45','33','30','39','352','31','351','34','46','358','64','44','44','44'];
function getCountryCode(selec) {ccode='';for (i = 0;i < 60; i++) {if (countries[i] == $('#'+selec).val()) {ccode = codes[i];}}return "+"+ccode;}

function getSubCountries()
{
		
		$("#ccode0").remove();$("#ccode1").remove();$("#ccode2").remove();$("#ccode3").remove();$("#ccode4").remove();$("#ccode5").remove();$("#ccode6").remove();

		var icount = 0;
		$("#phone_day, #landline, #phone_eve, #mobile").each( function (i) 
		{
			if ($('#country').val() != null) $(this).before("<span id='ccode"+icount+"'>"+getCountryCode("country")+" </span>"); 
			icount = icount + 1;
		});
}
function getSubCountriesRegion(bigcountry,field)
{
	var text = "";
	var sel = document.getElementById(bigcountry);
	bigcountry = sel.value;
	var selbox = document.getElementById(field);
	selbox.options.length = 0;
	selbox.options[selbox.options.length] = new Option('--Select Country--','');
	if(bigcountry == "Southern Africa")
	{
		selbox.options[selbox.options.length] = new Option('South Africa','South Africa');
		selbox.options[selbox.options.length] = new Option('Botswana','Botswana');
		selbox.options[selbox.options.length] = new Option('Lesotho','Lesotho');
		selbox.options[selbox.options.length] = new Option('Namibia','Namibia');
		selbox.options[selbox.options.length] = new Option('Swaziland','Swaziland');
	}
	if(bigcountry == "United Kingdom")
	{
		selbox.options[selbox.options.length] = new Option('Ireland','Ireland');
		selbox.options[selbox.options.length] = new Option('England','England');
		selbox.options[selbox.options.length] = new Option('Wales','Wales');
		selbox.options[selbox.options.length] = new Option('Scotland','Scotland');
	}
	if(bigcountry == "European Union")
	{
		selbox.options[selbox.options.length] = new Option('Austria','Austria');
		selbox.options[selbox.options.length] = new Option('Belgium','Belgium');
		selbox.options[selbox.options.length] = new Option('Denmark','Denmark');
		selbox.options[selbox.options.length] = new Option('France','France');
		selbox.options[selbox.options.length] = new Option('Greece','Greece'); 
		selbox.options[selbox.options.length] = new Option('Italy','Italy');
		selbox.options[selbox.options.length] = new Option('Luxemburg','Luxemburg'); 
		selbox.options[selbox.options.length] = new Option('Nederland','Nederland'); 
		selbox.options[selbox.options.length] = new Option('Portugal','Portugal');
		selbox.options[selbox.options.length] = new Option('Spain','Spain');
		selbox.options[selbox.options.length] = new Option('Sweden','Sweden');
		selbox.options[selbox.options.length] = new Option('Finland','Finland');
	}
	if(bigcountry == "Australia")
	{
		selbox.options[selbox.options.length] = new Option('Australia','Australia');
	}
	if(bigcountry == "New Zealand")
	{
		selbox.options[selbox.options.length] = new Option('New Zealand','New Zealand');
	}
	if(bigcountry == "United States")
	{
		selbox.options[selbox.options.length] = new Option('United States','United States');
	}
	if(bigcountry == "Canada")
	{
		selbox.options[selbox.options.length] = new Option('Canada','Canada');
	}
	if(bigcountry == "Other Countries")
	{
		selbox.options[selbox.options.length] = new Option('Argentina','Argentina');
		selbox.options[selbox.options.length] = new Option('Brazil','Brazil');
		selbox.options[selbox.options.length] = new Option('Chile','Chile');
		selbox.options[selbox.options.length] = new Option('China','China');
		selbox.options[selbox.options.length] = new Option('Colombia','Colombia');
		selbox.options[selbox.options.length] = new Option('Croatia','Croatia');
		selbox.options[selbox.options.length] = new Option('Cyprus','Cyprus');
		selbox.options[selbox.options.length] = new Option('Czech Republic','Czech Republic');
		selbox.options[selbox.options.length] = new Option('Estonia','Estonia');
		selbox.options[selbox.options.length] = new Option('Hong Kong','Hong Kong');
		selbox.options[selbox.options.length] = new Option('Iceland','Iceland');
		selbox.options[selbox.options.length] = new Option('India','India');
		selbox.options[selbox.options.length] = new Option('Indonesia','Indonesia');
		selbox.options[selbox.options.length] = new Option('Israel','Israel');
		selbox.options[selbox.options.length] = new Option('Jamaica','Jamaica'); 
		selbox.options[selbox.options.length] = new Option('Japan','Japan');
		selbox.options[selbox.options.length] = new Option('Korea','Korea');
		selbox.options[selbox.options.length] = new Option('Latvia','Latvia');
		selbox.options[selbox.options.length] = new Option('Lithuania','Lithuania');
		selbox.options[selbox.options.length] = new Option('Macau','Macau');
		selbox.options[selbox.options.length] = new Option('Mexico','Mexico');
		selbox.options[selbox.options.length] = new Option('Morocco','Morocco');
		selbox.options[selbox.options.length] = new Option('Panama','Panama'); 
		selbox.options[selbox.options.length] = new Option('Philippines','Philippines');
		selbox.options[selbox.options.length] = new Option('Poland','Poland');
		selbox.options[selbox.options.length] = new Option('Russian Federation','Russian Federation'); 
		selbox.options[selbox.options.length] = new Option('Singapore','Singapore');
		selbox.options[selbox.options.length] = new Option('Slovak Republic','Slovak Republic');
		selbox.options[selbox.options.length] = new Option('Switzerland','Switzerland');
		selbox.options[selbox.options.length] = new Option('Taiwan','Taiwan');
		selbox.options[selbox.options.length] = new Option('Thailand','Thailand');
		selbox.options[selbox.options.length] = new Option('Turkey','Turkey');
		selbox.options[selbox.options.length] = new Option('Venezuela','Venezuela');
		selbox.options[selbox.options.length] = new Option('Ukraine','Ukraine');
		selbox.options[selbox.options.length] = new Option('Malaysia','Malaysia');
	}
		$("#ccode0").remove();$("#ccode1").remove();$("#ccode2").remove();$("#ccode3").remove();$("#ccode4").remove();$("#ccode5").remove();$("#ccode6").remove();

		var icount = 0;
		$("#phone_day, #landline, #phone_eve, #mobile").each( function (i) 
		{
			if ($('#country').val() != null) $(this).before("<span id='ccode"+icount+"'>"+getCountryCode("country")+" </span>"); 
			icount = icount + 1;
		});
}
