// JavaScript Document

//clear initial text of a field when it's clicked
function clrInitTxt(field,initText,removeClass,blurred,password){
	if(blurred && field.value==''){
		field.value=initText;
		if(password) field.type="text";
		$(field).addClass(removeClass);
		return;	
	}
	if(field.value==initText) field.value='';
	if($(field).hasClass(removeClass)) $(field).removeClass(removeClass);
	if(password) field.type="password";
} 

var paymentSubmitted=false;
function submitPaymentOnlyOnce(){
	if( paymentSubmitted ){		
		return false;
	} 
	var submitBtn = document.getElementById('submitPaymentBtn'); 
	submitBtn.disabled=true;
	submitBtn.value='Sending Payment...'
	
	var throbber=document.getElementById('paymentSubmittedThrobber');
	throbber.style.display='inline';
	
	paymentSubmitted=true;
	return true;
}


function checkEmails() {
	var email1 = document.getElementById('form1').user_email.value;
	var email2 = document.getElementById('form1').user_email2.value;
	if (email1 == email2) { 
		document.getElementById('form1').submit();
	} else {
		alert("Your e-mail addresses did not match!");
	}
}

var tonyPopup = new TonyPopup(); 
window.addEvent('domready',function(){ tonyPopup.init(); });


//disable submit button after clicked
function submitOnce(obj){
	$(obj).value='Processing ...';	
	$(obj).onclick=function(){return false;};	
	return true;	
	}

//Serialize form data to POST string
function formSubmitStr(obj){
      var s='';
	  o=$(obj);
      for (i=0; i<o.elements.length; i++) {
		 n=o.elements[i];
         if (n.tagName == "INPUT") {
            if (n.type == "text")
               s += n.name + "=" + encodeURI(n.value)+ "&";
            else if (n.type == "checkbox"){
               if (n.checked)
                  s += n.name + "=" + encodeURI(n.value) + "&";
               else s += n.name + "=&";
			} else if (n.type == "radio"){
               if (n.checked)
                  s += n.name + "=" + encodeURI(n.value) + "&";
			} else s += n.name + "=" + encodeURI(n.value) + "&";
         }		 
         if (n.tagName == "SELECT")
            s += n.name + "=" + encodeURI(selectVal(n)) + "&";
         if (n.tagName == "TEXTAREA")
            s += n.name + "=" + encodeURI(n.value)+ "&";		
      }//for
	  return s;
	}//formSubmitStr