// JavaScript Document
//从quickBuy iframe子页面跳转到父页面form处
function toForm(){
	var hash = parent.location.hash;
	if(hash=="#form"){
		parent.location.href=parent.location;
	}else{
		parent.location.href=parent.location + "#form";
	}
}

//使文本框只能输入整数
function justInteger(t){ 
  t.value=t.value.replace(/[^\d]/g,"");
}

function change(oC){
	var quantityId = oC.value + "_quantity";
	if($(oC).attr("checked") == true){
		$("#"+quantityId).val("1");
		$("#"+quantityId).removeAttr("readonly");
		$("#"+quantityId).removeClass("readonly");
	}else{
		$("#"+quantityId).val("0");
		$("#"+quantityId).attr("readonly","true");
		$("#"+quantityId).addClass("readonly");
	}
}

//验证产品
function validateProduct(){
	var hasProduct = false;
	var qtyProduct = true;
	$("input[name='productCheck']").each(function(){
		if($(this).attr("checked")){
			hasProduct = true;
			var quantityId = $(this).val() + "_quantity";
			var quantityValue = parseInt($("#"+quantityId).val());
			if(quantityValue<=0){
				//alert("产品数量格式不对，请改正后重新提交。");
				qtyProduct = false;
			}
		}
	});
	if(hasProduct && qtyProduct){
		return true;
	}else{
		$("#product_msg").html("没有选择任何产品或者产品数量格式不正确，请改正后重新提交。").addClass("error");
		return false;
	}
}

//iframe auto height
function autoHeight(oFrm){    
	//oFrm.contentWindow.document为IE下 使用，获得子页面各个对象   
	var sub=oFrm.contentDocument ? oFrm.contentDocument:oFrm.contentWindow.document;    
	if(oFrm!=null&&sub!=null){   
	  oFrm.height=sub.body.scrollHeight+10;   
	}   
}

//默认选中"货到付款"
function autoSelectExp(){
	$(":radio[value='3']").attr("checked", true); 
}