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 MP_openBrWindow(theURL,winName,features, wid, hei) {//v2.0 modified
LeftPosition = (screen.width) ? (screen.width-wid)/2 : 0;
TopPosition = (screen.height) ? (screen.height-hei)/2 : 0; 
featuresAll = features + ',top ='+TopPosition+',left='+LeftPosition
  window.open(theURL,winName,featuresAll);
}
 
 
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)


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);
}


function filter2Num(  )
{ 

 var args = filter2Num.arguments;  
 instr = "" + args[0];

 if ( args.length == 2 )
	maxDecimalPlaces = parseInt( 0 + args[1]  );
 else
	maxDecimalPlaces = 100;

 zeroes=0;

 if (instr == "")
	  return 0;

 isANum = "";


 passedDecimalPoint = false;
 numDecimalPlaces = 2;

 for ( k=0 ; k < instr.length; k++ ) {

    check = instr.charAt(k)


    if (( check == "$" )&&( isANum.length > 1 ) ){
     	break;
    }

    if ( ( check == "." ) && ( !passedDecimalPoint ) ) {
      isANum = isANum + ".";
      passedDecimalPoint = true;
    }

    if ( ( k==0 ) && (check == "-" ) ) {
      isANum = "-" + isANum ;
    }

    if (  !isNaN(parseInt(check)) && ( check != "$" ) && ( check != "," )  ) {
    	isANum = isANum + check;
    }

    if ( passedDecimalPoint ) {
        numDecimalPlaces++;
        if (numDecimalPlaces > maxDecimalPlaces) 
           break;
    }

 }


 if ( isANum == ""  )
	return 0;
 else {
	temp = parseFloat( isANum );
  return temp;
  }

}

function fmtPrice(value) {


// WORK OUT THE ROUNDING

    if (Math.floor(value)<0) { // If it is a negative number
      DollarAmt = Math.ceil(value); 
      var cents=100*(Math.abs(value)-Math.abs( Math.ceil(value)))+0.5; // and cents is betweeen 99 and 00 ie: 9975
      if ( cents > 100 ) {
        DollarAmt--; // Reduce the dollar amount by 1
        cents = cents - 100; // And set up cents
      }
    }
    else { // Its a positive number, so rounding up means increasing value.
      DollarAmt = Math.abs(Math.floor(value));
      var cents=100*(value-Math.floor(value))+0.5; // is cents between 99 and 00 ie: 9975
      if ( cents > 100 ) {    
        DollarAmt++;  // increase the dollar amount
        cents = cents - 100; // reset cents.
      }
    }


// WORK OUT THE , 's

    DollarAmt = DollarAmt + ""; // type cast?!?
    
    if (DollarAmt.charAt(0)=='-') DollarAmt=DollarAmt.substr(1); // chop the signage.
    
    NewLookDollarAmt = "";
    for (x=DollarAmt.length-1; x>=3; x-=3) // go backwards through the dollar amt stopping at every third number
      NewLookDollarAmt = ',' + DollarAmt.charAt(x-2) + DollarAmt.charAt(x-1) + DollarAmt.charAt(x) + NewLookDollarAmt;
      // If we find a 3rd number, append a , to the front, the three numbers, and then anything we found before. iterative gives:
      // number = 123456789, x=9 ,NLDA = "", step, NLDA = ","+"7"+"8"+"9"+NLDA = ",789"
      // step, x=6, LDA = ",456,789"
      // step, x=3, outside of loop,
      
    for (y=x;y>=0;y--) NewLookDollarAmt = DollarAmt.charAt(y) + NewLookDollarAmt; // Append the first few numbers to the front


// WORK OUT THE DECIMAL POINT

    if (Math.floor(value) == value) { // Check if the value has no dec point.
      if (Math.floor(value) < 0) {
        return("-$"+ NewLookDollarAmt); // PLEASE NOTE: These RETURN they do not change RESULT
      }
      else {
        return("$"+ NewLookDollarAmt);
      }
    }    
    if (Math.floor(value) < 0 )  { // if it does, draw it
       result ="-$" + NewLookDollarAmt +"."; // PLEASE NOTE: These change RESULT and DO NOT RETURN
    }
    else {
       result ="$" + NewLookDollarAmt +".";
    }
    
    result += Math.floor(cents/10); //
    result += Math.floor(cents%10);
    return result; // Coz this is where the returning happens, after appending the cents :)
}





function checkpostcode(fn, formfield, returnto)
{
var formname = fn.name
var suburb = eval("document."+formname+"."+formfield+".value")
//alert (suburb)
if (suburb == ""){
alert("Please enter your suburb.")
return false;
}else{
var postpage = "postcodechecker.asp?suburb="+suburb+"&fn="+formname+"&returnto="+returnto
MP_openBrWindow(postpage,"postcodecheck","scrollbars=yes, width=300,height=300, resizable=yes", "300", "300")
  }
}

function insertpostcode(pc, fname, returncode){
	
eval("document."+fname+"."+returncode+".value = "+pc)

}




function CheckForm_contact()
{
if(document.contact.Email.value.length<1)
	{
	    alert("Please fill the Email item");
	    document.contact.Email.focus();
        return false;
	}
if (document.contact.Email.value.charAt(0)=="." ||        
         document.contact.Email.value.charAt(0)=="@"||       
         document.contact.Email.value.indexOf('@', 0) == -1 || 
         document.contact.Email.value.indexOf('.', 0) == -1 || 
         document.contact.Email.value.lastIndexOf("@")==document.contact.Email.value.length-1 || 
         document.contact.Email.value.lastIndexOf(".")==document.contact.Email.value.length-1)
     {
      alert("Incorrect format of the Email Address");
      document.contact.Email.focus();
      return false;
      }
 }

function MP_openBrWindow(theURL,winName,features, wid, hei) {//v2.0 modified
LeftPosition = (screen.width) ? (screen.width-wid)/2 : 0;
TopPosition = (screen.height) ? (screen.height-hei)/2 : 0; 
featuresAll = features + ',top ='+TopPosition+',left='+LeftPosition
  window.open(theURL,winName,featuresAll);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

