
function _recalc() {
	//alert($("#wigtype").val() + "=>" + $("input[name='frontalwigs']:checked").val());
	$.get("./content/common/common.custom.php",
	{ 
		hairlenght: $("#hair_length").val(),
		hairdensity: $("#hairdensity").val(),
		qty: $("#qty").val(),
		wigtype: $("#wigtype").val(),
		fw: $("input[name='frontalwigs']:checked").val()
	},	
		function(data){
			//alert(data);
			a = new Array;
			a = data.split("&");
			if(!a[3]){
				a[3] = 0;
			}
			//a["fw"] = new Array;
//			$.each( data, function(i, n){ 
//				a[i] = n;
//			});
			
			if(a[0]=='1'){
				$("#r2_5").show();
				var s = 1;
			}else{
				$("#r2_5").hide();
			}
			if(a[1]=='1'){
				$("#r4_0").show();
				var s = 1;
			}else{
				$("#r4_0").hide();
			}
			if(a[2]=='1'){
				$("#r5_0").show();
				var s = 1;
			}else{
				$("#r5_0").hide();
			}
			if(s != 1){
				$("#wigtypeoptions").hide();
			}else{
				wigTypeOptions();
			}
			
			pr = a[3]*$("#qty").val();
			
			$("#price1").empty();
			$("#price1").append("Total price: &pound;"+pr+"");
			//$("#price").empty();
			$("#price").val(a[3]);
  			
 		}
  	);
}

//				$("#_content").hide();
//				$("#_content_resp").show();

function send(submit_type) {
	var is_error = false;	
	
	if ($("#name").val()=='') {
		is_error = true;
		$("#name").addClass("error");
	} else {
		$("#name").removeClass("error");
	}
	
	if ($("#hair_length").val()=='') {
		is_error = true;
		$("#hair_length").css("border", "2px solid red");
	} else {
		$("#hair_length").css("border", "1px solid #707070");
	}
	
	if ($("#hair_colour").val()=='') {
		is_error = true;
		$("#hair_colour").css("border", "2px solid red");
	} else {
		$("#hair_colour").css("border", "1px solid #707070");
	}
	
	if ($("#hairdensity").val()=='') {
		is_error = true;
		$("#hairdensity").css("border", "2px solid red");
	} else {
		$("#hairdensity").css("border", "1px solid #707070");
	}
	
	if($("#customcapsizes").val() == $("input[name='capsizes']:checked").val()){
		if ($("#circumference").val()=='') {
			is_error = true;
			$("#circumference").css("border", "2px solid red");
		} else {
			$("#circumference").css("border", "1px solid #707070");
		}
	
		if ($("#fronttonape").val()=='') {
			is_error = true;
			$("#fronttonape").css("border", "2px solid red");
		} else {
			$("#fronttonape").css("border", "1px solid #707070");
		}
	
		if ($("#ete_acrossforehead").val()=='') {
			is_error = true;
			$("#ete_acrossforehead").css("border", "2px solid red");
		} else {
			$("#ete_acrossforehead").css("border", "1px solid #707070");
		}
	
		if ($("#ete_overtop").val()=='') {
			is_error = true;
			$("#ete_overtop").css("border", "2px solid red");
		} else {
			$("#ete_overtop").css("border", "1px solid #707070");
		}
	
		if ($("#templeroundback").val()=='') {
			is_error = true;
			$("#templeroundback").css("border", "2px solid red");
		} else {
			$("#templeroundback").css("border", "1px solid #707070");
		}
	
		if ($("#napeofneck").val()=='') {
			is_error = true;
			$("#napeofneck").css("border", "2px solid red");
		} else {
			$("#napeofneck").css("border", "1px solid #707070");
		}
	}
//	if ($("#hairtexture").val()=='') {
//		is_error = true;
//		$("#hairtexture1").css("border", "2px solid red");
//	} else {
//		$("#hairtexture1").css("border", "0px");
//	}
//	
//	if ($("#curlsize").val()=='') {
//		is_error = true;
//		$("#curlsize1").css("border", "2px solid red");
//	} else {
//		$("#curlsize1").css("border", "0px");
//	}
	
	if ($("#qty").val()=='') {
		is_error = true;
		$("#qty").addClass("error");
	} else {
		$("#qty").removeClass("error");
	}

	
	//alert(is_error);
	if (!is_error) {
		if(submit_type != 'save'&&submit_type != 'delete'){
			submit_product(submit_type);
		}else{
			if(submit_type == 'save'){
			$("#action1").val("save");
			var qString = $("#custom_form").serialize();
			$.post("./content/common/common.customsave.php", qString, 
  				function(data){
  					if(data){
  						if(data != "upd"){
  							$("#templblock").show();
							$("#templates").append("<option value='"+data+"'>"+$("#name").val()+"</option>");
							$("#alert").show();
							$("#alerttext").html("Template "+$("#name").val()+" saved successfuly!");
						}else{
							$("#templates option:selected").html($("#name").val());
							$("#alert").show();
							$("#alerttext").html("Template <b>'"+$("#name").val()+"'</b> updated successfuly!");
						}
  					
						
					}
  				}
  			);
			}
			if(submit_type == 'delete'){
				$("#action1").val("delete");	
				$.post("./content/common/common.customsave.php", {action: "delete", pid: $("#pid").val()}, 
  				function(data){
  					//alert(data);
					if(data){
						$("#templates option:selected").remove();
						if(!$("#templates").length){
							$("#templblock").hide();
						}
						$("#alert").show();
						$("#alerttext").html("Template "+$("#name").val()+" removed successfuly!");
					}
  				}
  			);
			}
		}
	}


}

function submit_product(submit_type)
{
	if(submit_type == 'basket'){
		//$("#custom_form").attr("action", '/shopping-cart/add.htm');
		$("#custom_form").submit();
	}
	
	if(submit_type == 'basket_upd'){
		//document.getElementById("custom_form").action = './shopping-cart/update.htm';
		document.getElementById("custom_form").submit();
	}
}

function capSizeOptions(){
	if($("#customcapsizes").val() == $("input[name='capsizes']:checked").val()){
		$("#capsizeoptions").show();	
		$("#is_capsize").val('1');
	}else{
		$("#capsizeoptions").hide();	
		$("#is_capsize").val('0');
	}
}

function textureOptions(){
	//alert($("#customcurlsizes").val() + " => " + $("input[name='hairtexture']:checked").val())
	if($("#customcurlsizes").val() == $("input[name='hairtexture']:checked").val()){
		$("#curlsizeoptions").show();	
		$("#is_curly").val('1');
	}else{
		$("#curlsizeoptions").hide();	
		$("#is_curly").val('0');
	}
}

function wigTypeOptions(){
	if($("#wigtype").val() == 4){
		$("#wigtypeoptions").show();
		$("#is_wigtype").val('1');
	}else{
		$("#wigtypeoptions").hide();
		$("#is_wigtype").val('0');
	}
}

function stripslashes( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
 
    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}

capSizeOptions();
textureOptions();
wigTypeOptions();
_recalc();
