// check reg items

function setMidImg(mid_url,big_url){
	$("#bigimg").attr("src",mid_url);
	$("#urllinks").attr("href",big_url);
}

function loadStyle(product_id,mid,step_obj_name){
	var step=$("#"+step_obj_name).val();
	var url="/ajax/style/"+product_id+"/"+mid+"/"+step;
 	var content=ajax(url,"",false,"GET");
	$("#styleinfo").html(content);
}

function setFont(font){
	$("#monogram_font").val(font);	
	if(font=="Times Roman"){
		$("#fontimgs1").attr("class","fontsimg1");
		$("#fontimgs2").attr("class","fontsimg");
	}else{
		$("#fontimgs1").attr("class","fontsimg");
		$("#fontimgs2").attr("class","fontsimg1");
	}
}

function setColor(color){
	$("#monogram_color").val(color);	
	if(color=="White"){
		$("#fontcolor1").attr("class","fontsimg1");
		$("#fontcolor2").attr("class","fontsimg");
		$("#fontcolor3").attr("class","fontsimg");
		$("#fontcolor4").attr("class","fontsimg");
	}else if(color=="Grey"){
		$("#fontcolor1").attr("class","fontsimg");
		$("#fontcolor2").attr("class","fontsimg1");
		$("#fontcolor3").attr("class","fontsimg");
		$("#fontcolor4").attr("class","fontsimg");
	}else if(color=="Blue"){
		$("#fontcolor1").attr("class","fontsimg");
		$("#fontcolor2").attr("class","fontsimg");
		$("#fontcolor3").attr("class","fontsimg1");
		$("#fontcolor4").attr("class","fontsimg");
	}else if(color=="Black"){
		$("#fontcolor1").attr("class","fontsimg");
		$("#fontcolor2").attr("class","fontsimg");
		$("#fontcolor3").attr("class","fontsimg");
		$("#fontcolor4").attr("class","fontsimg1");
	}

}


 
 
 
/*检测是否填写尺寸信息*/
function checkMeasurements(obj){
	if(obj.shirt_neck.value==""){
		alert("Please input the shirt neck size");
		return false;
	}
	if(obj.jacket_length.value==""){
		alert("Please input the Jacet Length");	
		return false;
	}
	if(obj.sleeve_length.value==""){
		alert("Please input the sleeve length");	
		return false;
	}
	if(obj.chest_size.value==""){
		alert("Please input the chest size");
		return false;
	}
	if(obj.stomach_size.value==""){
		alert("Please input the stomach size");
		return false;
	}
	if(obj.jacket_hips.value==""){
		alert("Please input the jacket hips");
		return false;
	}
	if(obj.shoulder_size.value==""){
		alert("Please input the shoulder size");
		return false;
	}
	if(obj.bicep_size.value==""){
		alert("Please input the bicep size");
		return false;
	}	
	if(obj.wrist_size.value==""){
		alert("Please input wrist size");
		return false;
	}
	if(obj.pants_length.value==""){
		alert("Please input pants length");
		return false;
	}
		
	if(obj.Waist.value==""){
		alert("Please input waist size");
		return false;
	}
	if(obj.crotch.value==""){
		alert("Please input the crotch size");	
		return false;
	}
	if(obj.pants_hips.value==""){
		alert("Please input the pants hips");
		return false;
	}	
	if(obj.thigh_size.value==""){
		alert("Please input the thigh size ");
		return false;
	}
	if(obj.knee_size.value==""){
		alert("Please input the knee size");
		return false;
	}
	
	return true;
}



//check Promo code

function redeem(){
	var code=$("#promo_code").val();
	if(code==""){
		$("#redeem_msg").html("Please input the Promo code");
		return false;
	}
	
	var url="/shopping/setdiscount.html";
	
	var content=ajax(url,"code="+code,false,"GET");
	var msg="";
	switch(parseInt(content)){
		case 1:
			msg="Please input the promo code!";
			break;
		case 2:
			msg="You can not use this promo code!";
			break;
		case 3:
			msg="The Promo Code does not exists";
			break;
		case 4,5:
			msg="The promo code is not in use during the period!";
			break;
		case 6:
			window.location.reload();
			break;
		default:
			
	}
	$("#redeem_msg").html(msg);
	
}



