function validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,nm2,test,eql,iseql,num,min,max,errors='',args=validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { 
	  test=args[i+2];
	  iseql=args[i+1];
	  eql=document.getElementById(args[i+1]);
	  val=document.getElementById(args[i]);


      if (val) { 
	    nm=val.title;
		if ((val=val.value)!="") {
		  if (iseql!=""){
			nm2 = eql.title;
			if (eql.value!=val) errors+='- '+nm+' and '+nm2+' must be equal\n';
		  }
          if (test.indexOf('isEmail')!=-1) { 
		    p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { 
		    num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { 
			  p=test.indexOf(':');
              min=test.substring(8,p); 
			  max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
            } 
	      } 
		} else if (test.charAt(0) == 'R') 
		errors += '- '+nm+' is required.\n'; 
	  }
  
	  
    } 
	
	//check if email exists
	if (errors) {
		alert('The following error(s) occurred:\n' + errors);
	}
	document.returnValue = (errors == '');
  } 
}

function changeInputType(prevObject, type) {
    var passInput = document.createElement('input');
    passInput.setAttribute('type', type);
    passInput.setAttribute('name', prevObject.getAttribute('name'));
    passInput.className = 'loginfield';
    passInput.id = 'passInput';
    prevObject.parentNode.replaceChild(passInput, prevObject);
 
    setTimeout("focusInput('passInput');", 1);
}

function focusInput(objectID) {
    document.getElementById(objectID).focus();
}

//add forms
function makeForm() {	
	ltl=document.getElementById("league_teams_list");
	myinput = document.createElement("input");
	myinput2 = document.createElement("input");
	number=document.getElementById("num");
	tbodi = document.createElement('tbody');
	tr = document.createElement('tr');
	td1 = document.createElement('td');
	td2 = document.createElement('td');
	td3 = document.createElement('td');
	td4 = document.createElement('td');
	tr2 = document.createElement('tr');
	td5 = document.createElement('td');
	hr = document.createElement('hr');
	//aboveteams01=document.getElementById("aboveteams");
	//heigh = parseInt(aboveteams01.style.height);
	//aboveteams01.style.height = heigh + 30 + 'px';

	tname = document.createTextNode("Team Name:");
	temail = document.createTextNode("Owners Email:");
	
	td5.setAttribute('colSpan',4);
	
	numbvalue = parseInt(number.value);
	numbvalue = numbvalue + 1;
	number.value = numbvalue;
	
	myinput.name="tname"+numbvalue;
	myinput2.name="omail"+numbvalue;
	td1.appendChild(tname);
	td2.appendChild(myinput);
	td3.appendChild(temail);
	td4.appendChild(myinput2);
	td5.appendChild(hr);
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);
	tr2.appendChild(td5);
	tbodi.appendChild(tr);	
	tbodi.appendChild(tr2);
	ltl.appendChild(tbodi);
}

function addnum() {
	number2=document.getElementById("number");
	numbvalue2 = parseInt(number2.value);
	for (i=1;i<=numbvalue2;i++){
		makeForm();
	}

}

function loadstart8() {
	for (i=1;i<=8;i++){
		makeForm();
	}

}


//validate form input

function compare(elementone,elementtwo,img)
{
var img_email;
var first;
var sec;
img_email = document.getElementById( img );
first = document.getElementById( elementone );
sec = document.getElementById( elementtwo );
	if ((first.value=='')&&(sec.value=='')){
		img_email.src = 'templates/images/spacer.gif';
	} else if (first.value!=sec.value){
		img_email.src = 'templates/images/aff_cross.gif';
	} else {
		img_email.src = 'templates/images/aff_tick.gif';
	}
}

function calculate()
{
var num = parseFloat(document.getElementById( 'planprice' ).innerHTML)-parseFloat(document.getElementById( 'plandiscount' ).innerHTML);
var result = num.toFixed(2);
document.getElementById( 'plantotal' ).innerHTML=result;
}

function code()
{
var xmlHttp;

var img_email;
img_email = document.getElementById( 'img-coupon' );

if(document.signup.coupon.value==''){
img_email.src = 'templates/images/spacer.gif'; 
exit; 
}

try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      if(xmlHttp.responseText==''){
      		document.getElementById( 'plandiscount' ).innerHTML='0.00';
  			img_email.src = 'templates/images/aff_cross.gif';     		
      	} else {
			discunt = parseFloat(document.getElementById( 'planprice' ).innerHTML)/100*xmlHttp.responseText;
      		document.getElementById( 'plandiscount' ).innerHTML = discunt.toFixed(2);
      		img_email.src = 'templates/images/aff_tick.gif';  
      	}
      calculate();
      }
    }
  xmlHttp.open("GET","check_coupon.php?id="+document.signup.coupon.value,true);
  xmlHttp.send(null);
  }
  
  function validate()
  {
  
  }
