function checker()
{
  var errors = false;
  var first;

  for(i=0; i<document.contact.elements.length; i++)
  {
	if(document.contact.elements[i].type != "checkbox" && document.contact.elements[i].type != "submit" && document.contact.elements[i].type != "reset" && document.contact.elements[i].type != "hidden" && document.contact.elements[i].type != "radio") {
	   if(document.contact.elements[i].value == "") {
		if(!errors) {
		   first = i;
		   errors = true;
		}
		document.contact.elements[i].style.backgroundColor="#e3f1d8";
	   } else {
		document.contact.elements[i].style.backgroundColor="#ffffff";
	   }
	}
  }

  if(errors) {
	alert('All Fields Are Required');
	document.contact.elements[first].focus();
	return false;
  }

  if(echeck(document.contact.from.value)) {
	document.contact.from.style.backgroundColor="#ffffff";
  } else {
	document.contact.from.focus();
	document.contact.from.style.backgroundColor="#e3f1d8";
	alert('Invalid Email Address');
	return false;
  }

  return true;
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;				
	}

function makeactive(tab) { 
 document.getElementById("tab1").className = ""; 
 document.getElementById("tab2").className = ""; 
 document.getElementById("tab3").className = ""; 
 document.getElementById("tab"+tab).className = "active"; 
 callAHAH('aff_statsc.php?content=' + tab + '&id=' + parseInt(Math.random()*99999999) + '&u=' + user + '&p=' + pwd, 'tabcontent', 'Querying database. Please wait...', 'Error');
} 

function imagecat(obj) { 
 callAHAH('includes/templateimages.php?cat=' + obj.options[obj.selectedIndex].value + '&id=' + parseInt(Math.random()*99999999), 'images', 'Getting images. Please wait...', 'Error');
 
}

function imagecatstart() { 
 callAHAH('includes/templateimages.php?cat=1&id=' + parseInt(Math.random()*99999999), 'images', 'Getting images. Please wait...', 'Error');
} 

function callAHAH(url, pageElement, callMessage, errorMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseAHAH(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
  }

function responseAHAH(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
         } else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
         }
      }
  }