function imageOver(obj,str){
 	obj.src="/wp-content/themes/true/images/icon-"+str+"~.png"
}


function imageOut(obj,str){
	obj.src="/wp-content/themes/true/images/icon-"+str+".png"
}


var xmlHttp;

function createAjax(){
try
  { 
  // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest(); 
if ( xmlHttp.overrideMimeType ) xmlHttp.overrideMimeType ( "text/xml" ); 
  }
  catch (e)
	    { 
	  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; 
	      } 
	    } 
	 } 
  }
var xmlHttpStr="";
var divScrollTop=0;

function ajaxFunction(str,flag){
createAjax();
if(flag!="widget")document.getElementById("formDiv").innerHTML="<h3>Please wait</h3>";
xmlHttp.open("GET","/wp-content/themes/true/signup.php?email=" + str ,true);
xmlHttp.send(null); 
  xmlHttp.onreadystatechange=function(){
		 if(xmlHttp.readyState==4){
			xmlHttpStr=xmlHttp.responseText;
			if(xmlHttpStr==1){
					if(flag=="widget"){
						document.getElementById("submitBtn").style.display="none";
						document.getElementById("signup").style.display="none";
						document.getElementById("signupWrap").style.background="none";
						document.getElementById("signupWrap").innerHTML="<p>Thanks, we'll be in touch.</p>";						
					}
					else
					{
					document.getElementById("formDiv").style.display="none";
					document.getElementById("thanks").style.display="block";
					}
				}
				else
				{
				alert("There was a problem.");
				}
			}
		}

  }








function isEmail(str,flag)
{
	var arrAt = str.split("@");
	if (arrayHasEmpty(arrAt)){alert("Please enter a valid email"); return false;}
	if (arrAt.length >= 2)
	{
		var arrPeriod = arrAt[1].split(".");
		if (!arrayHasEmpty(arrPeriod) && arrPeriod.length >= 2) {ajaxFunction(str,flag); return false;}
	};
	alert("Please enter a valid email");
	return false;
}

function arrayHasEmpty(arr)
{
	for (var a in arr)
	{
		if (arr[a] == "") return true;
	};
	return false;
}


function checkPostCode (toCheck) {

  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  var pcexp = new Array ();
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  var postCode = toCheck;
  var valid = false;
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
      pcexp[i].exec(postCode);
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      valid = true;
      break;
    }
  }
  if (valid) {return postCode;} else return false;
}


function checkContact (obj) {
	if(obj.name.value=="" || obj.name.value=="Name" || obj.coname.value=="" || obj.coname.value=="Company name"){
		alert("Please enter your name and Company name");
		return false;
	}
	if(!isEmail(obj.email.value)){
		alert("Please enter a valid email address");
		return false;
		}
	return true;
}
