﻿// JavaScript Document
var i;
var j;
var sobjTimer=null;
var sobjTimer2=null;
var dvhelp=document.getElementById("infomsgstr");
var tmptimeout=null;

function AjaxObjcar(){if(window.ActiveXObject){var msxmls=new Array('Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');for(var i=0;i<msxmls.length;i++){try{return new ActiveXObject(msxmls[i]);}catch(e){}}}else if(window.XMLHttpRequest){return new XMLHttpRequest();}return null;}

function viewcar(url,w,h,s)
{
		showDialog.show(url,w,h,s);
}

function ECarView(pid,num,name)
{
		var xmlhttp=AjaxObjcar();
		var obj=document.getElementById(name);
		var nums=document.getElementById(num);
		var date="pid="+pid+"&pnum="+nums.value+"&psize="+obj.value;
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				xmlhttp=null;
				document.location.reload();
			}
		};
		xmlhttp.open("get","/car.do?"+date,true);
		xmlhttp.send(null);
}

function ECarbySzie(pid,num,name,size)
{
	var xmlhttp=AjaxObjcar();
	if(num<0)
		num=0;
	var date="pid="+pid+"&pnum="+num+"&pname="+escape(name)+"&psize="+escape(size);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			viewcar('/car.do','680','500','yes');
			xmlhttp=null;
		}
	};
	xmlhttp.open("get","/car.do?"+date,true);
	xmlhttp.send(null);
}

function ECar(pid,num,name,size)
{
		var xmlhttp=AjaxObjcar();
		var obj=document.getElementById(size);
		var sizeobj='';
		if(obj!=null)
			if(obj.selectedIndex<0)
			sizeobj='0';
			else
			sizeobj=obj.value;
		else
			sizeobj='0';
		if(num=='usrnm'){
			num=document.getElementById('usrnm').value;
		}
		if(num<0)
			num=0;
		var date="pid="+pid+"&pnum="+num+"&pname="+escape(name)+"&psize="+sizeobj;
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				viewcar('/car.do','680','500','yes');
				xmlhttp=null;
			}
		};
		xmlhttp.open("get","/car.do?"+date,true);
		xmlhttp.send(null);
}

function nextform(obj){
	var divobj=document.getElementById("cur_div_v");
	divobj.innerHTML=obj.cur.value;
	if(obj.name.value.length<3){
		alert('Fill in the First Name is invalid.');
		obj.name.focus();
		return false;
	}
	if(obj.lname.value.length<3){
		alert('Fill in the Last Name is invalid.');
		obj.lname.focus();
		return false;
	}
	divobj=document.getElementById("name_div_v");
	divobj.innerHTML=obj.name.value+' '+obj.lname.value;
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9])+\.([a-zA-Z0-9])+/;
	if(!pattern.test(obj.email.value))
	{
		alert('Fill in the Email is invalid.');
		obj.email.focus();
		return false;
	}
	divobj=document.getElementById("email_div_v");
	divobj.innerHTML=obj.email.value;
	if(obj.add.value.length<5){
		alert('Fill in the Address is invalid.');
		obj.add.focus();
		return false;
	}
	divobj=document.getElementById("add_div_v");
	divobj.innerHTML=obj.add.value;
	if(obj.country.selectIndex<0){
		alert('Fill in the Country is invalid.');
		obj.country.focus();
		return false;
	}
	divobj=document.getElementById("country_div_v");
	divobj.innerHTML=obj.country.value;
	if(obj.province.value.length<2){
		alert('Fill in the Province is invalid.');
		obj.province.focus();
		return false;
	}
	divobj=document.getElementById("province_div_v");
	divobj.innerHTML=obj.province.value;
	divobj=document.getElementById("tele_div_v");
	divobj.innerHTML=obj.tele.value;
	if(obj.zip.value.length<4){
		alert('Fill in the Zip code is invalid.');
		obj.zip.focus();
		return false;
	}
	divobj=document.getElementById("zip_div_v");
	divobj.innerHTML=obj.zip.value;
	divobj=document.getElementById("payment_div_v");
	var paymentobj=document.getElementsByName("payment");
	for(var i = 0;i<paymentobj.length;i++){
		if(paymentobj[i].checked){
			divobj.innerHTML=paymentobj[i].value;
			break;
		}
	}
	var obj=document.getElementById("formdiv");
	obj.style.display="none";
	obj=document.getElementById("formdivv");
	obj.style.display="block";
}

function backform(){
	var obj=document.getElementById("formdivv");
	obj.style.display="none";
	obj=document.getElementById("formdiv");
	obj.style.display="block";
}

var optionstr=["testpx","3.0 g","long long long"];
var optionval=["1","2","3"];

function addsizeslc(obj,defalut){
	var objslc=document.getElementById(obj);
	if(objslc!=null){
		objslc.add(new Option("select","0"))
		for(var i in optionstr)
		{
			objslc.add(new Option(optionstr[i],optionval[i]));
			if(optionval[i]==defalut)
				objslc.selectedIndex=objslc.length-1;
		}
	}
}
String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}
var $=function(id){return(typeof(id)=='object')?id:document.getElementById(id);}
function gettable(){
	var cur=$("cur"),country=$("country"),payment=document.getElementsByName("payment"),div=$("con_table");
	if(cur!=null && country!=null && payment!=null && div!=null)
	{
		for(var i = 0;i<payment.length;i++){
			if(payment[i].checked){
				payment=payment[i].value;
				break;
			}
		}
		var xmlhttp=AjaxObjcar();
		xmlhttp.open("post", "buy.do",true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send("getable=true&cur="+escape(cur.value)+"&payment="+payment+"&con="+escape(country.value));
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState==4){
				if(xmlhttp.status==200){
					div.innerHTML=xmlhttp.responseText;
				}
				else{
					alert('Connection error.');
				}
				xmlhttp=null;
			}
		}
	}
}
function isIE(){
	var sUserAgent = navigator.userAgent;
	return sUserAgent.indexOf("compatible")>-1 && sUserAgent.indexOf("MSIE")>-1 && !(sUserAgent.indexOf("Opera")>-1);
}
if(isIE()){
	window.attachEvent('onload',gettable);
}
else{
	window.addEventListener('load',gettable,false);
}
//addsizeslc("size_select",null);
function showcls(str){
	var obj=$('clsul'+str);
	if(obj!=null){
		if(obj.style.display=='none')
			obj.style.display='block';
		else
			obj.style.display='none';
	}
}