/*
	http://www.cloakrenaissance.com
	version: 1.0 
	Date: 2008-8-26
*/

function $(){
	var El=new Array();
	for(var i=0;i<arguments.length;i++){
	var el=arguments[i];
	if (typeof el== "string"){
	el=document.getElementById(el);
	if (arguments.length==1)
	return el;
	El.push(el);
	}
	return El;
	}
}

//***
function trim(str) {
if(!str || typeof str != 'string')
return null; 
return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
//***

String.prototype.Trim = function() {return this.replace(/(^\s*)|(\s*$)/g, ""); } 


function CloseDiv(id){
		var stmt = $(id).style;
 		if(stmt.display=='none'){
			stmt.display='block';
			$(id+'s').innerHTML="<img src='/products/images/g.gif' border=none>";
			
		}else{
			stmt.display='none';
			$(id+'s').innerHTML="<img src='/products/images/j.gif' border=none>";
		}
}
//***

function clearShip(){
var _sbmoney = $('subTotalMoney').innerHTML;
$('shipPrice').value='';
$('shippingMoney').innerHTML='';
$('RoteMessage').style.display='none';
$('TotalPay').innerHTML=_sbmoney;
}
//***
function DeleteProduct(sku){
		$("item_"+sku).checked=false;
}
//***
function sendAsGift(N){
clearShip();
	if(N==1){
 		state.setVisible('shipInfo');
	}else{
		state.setHidden('shipInfo');
	}
}
//***
function CreatePassword(){
	if($('passwordDiv').style.display=="none"){
	state.setVisible('passwordDiv');
	}else{
		state.setHidden('passwordDiv');
	}
}


//***
var state={
	setVisible:function(id){ $(id).style.display="block";},
	setHidden:function(id){ $(id).style.display="none";}
	}
 
 
//***
var tree={
		getfirstNodeValue:function(xml,id){
			 
			},
		getlastNodeValue:function(xml){
			 
			},
		getNodeValue:function(xml,id){
			return xml.getElementsByTagName(id).item(0).firstChild.nodeValue;
			}
	}
//***
function setValue(_type,id,value){
	 if(_type==0){
	 	$(id).value=value;
	}else if(_type==1){
		$(id).innerHTML=value;
	}
}
//***
function getValue(_type,id){
	if(_type==0){
		return $(id).value;
	}else if(_type==1){
		return $(id).innerHTML;
	}
}
//***
function setFocus(id){
	$(id).focus();
}
//***
var xhr;
function openXHR(){
		try{
			xhr=new ActiveXObject("Msxml2.XMLHTTP");		
			}catch(e){
				try{
						xhr=new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){
						xhr=false;
						}
				}
		if(!xhr && typeof XMLHttpRequest !="undefined"){
			xhr=new XMLHttpRequest();
			}
		return xhr;
}

/* ebay */

function eBayPaybyCreditCard(){
	var _billinginfo = checkebayBillingInformation();
	if(_billinginfo==false){
		return false;
	}
	var _cardinfo = checkCardInformation();
	if(_cardinfo==false){
		return false;
	}
	
	var _checkout = document.checkoutForm;
	_checkout.action="eBay-paybycreditcard.asp";
	_checkout.submit();
}


/* end */


 function CalculateShip(){
	 
	var _place = $('shipTo').value;
	
 	var _c=getValue(0,'Country');
 	var _s;
	var _z;
 	var _w=getValue(0,'Weight');
	
 
	
	if(_place==1){
	var _shipcheck = checkShippingInformation();
	if(_shipcheck==false){
		return false;
	}
	}else{
		var _billcheck = checkBillingInformation();
		if(_billcheck==false){
			return false;
		}
	}
	$('RoteMessage').style.display='block';
	_s = (_place==1 ? getValue(0,'States') : getValue(0,'State'));
	_z = (_place==1 ? getValue(0,'Zips') : getValue(0,'Zip'));
 	
 	openXHR();
 	var _url="/xml-rate-data.asp?country="+_c+"&state="+_s+"&zipcode="+_z+"&weight="+_w;
	xhr.open("get",_url,true);
	xhr.onreadystatechange=function(){
		
		/// start ---

		if (xhr.readyState<4){
			$("RoteMessage").innerHTML="<div align=center>Please Wait ...</div>";
		}else{
		var _listMsg='';
		var _errorMsg='';
		var dom=xhr.responseXML.documentElement;
		var _price=dom.getElementsByTagName("Price");
		var RoteString,RoteValue;
 		var Explain;
  	  //  _listMsg+="<div style='color:#999999;font-size:11px;'>Weight: "+_w+" LBS </div>";
		for(var i=0;i<_price.length;i++){
			RoteString=_price[i].childNodes[0].nodeValue;
			RoteValue=RoteString.match(/\d+.\d+/);
			if(parseInt(RoteValue)>0){
 				if( RoteString.indexOf("Priority Mail")>0 ) { 
				Explain="Usps Priority - 1-5 days processing + 2-3 days transit"; }
				else if(RoteString.indexOf("Express Mail")>0 ){
				Explain="Usps Express - 1-2 days processing + 1 day transit"; }
 				else {Explain="";}
				var _RoteInfo = RoteString+"|"+Explain;
  		 _listMsg+="<div><input style='border:none' type=\"radio\" name=\"Rote\" id=\"Rote_"+i+"\" value=\""+RoteValue+"\"  onclick=\"RecalcuateShipMoney(1,"+i+",'"+_RoteInfo+"')\"  id=\"p_"+i+"\">$" +RoteValue+'</div>';
		 _listMsg+="<div style='font-size:12px;color:#FF8000;padding-left:25px; padding-bottom:10px;'>"+Explain+"</div>";
 		}
		else{
 		_errorMsg="<div align=center style='color:red'>Sorry, your city, state and zip code do not match.</div>"
			}
			
		 
		}
		if(_errorMsg!=''){
		$("RoteMessage").innerHTML=_errorMsg;
		}else{
		//_listMsg+="Please allow 3 working days for processing your order.";
		$("RoteMessage").innerHTML=_listMsg;
		}
		/// end ---
		}
		}
	xhr.send(null);
 }
 
 //*** test ***/
 
 
 
 //***
function AutoRecalcuateShip(){
	var _place = $('shipTo').value;
	var _zipValue;
 	if(_place==1){
 			_zipValue = $("Zip").value;
		}else{
 			_zipValue = $("Zips").value;
		}
	
	if(_zipValue!=""){
		CalculateShip();
	}else{
		return false;
	}
}
//***

function MyAjaxRequest(){
var Ajax=null;
try{
Ajax=new XMLHttpRequest();
}catch(e){
try{
Ajax=new ActvieXObject("Msxml2.XMLHTTP");
}catch(e){
Ajax=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return Ajax;
}

function RecalcuateShipMoney(type,no,info){
var _id = $("Rote_"+no);
if (type==1){
	_id.checked=true;
		var shipPrice = _id.value;
		var subprice = $("subTotalPrice").value;
		var sessionID=getValue(0,'sessionID');
 		CheckPrice(shipPrice,subprice,info);
		$('shiptype').value=info;
	}
	return;
}
//***
function CheckPrice(shipprice,subprice,info){
	 
  		var sessionID=getValue(0,'sessionID');
    		 openXHR;
		 var _url="/xmlshipprice.asp?shipprice="+shipprice+"&subprice="+subprice+"&sid="+sessionID+"&info="+info;
 		 xhr.open("get",_url,true);
 		 xhr.onreadystatechange=function(){
			 	 if(xhr.readyState==4){
 				 var getPrices=xhr.responseText;
				 var _MoneyArray=new Array();
				 _MoneyArray=getPrices.split("|");
				 setValue(0,'shipPrice',_MoneyArray[0]);
 				 setValue(1,'shippingMoney',_MoneyArray[0]);
 				 setValue(1,'TotalPay',_MoneyArray[1]);
 			  }
			 }
		 xhr.send(null);	
}


function checkcheckout(){
		var AString = new Array("First Name","Last Name","Address","State","City","Zip","Phone","Email");
		var AddressString = new Array("firstName","lastName","Address","State","City","Zip","Phone","Email");
			for(var i=0 ;i<AddressString.length;i++){
					if(!isInvalid(AddressString[i])){
						alert("Billing " + AString[i]+" is invalid !");
						setFocus(AddressString[i]);
 						return false;
				}
			}
			var getEmail = $("Email").value;
			var checkEmail = $("Email2").value;
			
			if(!checkemail(getEmail)){
				alert("Email is invalid !");
				setFocus("Email");
				return false;
			}
			
			if( getEmail!=checkEmail ){
				alert("Confirm Email is invalid !");
				setFocus("Email2");
				return false;
			}
			
//check ship
			var _place = $('shipTo').value;
			if(_place==1){
				var SString = new Array("First Name","Last Name","Address","State","City","Zip","Phone");
 				var ShipAddressString = new Array("firstNames","lastNames","Addresss","States","Citys","Zips","Phones");
				
  				for(var i=0 ;i<ShipAddressString.length;i++){
					var _sv = $(ShipAddressString[i]).value;
					if(_sv==null || _sv==''){
						alert("Shipping "+ SString[i]+" is invalid !");
						setFocus(ShipAddressString[i]);
 						return false;
						}
					}// end for
			}
			
//check shipment

			$('shipPrice').value = getValue(1,'shippingMoney');
			var _sp = $('shipPrice').value;
			var _sp2 = $('shippingMoney').innerHTML;
			if(_sp==null || _sp=='' || _sp2==null || _sp2==''){
				alert('Please calculate your shipping!');
				return false;
			}
		return true;
}


//new js code 

function checkDateDiff(){
  var _m = getValue(0,'cardMonth');
  var _y = getValue(0,'cardYear');
  var   str   =   _y+'-'+_m+'-30';
  var   re   =   /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;  
  var   dt;  
  if   (re.test(str)) {  
    dt   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);  
  }  
 var dt2 = new Date();
 var _diff = Math.floor((dt-dt2)/(1000 * 60 * 60 * 24));
 
 if(_diff<=0){
		 alert('Expiration Date is invalid!');
		 return false;
}
}

function checkMatchEmail(){
	var getEmail = $("Email").value;
	var checkEmail = $("Email2").value;
	if(!checkemail(getEmail)){
		alert("Email is invalid !");
		setFocus("Email");
		return false;
	}
 
	if(getEmail!=checkEmail){
		alert("Confirm Email is invalid !");
		return false;
	}
	
}

function checkMatchPassword(){
	var pwd1 = getValue(0,'pwd1');
	var pwd2 = getValue(0,'pwd2');
	if(pwd1!='' && pwd2!=''){
		if(pwd1!=pwd2){
			alert('Confirm password is invalid !');
			return false;
		}
	}
	return true;
}

function checkBillingInformation(){
	var AddressString = new Array("firstName","lastName","Address","State","City","Zip","Phone","Email");
	var AString = new Array("First Name","Last Name","Address","State","City","Zip","Phone","Email");
	for(var i=0 ;i<AddressString.length;i++){
					if(!isInvalid(AddressString[i])){
						alert("Billing " + AString[i]+" is invalid !");
						setFocus(AddressString[i]);
 						return false;
				}
	 }
	 var _checkEmail = checkMatchEmail();
	 if(_checkEmail==false){
		 return false;
	 }
 }
 
function checkebayBillingInformation(){
	var AddressString = new Array("firstName","lastName","Address","State","City","Zip","Phone");
	var AString = new Array("First Name","Last Name","Address","State","City","Zip","Phone");
	for(var i=0 ;i<AddressString.length;i++){
					if(!isInvalid(AddressString[i])){
						alert("Billing " + AString[i]+" is invalid !");
						setFocus(AddressString[i]);
 						return false;
				}
	 }
 
 }
 
function checkShippingInformation(){
	var SString = new Array("First Name","Last Name","Address","State","City","Zip","Phone");
	var ShipAddressString = new Array("firstNames","lastNames","Addresss","States","Citys","Zips","Phones");
	for(var i=0 ;i<ShipAddressString.length;i++){
		var _sv = $(ShipAddressString[i]).value;
		_sv = _sv.replace(/(^\s*)|(\s*$)/g, ""); 
		if(_sv==null || _sv==''){
			alert("Shipping "+ SString[i]+" is invalid !");
			setFocus(ShipAddressString[i]);
			return false;
			}
		} 
}




function checkShippingMoney(){
	$('shipPrice').value = getValue(1,'shippingMoney');
	var _sp = $('shipPrice').value;
	var _sp2 = $('shippingMoney').innerHTML;
	if(_sp==null || _sp=='' || _sp2==null || _sp2==''){
	alert('Please calculate your shipping!');
	return false;
	}
}

function checkCardInformation(){
	var _cardno = $('cardNo').value;
	var _cardname = $('cardName').value;
	var _cardcode = $('cardCode').value;
	
if(_cardno==null || _cardno==''){
		alert("Card No is invalid !");
		setFocus('cardNo');
		return false;
}else if(_cardno.length<14 || _cardno.length>22){
		alert("Card No is invalid !");
		setFocus('cardNo');
		return false;
}
		
	if(_cardname==null || _cardname==''){
	alert("Card Name is invalid !");
		setFocus('cardName');
		return false;}
	var _date = checkDateDiff();
	if(_date==false){
		return false;
	}
	if(_cardcode==null || _cardcode==''){
	alert("Secuirty Code is invalid !");
		setFocus('cardCode');
		return false;}	
	
}


function checkInformation(){
	var _billinginfo = checkBillingInformation();
	if(_billinginfo==false){
		return false;
	}
	var _place = $('shipTo').value;
	if(_place==1){
		var _shippinginfo = checkShippingInformation();
		if(_shippinginfo==false){
			return false;
		}
	}
	var _shippingmoney = checkShippingMoney();
	if(_shippingmoney ==false){
		return false;
	}
	
	var _checkpassword = checkMatchPassword();
	if(_checkpassword == false){
		return false;
	}
	
	var _cardinfo = checkCardInformation();
	if(_cardinfo==false){
		return false;
	}
}

function PaybyCreditCard(){
 	var _check =  checkInformation();
	if(_check == false){
	return false;
	}
	
	var _checkout = document.checkoutForm;
	_checkout.action="https://www.cloakrenaissance.com/paybycreditcard.asp";
	_checkout.submit();
}

function PayByPaypal(){
	
	var _cf = document.cardform;
	_cf.action="https://www.cloakrenaissance.com/paypal/revieworder.asp";
	_cf.submit();
}

//end new js code

//***
function payWithCard(){
 	var _true = getValue(1,'isReadyPaywithCard');
 	if(_true==null || _true==''){
 		$('CreditCardTable').style.display="block";
		setValue(1,'isReadyPaywithCard','true');
	}else{ 
			var f = checkcheckout();
			if(f==false){
				return false;
			}else{
				
			var _cardno = $('cardNo').value;
			var _cardname = $('cardName').value;
			var _cardcode = $('cardCode').value;
			
			if(_cardno==null || _cardno==''){
				alert("Card No is invalid !");
						setFocus('cardNo');
 						return false;}
			if(_cardname==null || _cardname==''){
				alert("Card Name is invalid !");
						setFocus('cardName');
 						return false;}
			if(_cardcode==null || _cardcode==''){
				alert("Secuirty Code is invalid !");
						setFocus('cardCode');
 						return false;}
			
 			var _checkout = document.checkoutForm;
			_checkout.action="bycreditcard.asp";
			_checkout.submit();
			}
	}
	
}

//***
function payWithPaypal(){
 			var f = checkcheckout();
			if(f==false){
				return false;
			}else{
   			var _checkout = document.checkoutForm;
			_checkout.action="bypaypal.asp";
			_checkout.submit();
			}
}

//***
function isInvalid(id){
	var _v = $(id).value;
	_v = _v.replace(/(^\s*)|(\s*$)/g, ""); 
 	if(_v==null || _v==''){
		return false;
	}
	return true;
 }

//**
 
function checkemail(str){
     var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
     var objExp=new RegExp(Expression);
     if(objExp.test(str)==true){
       return true;
     }else{
       return false;
     }
}

 function showPicture(srcPath)
{
 		var _pos = srcPath.lastIndexOf("\/");
		var _name = srcPath.substring(_pos+1);
		var _bigImage = srcPath.substring(0,_pos+1)+_name.replace("s","l");
		var _html="<a href='"+_bigImage+"' rel='lightbox[plants]'><img src='"+srcPath+"' border=0 /></a>";
		$('MiddlePicture').innerHTML=_html;
}
function sendSuggest(){
	var _msg = $('customersugest').value;
	var _email = $('customerEmail').value;
	if(_msg==null || _msg==""){return false;}
	if(_email==null || _email==""){return false;}
	if(!checkemail(_email)) {alert("Email is invalid!"); return false;}
	
	var _sku = $('productsku').value;
	var _email = $('customerEmail').value;
	var  regExp = new RegExp('\n','g');
    var _inf = _msg.replace(regExp,'<br/>');
	var _stock = $('skustock').innerHTML;
	if(_stock==null || _stock==''){
		_stock='Coming Soon';
	}
	
	openXHR();
  	var _url="/xml-customer-question.asp?sku="+_sku+"&email="+_email+"&info="+_inf+"&stk="+_stock;
	xhr.open("get",_url,true);
 	xhr.onreadystatechange=function(){
		if (xhr.readyState<4){
			$('customerquestion').innerHTML='Send data, wait...';
		}else{
			var doc = xhr.responseText;
			if(doc==1){
					var _return='You have successfully submitted the question, we will respond to you as soon as possible !';
					$('customerquestion').innerHTML=_return;
				}
		}
	}
	xhr.send(null);	

}

function goHere(sku){
		var _ps = $('product_'+sku).style;
		_ps.display='block';
	}
function outHere(sku){
		var _ps = $('product_'+sku).style;
		_ps.display='none';
	}
function goHerePopWin(sku){
		window.open('gohere.asp?sku='+sku,'gohere','left=200,top=200,width=600,height=600');
	}

function selectpayment(v){
if(v==0){
$('CreditCardTable').style.display='none';
}else{
$('CreditCardTable').style.display='block';
}
}

function sendEmailToUs(){
	document.msgform.action='sendemail.asp';
	document.msgform.submit();
}

//ship by paypal
function PaypalShip(_weight,_country,_state,_zip){
 	
	if(_state==null || _zip==null || _weight==null){
		$('showMsg').innerHTML='<font color=red>Sorry, we cann\'t calculate .</font>';
		return false;
	}
	
	openXHR();
 	var _url="/xml-rate-data.asp?country="+_country+"&state="+_state+"&zipcode="+_zip+"&weight="+_weight;
	xhr.open("get",_url,true);
	xhr.onreadystatechange=function(){
 		if (xhr.readyState<4){
			$("showMsg").innerHTML="<div align=center style='padding-top:50px'>Please Wait ...</div>";
		}else{
		var _listMsg='';
		var _errorMsg='';
		var dom=xhr.responseXML.documentElement;
		var _price=dom.getElementsByTagName("Price");
		var RoteString,RoteValue;
 		var Explain;
  	    // _listMsg+="<div>Weight: "+_weight+"</div>";
		for(var i=0;i<_price.length;i++){
			RoteString=_price[i].childNodes[0].nodeValue;
			RoteValue=RoteString.match(/\d+.\d+/);
			if(parseInt(RoteValue)>0){
 				if( RoteString.indexOf("Priority Mail")>0 ) { 
				Explain="Usps Priority - 1-5 days processing + 2-3 days transit"; }
				else if(RoteString.indexOf("Express Mail")>0 ){
				Explain="Usps Express - 1-2 days processing + 1 day transit"; }
				else {Explain="";}
				var _RoteInfo = RoteString+"|"+Explain;
  		 _listMsg+="<div><input style='border:none' type=\"radio\" name=\"Rote\" id=\"Rote_"+i+"\" value=\""+RoteValue+"\"  onclick=\"RecalcuateShipMoney(1,"+i+",'"+_RoteInfo+"')\"  id=\"p_"+i+"\"><span onclick=\"RecalcuateShipMoney(1,"+i+",'"+_RoteInfo+"')\"   style='cursor:pointer;font-size:12px;color:#0A93D6;'> &nbsp;" +RoteValue+'</span></div>';
		 _listMsg+="<div style='font-size:12px;color:#FF8000;padding-left:25px;padding-bottom:10px;'>"+Explain+"</div>";
 		}
		else{
 		_errorMsg="<div align=center style='color:red'>Sorry,Service not available for this country.</div>"
			}
 		}
		if(_errorMsg!=''){
		$("showMsg").innerHTML=_errorMsg;
		}else{
 		$("showMsg").innerHTML=_listMsg;
		}
 		}
		}
	xhr.send(null);
	
}


function PaypalShip2(_weight,_country,_state,_zip){
	if(_state==null || _zip==null || _weight==null){
		$('showMsg').innerHTML='<font color=red>Sorry, we cann\'t calculate .</font>';
		return false;
	}
 	
 	openXHR();
 	var _url="/xml-getship-cost.asp?country="+_country+"&state="+_state+"&zipcode="+_zip+"&weight="+_weight;
	 
	 
	
	xhr.open("get",_url,true);
	xhr.onreadystatechange=function(){
		

		if (xhr.readyState<4){
			$("showMsg").innerHTML="<div align=center>Please Wait ...</div>";
		}else{
		var _listMsg='';
		var _errorMsg='';
		var dom=xhr.responseText;
		 
		var _price=dom.split("|");
		var RoteString,RoteValue;
 		var Explain;
		 
 		for(var i=0;i<_price.length-1;i++){
			RoteString=_price[i];
			RoteValue=RoteString.match(/\d+.\d+/);
		 
			if(RoteValue!=null && parseInt(RoteValue)>0){
			 if(RoteString.indexOf("UspsIntl")>0){
				 Explain=RoteString.replace("g","").replace(/\d+.\d+/g,"");
			 }else{
 				if( RoteString.indexOf("Priority Mail")>0 ) { 
				Explain="Usps Priority - 1-5 days processing + 2-3 days transit"; }
				else if(RoteString.indexOf("Express Mail")>0 ){
				Explain="Usps Express - 1-2 days processing + 1 day transit"; }
 				else{
				Explain="";}
			 }
				var _RoteInfo = RoteString+"|"+Explain;
  		 _listMsg+="<div><input style='border:none' type=\"radio\" name=\"Rote\" id=\"Rote_"+i+"\" value=\""+RoteValue+"\"  onclick=\"RecalcuateShipMoney(1,"+i+",'"+_RoteInfo+"')\"  id=\"p_"+i+"\"><span style='font-size:12px;color:#0A93D6;'> $" +RoteValue+'</span></div>';
		 _listMsg+="<div style='font-size:12px;color:#FF8000;padding-left:25px; padding-bottom:10px;'>"+Explain+"</div>";
		 
		  

 		}
		else{
 		_errorMsg="<div align=center style='color:red'>Sorry, your city, state and zip code do not match.</div>"
			}
		
 		//document.write(_listMsg);
		 
		}
		
		 
		 
		if(_errorMsg!=''){
 		$("showMsg").innerHTML=_errorMsg;
		}else if(_listMsg!=''){
  		$("showMsg").innerHTML= _listMsg;
		}else{
			$("showMsg").innerHTML="<div align=center style='color:red'>Sorry,Service not available for this country.</div>"
		}
	}
	}
	xhr.send(null);
 }
 
 
 
 
function PayOver(){
	var _ship = $('shippingMoney').innerHTML;
	var _ship2 = $('shipPrice').value;
	var _phone = $('phone').value;
	var _p = _phone.Trim();
	if(_p==null || _p==''){
		alert("Please enter your phone number!");
		$('phone').focus();
		return false;
	}
	if(_ship==null || _ship=='' || _ship2==null || _ship2==''){
		alert("Please select the shipping methods!");
		return false;
	}
	document.shipform.action='https://www.cloakrenaissance.com/pay.asp';
	document.shipform.submit();
}
//end ship by paypal

 
 function getStates(v,idadrs,idselect){
	 clearShip();
 	var URL;
	var ajax = new MyAjaxRequest();
 	URL="/xmlCountry.asp?isoCode="+v;
	ajax.onreadystatechange=CallBack;
	 
	ajax.open("GET",URL,true);
 	ajax.send(null);	
		function CallBack() {
		if(ajax.readyState==4){
		 var getCodes=ajax.responseText;
		  
   		 if(getCodes!=null && getCodes!=''){
		  $(idadrs).innerHTML="<select name='"+idselect+"' id='"+idselect+"' style='width:150px'></select>";
		   $(idselect).length=0;
			var getCodesArray = getCodes.split('|');
				for(var i=0;i<getCodesArray.length;i++){
					var opt = new Option();
					var getString =  getCodesArray[i].split('-');
					opt.value =getString[1];
					opt.text = getString[0];
					$(idselect).options.add(opt);
				}//end for
			} 
		else{
			$(idadrs).innerHTML="<input type='text' name='"+idselect+"' id='"+idselect+"' width='150px'/>";
		 }//end if getCodes
  		}//end xhr readystate
	}//end callback 
}


function CalculateShip2(){
	var _place = $('shipTo').value;
 	var _c=getValue(0,'Country');
 	var _s;
	var _z;
 	var _w=getValue(0,'Weight');
	if(_place==1){
	var _shipcheck = checkShippingInformation();
	if(_shipcheck==false){
		return false;
	}
	}else{
		var _billcheck = checkBillingInformation();
		if(_billcheck==false){
			return false;
		}
	}
	$('RoteMessage').style.display='block';
	_c = (_place==1 ? getValue(0,'Countrys') : getValue(0,'Country'));
	_s = (_place==1 ? getValue(0,'States') : getValue(0,'State'));
	_z = (_place==1 ? getValue(0,'Zips') : getValue(0,'Zip'));
 	
 	openXHR();
 	var _url="/xml-getship-cost.asp?country="+_c+"&state="+_s+"&zipcode="+_z+"&weight="+_w;
	 
	 
	
	xhr.open("get",_url,true);
	xhr.onreadystatechange=function(){
		

		if (xhr.readyState<4){
			 
		}else{
			 
		var _listMsg='';
		var _errorMsg='';
		var dom=xhr.responseText;
		 
		var _price=dom.split("|");
		var RoteString,RoteValue;
 		var Explain;
		 
 		for(var i=0;i<_price.length-1;i++){
			RoteString=_price[i];
			RoteValue=RoteString.match(/\d+.\d+/);
		 
			if(RoteValue!=null && parseInt(RoteValue)>0){
			 if(RoteString.indexOf("UspsIntl")>0){
				 Explain=RoteString.replace("g","").replace(/\d+.\d+/g,"");
			 }else{
 				if( RoteString.indexOf("Priority Mail")>0 ) { 
				Explain="Usps Priority - 1-5 days processing + 2-3 days transit"; }
				else if(RoteString.indexOf("Express Mail")>0 ){
				Explain="Usps Express - 1-2 days processing + 1 day transit"; }
 				else{
				Explain="";}
			 }
				var _RoteInfo = RoteString+"|"+Explain;
  		 _listMsg+="<div><input style='border:none' type=\"radio\" name=\"Rote\" id=\"Rote_"+i+"\" value=\""+RoteValue+"\"  onclick=\"RecalcuateShipMoney(1,"+i+",'"+_RoteInfo+"')\"  id=\"p_"+i+"\"> $" +RoteValue+'</div>';
		 _listMsg+="<div style='font-size:12px;color:#FF8000;padding-left:25px; padding-bottom:10px;'>"+Explain+"</div>";
		 

 		}
		else{
 		_errorMsg="<div align=center style='color:red'>Sorry, your city, state and zip code do not match.</div>"
			}
		
 
		 
		}
		if(_errorMsg!=''){
		$("RoteMessage").innerHTML=_errorMsg;
		}else if(_listMsg!=''){
 		$("RoteMessage").innerHTML=_listMsg;
		}else{
			$("RoteMessage").innerHTML="<div align=center style='color:red'>Sorry, your city, state and zip code do not match.</div>"
		}
	}
	}
	xhr.send(null);
 }
 
 
function changeQty()
{
		document.cardform.action='saveChangeQty.asp';
		document.cardform.submit();
}
 
 
// ----------------------------------------- Vote for CR website -----------------------------------------------------------
var imageDir = "/products/images";
var imageArray = new Array("vote1.gif","vote2.gif","vote3.gif","vote4.gif","vote5.gif","vote_12.gif","vote_22.gif","vote_32.gif","vote_42.gif","vote_52.gif")

var startflash ;

function borderflash(id)
{
	document.getElementById(id).style.border='2px solid #FF0000';
	setTimeout("clearborderflash('"+id+"')",100);
	startflash = setTimeout("borderflash('"+id+"')",400);
 }

function clearborderflash(id)
{
	document.getElementById(id).style.border='2px solid #F7EBF7';
}

function stopborderflash()
{
	clearTimeout(startflash);
}

function VoteforProducts(votingsku,votes,userid)
{
 	for(var i=1;i<6;i++)
	{
 		$('VoteSKU_'+votingsku+'_'+i).src=imageDir+"/"+imageArray[i+4];
	}
	
	//borderflash("ProductSKU_"+votingsku);
	
  	var _url="/xml-vote.asp?sku="+votingsku+"&votes="+votes+"&userid="+userid;

	 
 
 	openXHR();
	xhr.open("get",_url,true);
 	xhr.onreadystatechange=function()
	{
		if (xhr.readyState<4)
		{
			  $('Vote_'+votingsku).innerHTML="<font size=1 color=#FF0080>Voting</font>";
		}
		else if(xhr.readyState==4)
		{
			var doc = xhr.responseText;
   			if(doc==1)
			{
				 $('Vote_'+votingsku).innerHTML="<font size=1 color=#C0C0C0>VOTED</font>";
				
					for(var i=1;i<6;i++)
					{
						if(votes!=i)
						{
 							$('VoteSKU_'+votingsku+'_'+i).src=imageDir+"/"+imageArray[i-1];
						}
					}
			//stopborderflash("ProductSKU_"+votingsku);
 			}
		}
	}
	xhr.send(null);	
}





function prevLoadImage()
{
 
	for(var i=0;i<imageArray.length;i++)
	{
		var image = new Image();
		image.src=imageDir+"/"+imageArray[i];
	}
}




function ebayCustomerVoteProducts(votingsku,filename,votes)
{
 
	
	borderflash("ProductSKU_"+votingsku);
	
  	var _url="/xml-ebaycustomer-vote.asp?sku="+votingsku+"&votes="+votes+"&filename="+filename;
 	for(var i=1;i<6;i++)
	{
 		$('VoteSKU_'+votingsku+'_'+i).src=imageDir+"/"+imageArray[i+4];
	}
 	
 	openXHR();
	 
	
	xhr.open("get",_url,true);
	alert("Vote");
	
 	xhr.onreadystatechange=function()
	{
		if (xhr.readyState<4)
		{
			  $('VoteStatus').innerHTML="<font size=2 color=#FF0080><b>Voting</b></font>";
		}
		else if(xhr.readyState==4)
		{
			var doc = xhr.responseText;
			alert(doc);
   			if(doc==1)
			{
				 $('VoteStatus').innerHTML="<font size=2 color=#FF80FF>Thanks for your vote!</font>";
				
					for(var i=1;i<6;i++)
					{
						if(votes!=i)
						{
 							$('VoteSKU_'+votingsku+'_'+i).src=imageDir+"/"+imageArray[i-1];
						}
					}
				stopborderflash("ProductSKU_"+votingsku);
 			}
		}
	}
	xhr.send(null);	
}



var MyXHR;
function openMyXHR(){
		try{
			MyXHR=new ActiveXObject("Msxml2.XMLHTTP");		
			}catch(e){
				try{
						MyXHR=new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){
						MyXHR=false;
						}
				}
		if(!MyXHR && typeof XMLHttpRequest !="undefined"){
			MyXHR=new XMLHttpRequest();
			}
		return MyXHR;
}

function addToMyfriend()
{
 	var _profileID = document.getElementById('add_profileid').value;
	var _userID = document.getElementById('add_userID').value;
	var _username = document.getElementById('add_profile_username').value;
 	
	if(_profileID==null || _profileID=="" || _userID==null || _userID=="")
	{
		alert("You must be  logged in to add "+_username+" to friend.");
	}
	else
	{
		var _url = "/addtomyfriends.asp?profileID="+_profileID+"&userID="+_userID+"&username="+_username;
		window.open(_url,"win","left=300,top=200,width=500,height=500");
	}
}
function SendMessage(fromID,toID)
{
	if(fromID==null || fromID=="")
	{
		alert("You need login first.");
		return false;
	}
	window.open("/sendEmailtoFriends.asp?fromID="+fromID+"&toID="+toID,"SendEmail","width=600,height=600,left=400,top=280");
}

// vote for .net 
function VoteforProductsByNet(votingsku,votes,userid)
{
	
	
  	var _url="/save-score-products-votedata.aspx?sku="+votingsku+"&votes="+votes+"&userid="+userid;

 	openXHR();
	
	
	
	xhr.open("get",_url,true);
 	xhr.onreadystatechange=function()
	{
		if (xhr.readyState<4)
		{
			  $('Vote_'+votingsku).innerHTML="<font size=1 color=#FF0080>Voting</font>";
		}
		else if(xhr.readyState==4)
		{
			var doc = xhr.responseText;
			 
   			if(doc==1)
			{
				 $('Vote_'+votingsku).innerHTML="<font size=1 color=#C0C0C0>VOTED</font>";
 			}
		}
	}
	xhr.send(null);	
}


// vote for .net 
function VoteforCustomerProductsByNet(votingpId,votes,userid)
{
	
	
  	var _url="/save-adult-costume-contest-vote.aspx?pid="+votingpId+"&votes="+votes+"&userid="+userid;

 	openXHR();
	
	
	
	xhr.open("get",_url,true);
 	xhr.onreadystatechange=function()
	{
		if (xhr.readyState<4)
		{
			  $('Vote_'+votingpId).innerHTML="<font size=1 color=#FF0080>Voting</font>";
		}
		else if(xhr.readyState==4)
		{
			var doc = xhr.responseText;
			 
   			if(doc==1)
			{
				 $('Vote_'+votingpId).innerHTML="<font size=1 color=#C0C0C0>VOTED</font>";
 			}
		}
	}
	xhr.send(null);	
}


