﻿// JavaScript Document
var i;
var j;
var sobjTimer=null;
var sobjTimer2=null;
var dvhelp=document.getElementById("infomsgstr");
var tmptimeout=null;
var $=function(id){return(typeof(id)=='object')?id:document.getElementById(id);}
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
var createobj=function(){
	return{
		setObj:function(ele,styles){
			var obj=document.createElement(ele);
            for(var i in styles){
                obj.setAttribute(i,styles[i]);
            }
			return obj;
        },
		setStyle:function(ele,styles){
            for(var i in styles){
                ele.style[i] = styles[i];
            }
        },
		setOpacity:function(ele,level){
            if(createobj.isIE()){
                ele.style.filter = 'Alpha(opacity=' + level + ')';
            }else{
                ele.style.opacity = level/100;
            }
        },
		isIE:function(){
            var sUserAgent = navigator.userAgent;
			return sUserAgent.indexOf("compatible")>-1 && sUserAgent.indexOf("MSIE")>-1 && !(sUserAgent.indexOf("Opera")>-1);
        }
	};
}();
var scd=function(){
	var cHeight=document.documentElement.clientHeight;
	var oWidth,oHeight;
	return{
		top:function(){
			return (document.body.scrollTop>document.documentElement.scrollTop?document.body.scrollTop:document.documentElement.scrollTop)+scd.cHeight/2+'px';
		},
		left:function(){
			scd.cHeight=document.documentElement.clientHeight-parseInt(scd.oHeight);
			return (document.body.offsetWidth-scd.oWidth)/2+'px';
		},
		resize:function(){
			if(showcondiv){
			showcondiv.style.left=scd.left();
			showcondiv.style.top=scd.top();}
		},
		trun:function(){
			if(showcondiv){
			showcondiv.style.top=scd.top();}
		},
		urlstr:function(str){
			str = str.replace(/\&/,"{38}");
			str = str.replace(/\?/,"{63}");
			str = str.replace(/\'/,"{39}");
			str = str.replace(/\"/,"{34}");
			return str;
		},
		disobj:function(meb){
			if($('__inputtxt'))$('__inputtxt').disabled=meb;
			if($('__inputindex'))$('__inputindex').disabled=meb;
			if($('__selectclass'))$('__selectclass').disabled=meb;
			if($('_doset'))$('_doset').disabled=meb;
			if($('_doreset'))$('_doreset').disabled=meb;
			if($('_docan'))$('_docan').disabled=meb;
		}
	};
}();
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 ShowpSize(pid,num,name){
	var showcondiv=$('__showpsizediv');
	if(showcondiv==null){
		nownoload=false;
		scd.oWidth=350;
		scd.oHeight=100;
		showcondiv=createobj.setObj('DIV',{id:'__showpsizediv'});
		createobj.setStyle(showcondiv,{width:scd.oWidth+'px',height:scd.oHeight+'px',backgroundColor:'#333333',padding:'0px 3px',position:'absolute',textAlign:'center'});
		//createobj.setOpacity(showcondiv,90);
		showcondiv.innerHTML="<div style='text-align:center;background-color:#666666;color:#ffffff;padding:6px 0px 3px 0px;margin-bottom:8px;'>Search by Size</div>";
		var input_lable=document.createElement('LABLE');
		createobj.setStyle(input_lable,{color:'#000000',fontSize:'12px',height:'16px',lineHeight:'15px'});
		input_text=createobj.setObj('select',{id:'__selectclass',name:'__selectclass'});
		input_lable.appendChild(input_text);
		showcondiv.appendChild(input_lable);
		showcondiv.innerHTML+='<div class=cls10px></div>';
		
		input_lable=document.createElement('div');
		createobj.setStyle(input_lable,{position:'relative',textAlign:'center'});
		
		var butcan=createobj.setObj('input',{id:'__doset',name:'__doset',type:'button',value:'OK',disabled:'disabled'});
		if(createobj.isIE()){
		butcan.attachEvent('onclick',function(){var sizenum=$('__selectclass').value;document.body.removeChild($("__showpsizediv"));ECar1(pid,num,name,sizenum);});
		}
		else{
		butcan.addEventListener('click',function(){var sizenum=$('__selectclass').value;document.body.removeChild($("__showpsizediv"));ECar1(pid,num,name,sizenum);},false);
		}
		input_lable.appendChild(butcan);
		
		butcan=createobj.setObj('span',{});
		butcan.innerHTML='&nbsp;&nbsp;';
		input_lable.appendChild(butcan);
		butcan=createobj.setObj('input',{id:'__docan',name:'__docan',type:'button',value:'Cancel'});
		if(createobj.isIE()){
		butcan.attachEvent('onclick',function(){document.body.removeChild($("__showpsizediv"));});
		}
		else{
		butcan.addEventListener('click',function(){document.body.removeChild($("__showpsizediv"));},false);
		}
		input_lable.appendChild(butcan);
		showcondiv.appendChild(input_lable);
		
		document.body.appendChild(showcondiv);
		showcondiv.style.left=scd.left();
		showcondiv.style.top=scd.top();
		
		var xmlhttp=AjaxObjcar();
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				if(xmlhttp.responseText!='fail'){
					var retxt=xmlhttp.responseText.split(',')
					var sltobj=$('__selectclass');
					for(var opt in retxt){
						sltobj.options.add(new Option(retxt[opt].trim(),retxt[opt].trim()));
					}
					$('__doset').disabled='';
				}
				else
				alert('Communication error.');
				xmlhttp=null;
				//document.location.reload();
			}
		};
		xmlhttp.open("post","/products.do",true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send("gcsID="+pid);
	}
}

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 ECar1(pid,num,name,size)
{
		var xmlhttp=AjaxObjcar();
		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.value.length<2){
		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;
		}
	}
}

//addsizeslc("size_select",null);