function setShippingFee(obj){
	var url="/ajax/getShippingCost.html";
	var content=ajax(url,"ship_id="+obj.value,false,"GET");

	$("#shipfee").html("$ "+content+" USD");
	$("#shipping").val(parseFloat(content));
	
	url="/ajax/getFinalTotal.html";
	content=ajax(url,"shipfee="+content,false,"GET");
	$("#final_total").html("$ "+content+" USD");
}


//购物车全选
function SelectAll(obj){
	var ids=document.getElementsByName("id[]");
	if(ids.length>0){
		for(var i=0;i<ids.length;i++){
			ids[i].checked=obj.checked;
		}
	}
}

//remove product from cart
function removeCart(form_name){
  if(confirm("Would you like to remove the product your picked from your shopping cart?")){
	$("#"+form_name).attr("action","/shopping/removeCart");	
	$("#"+form_name).submit();
  }
}

function updateCart(form_name){
	$("#"+form_name).attr("action","/shopping/updateCart");
	$("#"+form_name).submit();
 }
 
function CheckOut(form_name){
	var url="/ajax/checkCart.html";
	var content=ajax(url,"",false,"GET");
	if(parseInt(content)==0){//please loing first
		window.location.href="/user/login.html?ref=/shopping/cart.html";		 
	}
	if(parseInt(content)==1){
		alert("There is not anything on your cart!");
		return false;
	}
	if(parseInt(content)==2){
			$("#"+form_name).attr("action","/shopping/checkout.html");
			$("#"+form_name).submit();
	}
	
}


//检测登录
function Login(){
	if($("#username").val()==""){
		alert("Please Input your UserName or Email address");
		return false;
	}
	if($("#password").val()==""){
		alert("Please input your password");
		return false;
	}
	return true;
}


//设置默认
function setCurrentDefault(obj){
	 var subitem=document.getElementsByName("address_id");
	 for(var i=0;i<subitem.length;i++){
		subitem[i].parentNode.className="nocurrent";
		
	 }
	 
	 obj.parentNode.className="current";
	 if(obj.value=="0"){
		$("#newaddress").show("fast"); 
	 }else{
		$("#newaddress").hide("fast"); 
	 }	
}


//保存新地址
function addNewAddress(){
	if($("#firstname").val()==""){
		alert("Please input your first name");
		return false;
	}
	
	if($("#lastname").val()==""){
		alert("Please input your last name");
		return false;
	}
	
	if($("#country").val()==""){
		alert("Please input your country");
		return false;
	}
	
	if($("#state").val()==""){
		alert("Please input your State");
		return false;
	}
	
	if($("#city").val()==""){
		alert("please input your city");
		return false;
	}
	if($("#address1").val()==""){
		alert("Please input your address");
		return false;
	}
	
	if($("#postal").val()==""){
		alert("Please input your postal code");
		return false;
	}
	if($("#telephone").val()==""){
		alert("Please input your telephone");
		return false;
	}

}


function checkUseraddress(){
	if($("#address_id").val()=="0"){
		if(!addNewAddress()){
			return false;	
		}
	}
	 
}

function loadAddress(id){
	var url="/ajax/getaddress/"+id+".html";
 
	var content=ajax(url,"",false,"GET");
 	 
	if(content==0){
		window.location.href="/user/login.html";	
		return false;
	}
	if(content==1){
		alert("Your address does not exists!");
		return false;
	}
 	
	 
	var js=eval("("+content+")");
	if(js){
	   $("#id").val(js.address_id);
	   $("#firstname").val(js.address_firstname);
	   $("#lastname").val(js.address_lastname);
	   $("#country").val(js.address_country);
	   $("#state").val(js.address_state);
	   $("#city").val(js.address_city);
	   $("#line1").val(js.address_line1);
	   $("#line2").val(js.address_line2);
	   $("#postal").val(js.address_postal);
	   $("#telephone").val(js.address_telephone);
		 if(js.address_default=="Y"){
		   $("#address_default").attr("checked",true);
		}else{
			$("#address_default").attr("checked",false);	
		}
	   $("#addresscap").html("Address Edit");
		
	}
 
 

}

