function str2date(str){
	var aryDate = str.split("-");
	var month = parseInt(aryDate[1]) - 1;
	return new Date(aryDate[0],month,aryDate[2],0,0,0);
}

function ifEmpty(ele,msg) {
	if(ele.value == '') {
		alert(msg);
		ele.focus();
		return false;
	}
return true;
}


function CheckEmail(ele,msg){
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  var email=ele.value;

  if (!(!reg1.test(email) && reg2.test(email))) { // if syntax is valid
		alert(msg); // this is also optional
		ele.focus();
		return false;
  }
  return true;
}

function openUrl(theUrl,wlength,hlength)
{
    window.open(theUrl, "","width="+wlength+",height="+hlength+",resizable=yes,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,top=70,left=130");
}

function redMsg(msg){
	var str = "";
	str = "<font color=\"red\">"+msg+"</font>";
	return str;
}

function getCheckedRadioKey(obj){
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked)
			return obj[i].value;			
	}
}

function doPrint() {
	var bodystr=document.body.innerHTML;
	var obj = document.body.style;
	var originBgcolor = document.body.style.background;
	var originBgimage = document.body.style.backgroundImage;
	var p_content=document.all.printLayer.innerHTML;
     if (window.print) {
       //document.body.innerHTML = '<center>' + p_content + '</center>';
	   document.body.style.backgroundImage = '';
	   document.body.style.background = 'ffffff';
       document.body.innerHTML =  p_content;
       window.print();
     }
     window.location.reload();
//	document.body.style.backgroundImage=originBgimage;
//	document.body.style.background=originBgcolor;
//	document.body.innerHTML=bodystr;
}
function checkNull(obj)
{
	if (obj == null || typeof(obj) == "undefined") {
		return true;
	}
	return false;
}
function getVal(extra_val)
{
	if (checkNull(extra_val) == false) {
		return extra_val.value;
	}
	return '';
}

function Testprice1(product_id,extra1_val,extra2_val,extra3_val,extra4_val)
{
	price_ary = eval('price_ary_' + product_id);
	for (i = 0; i < price_ary.length; i++) {
		if (price_ary[i][0] == extra1_val && price_ary[i][1] == extra2_val && price_ary[i][2] == extra3_val && price_ary[i][3] == extra4_val) {
			return price_ary[i][4];
		}
	}
	default_price = eval('default_price_' + product_id);
	//default_price = 123;
	return default_price;
}

function changePrice(form, product_id)
{
	extra1_val = getVal(form.extra1);
	extra2_val = getVal(form.extra2);
	extra3_val = getVal(form.extra3);
	extra4_val = getVal(form.extra4);
	//document.write(extra1_val); document.write(extra2_val);    document.write(extra3_val); document.write(extra4_val);   
	pricetest=Testprice1(product_id,extra1_val,extra2_val,extra3_val,extra4_val);
	//document.write(test);   
	//xajax_calcPromotion(product_id,product_price_);
    //xajax_helloWorld(0);
	//document.getElementById('promotion_iframe_' + product_id).src = '/shop/promotion.server.php?func=calcPromotion&product_id=' + product_id + '&price=' + product_price_;
	document.getElementById('product_price_' + product_id).innerHTML =pricetest;
	//document.getElementById('product_price_' + product_id+"_2").innerHTML = product_price_;
}