function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}



function checkuserinfo()
{
 if(document.userinfo.useremail.value.length!=0)
  {
    if (document.userinfo.useremail.value.charAt(0)=="." ||        
         document.userinfo.useremail.value.charAt(0)=="@"||       
         document.userinfo.useremail.value.indexOf('@', 0) == -1 || 
         document.userinfo.useremail.value.indexOf('.', 0) == -1 || 
         document.userinfo.useremail.value.lastIndexOf("@")==document.userinfo.useremail.value.length-1 || 
         document.userinfo.useremail.value.lastIndexOf(".")==document.userinfo.useremail.value.length-1)
     {
      alert("Incorrect Email Address format ! ");
      document.userinfo.useremail.focus();
      return false;
      }
   }
 else
  {
   alert("Please fill in the Email Address !");
   document.userinfo.useremail.focus();
   return false;
   }
}

function check0()
{
   if(checkspace(document.shop0.username.value)) {
	document.shop0.username.focus();
    alert("Please fill in the User Name!");
	return false;
  }
  }



function trans_form()
{
var f
f = document.receiveaddr

f.billing_name.value = f.realname.value
f.billing_surname.value = f.surname.value
f.billing_email.value = f.delivery_email.value
f.billing_address1.value = f.address.value
f.billing_address2.value = f.city.value
f.billing_address3.value = f.userqq.value
f.billing_postcode.value = f.postcode.value
f.billing_telg.value = f.usertelg.value
f.billing_tel.value = f.usertel.value
f.billing_mobileg.value = f.usermobileg.value
f.billing_mobile.value = f.usermobile.value


}

function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}


function regInput(obj, reg, inputStr)
	{
		var docSel	= document.selection.createRange()
		if (docSel.parentElement().tagName != "INPUT")	return false
		oSel = docSel.duplicate()
		oSel.text = ""
		var srcRange	= obj.createTextRange()
		oSel.setEndPoint("StartToStart", srcRange)
		var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
		return reg.test(str)
	}



function DrawImage(ImgD){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= 100/100){
     if(image.width>100){  
     ImgD.width=100;
     ImgD.height=(image.height*100)/image.width;
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }

     }
    else{
     if(image.height>100){  
     ImgD.height=100;
     ImgD.width=(image.width*100)/image.height;     
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }

     }
    }
   }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
 }
 
function view(what) { 

		var imgwin = window.open("",'WIN','scrollbars=no,status=no,toolbar=no,resizable=1,location=no,menu=no,width=10,height=10'); 
		imgwin.focus(); 
		imgwin.document.open(); 
		imgwin.document.write("<html>\n"); 
		imgwin.document.write("<head>\n"); 
		imgwin.document.write("<title>Full Size</title>\n"); 

		imgwin.document.write("<sc"+"ript>\n"); 
		imgwin.document.write("function resize() {\n"); 
		imgwin.document.write("pic = document.il;\n"); 
		imgwin.document.write("if (eval(pic).height) { var name = navigator.appName\n"); 
		imgwin.document.write("  if (name == 'Microsoft Internet Explorer') { myHeight = eval(pic).height + 40; myWidth = eval(pic).width + 12;\n"); 
		imgwin.document.write("  } else { myHeight = eval(pic).height + 9; myWidth = eval(pic).width; }\n"); 
		imgwin.document.write("  clearTimeout();\n"); 
		imgwin.document.write("  var height = screen.height;\n"); 
		imgwin.document.write("  var width = screen.width;\n"); 
		imgwin.document.write("  var leftpos = width / 2 - myWidth / 2;\n"); 
		imgwin.document.write("  var toppos = height / 2 - myHeight / 2; \n"); 
		imgwin.document.write("  self.moveTo(leftpos, toppos);\n"); 
		imgwin.document.write("  self.resizeTo(myWidth, myHeight);\n"); 
		imgwin.document.write("}else setTimeOut(resize(), 100);}\n"); 
		imgwin.document.write("</sc"+"ript>\n"); 

		imgwin.document.write("</head>\n"); 
		imgwin.document.write('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">\n'); 

		imgwin.document.write("<a href='javascript:window.close()'><img border=0 src='"+what+"' xwidth=100 xheight=9 name=il onload='resize();'></a>\n"); 
		imgwin.document.write("</body>\n"); 
		imgwin.document.close(); 

	} 


function submit_billing_address(submitType){
    if(submitType==1)
        billing_address.action='?action=save_billing_address';
    else
        billing_address.action='?action=save_billing_address&methord=SameAddress';
    billing_address.submit();
} 

function submit_delivery_address(submitType){
    if(submitType==1)
        delivery_address.action='?action=save_delivery_address';
    else
        delivery_address.action='?action=save_delivery_address&methord=SameAddress';
    delivery_address.submit();
}



function count_total_spend()
{
var f
f = document.receiveaddr

if ((f.donationfee.value)=="")

f.total_spend.value = parseInt(f.total_spend_before.value)


else

f.total_spend.value = parseInt(f.total_spend_before.value) + parseInt(f.donationfee.value)


f.total_spend.value = formatAsMoney(parseInt(f.total_spend.value));
f.total_spend3.value = formatAsMoney(parseInt(f.donationfee.value));


}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}
