var email="";
var password="";
var password_md5="";
var firstname="";
var lastname="";
var today=new Date();
var dob=new Date(today.getFullYear()-20,today.getMonth(),today.getDate());
var country="";
var countryName="";
var emailInputObject=null;
var usernameInputObject=null;
var lastCountrySearch="";
var theCountrySearchField=null;
var junk_output;
var warnings=[];

function displaySignup() {
    country=document.getElementById("defaultCountry").value;
    countryName=document.getElementById("defaultCountryName").value;



    contentHTML="<div id=\"registrationArea\">";
    contentHTML+="<table style=\"font-size:11px\" cellspacing=\"8\"><tr><td class=\"floatingHead\" colspan=\"3\"><img src=\"/skin/close.png\" style=\"cursor:pointer\" onclick=\"removeWarnings();startFadeDown()\" align=\"right\" />";
    contentHTML+="<b>SIGN UP</b>";
    contentHTML+="</td></tr>";


	contentHTML+="<input type=\"hidden\" name=\"day\" value=\"0\" />";
	contentHTML+="<input type=\"hidden\" name=\"month\" value=\"0\" />";
	contentHTML+="<input type=\"hidden\" name=\"year\" value=\"0\" />";
    contentHTML+="<tr><td align=\"right\">Username</td><td>"+inputSurround("username","<input type=\"text\" onkeyup=\"checkUsername(this)\" maxlength=\"50\" class=\"standardInput\" id=\"username\" title=\"Required\" />",false)+"</td></tr>";
    contentHTML+="<tr><td align=\"right\">Password</td><td>"+inputSurround("password","<input type=\"hidden\" id=\"md5\" /><input type=\"password\" onkeyup=\"checkPassword(this,3,50)\" maxlength=\"50\" class=\"standardInput\" id=\"password\" title=\"Required\" />",false)+"</td></tr>";
    contentHTML+="<tr><td align=\"right\">Email</td><td>"+inputSurround("email","<input type=\"text\" onkeyup=\"checkEmail(this)\" maxlength=\"100\" class=\"standardInput\" id=\"email\" title=\"Required\" />",false)+"</td></tr>";
    contentHTML+="<tr><td colspan=\"3\">&nbsp;</td></tr>";
    contentHTML+="<tr><td align=\"right\">Firstname</td><td>"+inputSurround("firstnameInput","<input type=\"text\" onkeyup=\"checkLength(this,1,50)\" maxlength=\"50\" class=\"standardInput\" id=\"firstnameInput\" title=\"Required\" />",false)+"</td><td style=\"font-size:9px;color:#5d5252\"><span id=\"firstnameInputComment\"></span></td></tr>";
    contentHTML+="<tr><td align=\"right\">Lastname</td><td>"+inputSurround("lastnameInput","<input type=\"text\" onkeyup=\"checkLength(this,1,50)\" maxlength=\"50\" class=\"standardInput\" id=\"lastnameInput\" title=\"Required\" />",false)+"</td><td style=\"font-size:9px;color:#5d5252\"><span id=\"lastnameInputComment\"></span></td></tr>";
    contentHTML+="<tr><td align=\"right\">Date of birth</td><td>";
    contentHTML+=inputSurround("dobText","<div class=\"standardInput\" style=\"cursor:pointer\" onclick=\"openTheCalendar(this)\" id=\"dobText\" title=\"Required\"> - </div>",false);
    contentHTML+="</td></tr>";
    contentHTML+="<tr><td align=\"right\">Country</td><td>";
    countryStyle=false;
    if (country!="") countryStyle=true;
    contentHTML+=inputSurround("countrySearchField","<input type=\"text\" id=\"countrySearchField\" onkeyup=\"findCountries(this)\" onclick=\"resetCountry(this)\" onkeydown=\"javascript:return checkKey(event)\" class=\"standardInput\" title=\"Required\" value=\""+countryName+"\" />",countryStyle);
    contentHTML+="</td><td style=\"font-size:9px;color:#5d5252\"></td></tr>";

			
	contentHTML+="<tr><td style=\"text-align:center\" colspan=\"2\" class=\"floatingFoot\">";
	
		
	//contentHTML+="<input type=submit value=\"Log In\" />";
	contentHTML+="<img id=\"saveProfileButton\" src=\"/skin/signup.gif\" style=\"cursor:pointer\" onmouseover=\"javascript:this.src='/skin/signupOver.gif'\" onmouseout=\"javascript:this.src='/skin/signup.gif'\" onclick=\"saveProfile()\" />";
    
	contentHTML+="</td></tr>";
	contentHTML+="</table></div>";
    
    
    pasteRawHTML(returnRoundedBox("dialogBox",350,contentHTML,55,"lb"),document.body);
    fader(document.getElementById("dialogBox"),0);
    centerObject(document.getElementById("dialogBox"));
    document.getElementById("username").focus();
    startFadeUp();
}

function showWarning(id,message,target) {
    message=message.replace(" ","&nbsp;");
    if (message=="") {
        removeTheNode(id+"Container");
        
    }else{
        if (document.getElementById(id+"Container")) {
            document.getElementById(id).innerHTML=message;
        }else{
            contentHTML="<table id=\""+id+"Container\" cellpadding=0 cellspacing=0 style=\"border:none;z-index:56;position: absolute;\"><tr><td><img src=\"/skin/warningLeft.png\" /></td><td style=\"background-color:#fe9d5d;font-size:9px;color:#000\" id=\""+id+"\">"+message+"</td><td><img src=\"/skin/warningRight.png\" /></td></tr></table>";
            pasteRawHTML(contentHTML,document.body);
            alignObjectLeftTopWithTargetRightMiddle(document.getElementById(id+"Container"),target);
            warnings.push(id+"Container");
        }
    }
}
function removeWarnings() {
    for(i=0;i<warnings.length;i++) {
        removeTheNode(warnings[i]);
    }
    warnings=[];
}
function displayLogin() {
    contentHTML="<form id=\"loginform\" action=\"/forum/login.php\" method=post onsubmit=\"md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf)\">";
	contentHTML+="<table style=\"font-size:11px\" cellspacing=\"8\"><tr><td class=\"floatingHead\" colspan=\"2\"><img src=\"/skin/close.png\" style=\"cursor:pointer\" onclick=\"startFadeDown()\" align=\"right\" /><b>LOGIN</b></td></tr>";
	contentHTML+="<input type=hidden name=s value="+document.getElementById("sesh").value+" />";
	contentHTML+="<input type=hidden name=do value=login />";
	contentHTML+="<input type=hidden name=vb_login_md5password />";
	contentHTML+="<input type=hidden name=vb_login_md5password_utf />";
	//contentHTML+="<script type=text/javascript src=\"forum/clientscript/vbulletin_md5.js\"></script>";
	contentHTML+="<tr><td>";
	contentHTML+="User&nbsp;Name:&nbsp;</td><td>";
	contentHTML+=inputSurround("vb_login_username","<input name=vb_login_username type=text id=vb_login_username size=10 class=\"standardInput\" />");
			
	contentHTML+="</td></tr><tr><td>";
	contentHTML+="Password:&nbsp;</td><td>";
	contentHTML+=inputSurround("vb_login_password","<input name=vb_login_password id=vb_login_password type=password size=10 class=\"standardInput\" />");
	contentHTML+="</td></tr><tr><td>&nbsp;</td><td>";
		
	contentHTML+="<label for=cb_cookieuser_navbar><input name=cookieuser type=checkbox id=cb_cookieuser_navbar value=1 checked=checked />";
	contentHTML+="Remember Me?<br /></label>";
	contentHTML+="</td></tr><tr><td style=\"text-align:center\" colspan=\"2\" class=\"floatingFoot\">";
	
		
	//contentHTML+="<input type=submit value=\"Log In\" />";
	//contentHTML+="<img id=\"loginButton\" src=\"/skin/login.gif\" style=\"cursor:pointer\" onmouseover=\"javascript:this.src='/skin/loginOver.gif'\" onmouseout=\"javascript:this.src='/skin/login.gif'\" onclick=\"checklogin()\" />";
    contentHTML+="<img id=\"loginButton\" src=\"/skin/login.gif\" style=\"cursor:pointer\" onmouseover=\"javascript:this.src='/skin/loginOver.gif'\" onmouseout=\"javascript:this.src='/skin/login.gif'\" onclick=\"document.getElementById('loginform').submit()\" />";
    
	contentHTML+="</td></tr>";
	contentHTML+="<tr><td colspan=\"2\">";
	//contentHTML+="<div id=\"forgotOpener\" style=\"text-align:right\"><span style=\"color:#9ea9b6;font-size:11px;cursor:pointer\" onmouseout=\"javascript:this.style.color='#9ea9b6'\" onmouseover=\"javascript:this.style.color='#fe9d5d'\" onclick=\"getMyPassword()\">forgotten password?</span></div>";
	//contentHTML+="<div id=\"forgot\" style=\"display:none\">Enter your email address here...<br />";
	//contentHTML+=inputSurround("forgot_email","<input name=forgot_email id=forgot_email type=text size=10 class=\"standardInput\" />");
	contentHTML+="<a href=\"/forum/login.php?do=lostpw\" id=\"forgotbutton\" style=\"color:#9ea9b6;font-size:12px;cursor:pointer\" >forgotten password?</a>";
	contentHTML+="</td></tr>";
	
	
	contentHTML+="</table>";
    


    
	contentHTML+="</form>";
	
    pasteRawHTML(returnRoundedBox("dialogBox",350,contentHTML,55,"lb"),document.body);
    fader(document.getElementById("dialogBox"),0);
    centerObject(document.getElementById("dialogBox"));
    document.getElementById("vb_login_username").focus();

    startFadeUp();
}
function getMyPassword() {
    document.getElementById("forgot").style.display="block";
    document.getElementById("forgotOpener").style.display="none";
}
function sendPasswordRequest() {
    if (document.getElementById("forgotbutton").innerHTML!="Requesting...") {
        docUrl="/resource/forgot.php?queryemail="+document.getElementById("forgot_email").value;
        sendRequest(docUrl,passwordRequested);
        document.getElementById("forgotbutton").innerHTML="Requesting...";
    }
}
function passwordRequested() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            document.getElementById("forgotbutton").innerHTML="Get my password...";
            var res=trim(requesthttp.responseText);
            if (res=="ok") {
                document.getElementById("forgot").style.display="none";
                document.getElementById("forgotOpener").style.display="block";
                alert("A password reminder has been sent to your email address");
            }else{
                alert(res);
            }
        }else{
            alert("Problem retrieving XML data:" + requesthttp.statusText+"\n"+requesthttp.responseText);
        }
        requesthttp=null;
    }
}
function inputSurround(id, ip,valid) {
    backURL=valid?"inputValid":"inputRequired";
    op="<table cellspacing=0 cellpadding=0 id=\""+id+"Table\" style=\"background-image:url(/skin/"+backURL+".gif);font-size:12px;width:100px\"><tr>";
    op+="<td><img src=\"/skin/inputLeft.png\" /></td><td>"+ip+"</td><td><img src=\"/skin/inputRight.png\" /></td></tr></table>";
    return op;
}
function saveProfile() {
    fields=new Array("username","email","password","firstnameInput","lastnameInput","countrySearchField","dobText");
    isOK=true;
    mistakes="";
    filter=/inputValid/;
    for(field=0;field<fields.length;field++) {
        if (!filter.test(document.getElementById(fields[field]+"Table").style.backgroundImage)) {
            mistakes+=fields[field]+"<br />";
            isOK=false;
        }
    }
    if (isOK) {
        docUrl="/forum/saveProfile.php?u="+document.getElementById("username").value;
        docUrl+="&e="+document.getElementById("email").value;
        docUrl+="&gp="+document.getElementById("password").value;
        md5hash(document.getElementById("password"), document.getElementById("md5"), junk_output, 0);
        docUrl+="&pmd="+document.getElementById("md5").value;
        docUrl+="&fn="+document.getElementById("firstnameInput").value;
        docUrl+="&ln="+document.getElementById("lastnameInput").value;
        docUrl+="&c="+country;
        docUrl+="&d="+dob.getFullYear()+"-"+(dob.getMonth()+1)+"-"+dob.getDate();
        //alert(docUrl);
        //document.getElementById("pageContent").innerHTML=docUrl;
    //document.body.innerHTML+=docUrl;
        sendRequest(docUrl,profileSaved);
    }else{
        //alert(mistakes);
        alert("Not all fields are valid!");
    }
}
function profileSaved() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            var res=trim(requesthttp.responseText);
            parts=res.split("&");
            if (parts[0]=="ok" && parts.length>2) {
                //alert("Password="+parts[3]);
                doVerification(parts[1],parts[2]);
                //startFadeDown();
            }else{
                //document.getElementById("saveProfileButton").innerHTML="&nbsp;Create my profile&nbsp;";
               // document.getElementById("saveProfileButton").onclick="saveProfile()";
               
                alert(res+"["+res.length+"]");
                
                //alert("Your profile has not been saved");
            }
        }else{
            alert("Problem retrieving XML data:" + requesthttp.statusText+"\n"+requesthttp.responseText);
        }
        requesthttp=null;
    }
}

function doVerification(verifyKey,uid) {
    
verForm="<center><form id=\"verForm\" method=\"post\" action=\"http://www.aweber.com/scripts/addlead.pl\">";
verForm+="<input type=\"hidden\" name=\"meta_web_form_id\" value=\"1118244657\">";
verForm+="<input type=\"hidden\" name=\"meta_split_id\" value=\"\">";
verForm+="<input type=\"hidden\" name=\"unit\" value=\"gan\">";
verForm+="<input type=\"hidden\" name=\"redirect\" value=\"http://www.gamingaffiliatenews.com/index.php?ganm=verifySent\">";
verForm+="<input type=\"hidden\" name=\"meta_redirect_onlist\" value=\"\">";
verForm+="<input type=\"hidden\" name=\"meta_adtracking\" value=\"\">";
verForm+="<input type=\"hidden\" name=\"meta_message\" value=\"1\">";
verForm+="<input type=\"hidden\" name=\"meta_required\" value=\"from,name\">";
verForm+="<input type=\"hidden\" name=\"meta_forward_vars\" value=\"0\">";
verForm+="<input type=\"hidden\" name=\"from\" value=\""+document.getElementById("email").value+"\">";
verForm+="<input type=\"hidden\" name=\"name\" value=\""+document.getElementById("firstnameInput").value+" "+document.getElementById("lastnameInput").value+"\">";
verForm+="<input type=\"hidden\" name=\"custom verifyKey\" value=\""+verifyKey+"\" >";
verForm+="<input type=\"hidden\" name=\"custom uid\" value=\""+uid+"\" >";


verForm+="</form>";
verForm+="<span style=\"font-size:12px\">Your profile has been saved!<br />An email is now being sent to you, containing a verification link.<br />Click this link to activate your profile...</span></center>";


document.getElementById("registrationArea").innerHTML=verForm;
document.getElementById("verForm").submit();
}



function logmeout(docUrl) {
    window.location=docUrl;
            //window.location="index.php";
    //sendRequest(docUrl,logoutreply);
}
function logoutreply() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            alert(requesthttp.responseText);
        }else{
            alert(requesthttp.responseText);
        }
        requesthttp=null;
    }
}
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function sendRequest(docUrl,returnHandler) {
    docUrl+="&randomnumber="+Math.random();
    if (window.XMLHttpRequest){
        requesthttp=new XMLHttpRequest();
        requesthttp.onreadystatechange=returnHandler;
        requesthttp.open("GET",docUrl,true);
        requesthttp.send(null);
    }else if (window.ActiveXObject){
        requesthttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (requesthttp){
            requesthttp.onreadystatechange=returnHandler;
            requesthttp.open("GET",docUrl,true);
            requesthttp.send();
        }
    }
}
function checkLength(srcObj,minlength,maxlength) {
    var inputLength=srcObj.value.length;
    if (inputLength<=maxlength && inputLength>=minlength) {
        showWarning(srcObj.id+"Comment","",srcObj);
	    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
	}else{
	    var theComment=minlength+" - "+maxlength+" chars";
	    if (minlength==1) theComment="&lt; "+maxlength+" chars";
	    if (maxlength==0) theComment="&gt; "+minlength+" chars";
        showWarning(srcObj.id+"Comment",theComment,srcObj);
	    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
	}
}
function checkEmail(srcObj) {
    emailInputObject=srcObj;
    email=srcObj.value;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
	    if (emailInputObject.id=="loginEmail") {
	        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
	    }else{    
	        checkEmailWithDatabase(trim(email));
	    }
	}else{
        showWarning(srcObj.id+"Comment","Not a valid email",srcObj);
	    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        emailInputObject.title="Required";
	}
}
function checkUsername(srcObj) {
    usernameInputObject=srcObj;
    un=srcObj.value;
    inputLength=un.length;
    minlength=4;
    maxlength=100;
    if (inputLength<=maxlength && inputLength>=minlength) {
        showWarning(srcObj.id+"Comment","",srcObj);
        docUrl="/resource/checkEmail.php?username="+trim(un);
        docUrl+="&v="+new Date().valueOf();
        sendRequest(docUrl,usernameCheckReceived);
	}else{
	    var theComment=minlength+" - "+maxlength+" chars";
	    if (minlength==1) theComment="&lt; "+maxlength+" chars";
	    if (maxlength==0) theComment="&gt; "+minlength+" chars";
        showWarning(srcObj.id+"Comment",theComment,srcObj);
	    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
	}
}

function usernameCheckReceived() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            var res=trim(requesthttp.responseText);
            if (res=="ok") {
                document.getElementById(usernameInputObject.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
                
                showWarning(usernameInputObject.id+"Comment","",usernameInputObject);
                usernameInputObject.title="This username address is valid";
            }else{
                document.getElementById(usernameInputObject.id+"Table").style.backgroundImage="url(/skin/inputError.gif)";
                showWarning(usernameInputObject.id+"Comment","Exists",usernameInputObject);
                usernameInputObject.title="This username is already registered";
            }
        }else{
            alert("Problem retrieving XML data:" + requesthttp.statusText+"\n"+requesthttp.responseText);
        }
        requesthttp=null;
    }
}
function checkEmailWithDatabase(emailToCheck){
    docUrl="/resource/checkEmail.php?email="+emailToCheck;
    docUrl+="&v="+new Date().valueOf();
    sendRequest(docUrl,emailCheckReceived);
}
function emailCheckReceived() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            var res=trim(requesthttp.responseText);
            if (res=="ok") {
                document.getElementById(emailInputObject.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
                showWarning(emailInputObject.id+"Comment","",emailInputObject);
                emailInputObject.title="This email address is valid";
            }else{
                document.getElementById(emailInputObject.id+"Table").style.backgroundImage="url(/skin/inputError.gif)";
                showWarning(emailInputObject.id+"Comment","Exists",emailInputObject);
                emailInputObject.title="This email address is already registered";
            }
        }else{
            alert("Problem retrieving XML data:" + requesthttp.statusText+"\n"+requesthttp.responseText);
        }
        requesthttp=null;
    }
}
function checkPassword(srcObj) {
    passwordString=srcObj.value;
    var filter  = /^([a-zA-Z0-9])+$/;
	if (passwordString.length>6) {
	    if (filter.test(passwordString)) {
            document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
            showWarning(srcObj.id+"Comment","",srcObj);
        }else{
            document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputError.gif)";
            showWarning(srcObj.id+"Comment","The password must be alphanumeric",srcObj);
        }
	}else{
	    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        showWarning(srcObj.id+"Comment","6 to 50 alphanumeric character",srcObj);
	}
}

function checkKey(e) {
    var rval=true;
    if (window.event) keycode=window.event.keyCode;
    else if (e) keycode=e.which;
    if (keycode>105) {
        rval=false;
    }
    return rval;   
}
function foundCountries() {
    if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
            if (document.getElementById("shortlist")==null) {
                var floater="<div id=\"shortlist\" class=\"shortlist\" style=\"position:absolute;z-index:61\">"+xmlhttp.responseText+"</div>";
                pasteRawHTML(floater,document.body);
            }else{
                document.getElementById("shortlist").innerHTML=xmlhttp.responseText;
            }
            alignObjectUnderTarget(document.getElementById("shortlist"),theCountrySearchField,3);
        }else{
            alert("Problem retrieving XML data:" + xmlhttp.statusText+"\n"+xmlhttp.responseText);
        }
    }
}
function findCountries(srcObj) {
    theCountrySearchField=srcObj;
    country="";
    countryName="";
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        var searchField=srcObj.value;
        lastCountrySearch=searchField;
        var docUrl="/resource/shortlistCountries.php?q="+searchField;
        if (searchField!="") {
        if (window.XMLHttpRequest){
            xmlhttp=new XMLHttpRequest();
            xmlhttp.onreadystatechange=foundCountries;
            xmlhttp.open("GET",docUrl,true);
            xmlhttp.send(null);
        }else if (window.ActiveXObject){
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
            if (xmlhttp){
                xmlhttp.onreadystatechange=foundCountries;
                xmlhttp.open("GET",docUrl,true);
                xmlhttp.send();
            }
        }
        }
}
function resetCountry(srcObj) {
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        srcObj.value=lastCountrySearch;
        country="";
        countryName="";
        findCountries(srcObj);
}
function countryChosen(code2,countryNom) {
        theCountrySearchField.value=countryNom;
        countryName=countryNom;
        document.getElementById(theCountrySearchField.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
        country=code2;
        removeTheNode('shortlist');
}
function findCounties(srcObj) {
    theCountySearchField=srcObj;
    county="";
    countyName="";
    if (country!="") {
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        var searchField=srcObj.value;
        lastCountySearch=searchField;
        var docUrl="/shortlistCounties.ashx?q="+searchField+"&country="+country;
        if (window.XMLHttpRequest){
            xmlhttp=new XMLHttpRequest();
            xmlhttp.onreadystatechange=foundCounties;
            xmlhttp.open("GET",docUrl,true);
            xmlhttp.send(null);
        }else if (window.ActiveXObject){
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
            if (xmlhttp){
                xmlhttp.onreadystatechange=foundCounties;
                xmlhttp.open("GET",docUrl,true);
                xmlhttp.send();
            }
        }
    }else{
        if (countryCode=="") {
            document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        }
    }
}
function foundCounties() {
    if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
            if (document.getElementById("shortlist")==null) {
                var floater="<div id=\"shortlist\" style=\"background-color:#ECF5F8;border:1px solid #007FAF;position:absolute;z-index:41\">"+xmlhttp.responseText+"</div>";
                pasteRawHTML(floater,document.body);
            }else{
                document.getElementById("shortlist").innerHTML=xmlhttp.responseText;
            }
            alignObjectUnderTarget(document.getElementById("shortlist"),theCountySearchField,3);
            
        }else{
            alert("Problem retrieving XML data:" + xmlhttp.statusText+"\n"+xmlhttp.responseText);
        }
    }
}
function resetCounty(srcObj) {
    county="";   
    countyName="";
    document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
    if (srcObj.value!=lastCountySearch) srcObj.value=lastCountySearch;
        findCounties(srcObj);
}
function countyChosen(code,countyNom) {
        theCountySearchField.value=countyNom;
        countyName=countyNom;
        document.getElementById(theCountySearchField.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)"; 
        county=code;
        removeTheNode('shortlist');
}
    function alignObjectUnderTarget(obj,target,offset) {
        src=target;
	    var curleft = curtop = 0;
	    if (target.offsetParent) {
		    curleft = target.offsetLeft;
		    curtop = target.offsetTop;
		    while (target = target.offsetParent) {
		    	curleft += target.offsetLeft;
		    	curtop += target.offsetTop;
		    }
	    }
	    
        obj.style.left=(curleft)+"px";
        obj.style.top=(curtop+src.clientHeight+offset)+"px";
    }
function removeTheNode(idname) {
    if (document.getElementById(idname)!=null) {
        thisNode=document.getElementById(idname);
        //alert(thisNode.id);
        thisNode.parentNode.removeChild(thisNode);
    }
}
function validatePostcode(srcObj) {
    var regExp = /^([a-zA-Z0-9])+$/i;
    if (country=="GB") {
        regExp= /^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$/i;
    }
//    if (country=="ES") {
//        regExp= /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/i;
//    }
//    if (country=="AU") {
//        regExp= /^(((2|8|9)\d{2})|((02|08|09)\d{2})|([1-9]\d{3}))$/i;
//    }
//    if (country=="NL") {
//        regExp= /^[1-9]{1}[0-9]{3}\s?[A-Z]{2}$/i;
//    }
    if (country=="US") {
        regExp= /^(?!0{5})(\d{5})(?!-?0{4})(-?\d{4})?$/i;
    }
    if (country=="CA") {
        regExp= /^[abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9]$/i;
    }
    if (regExp.test(srcObj.value) && srcObj.value.length>0) {
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
    }else{
        if (srcObj.value.length==0) {
            document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
        }else{
            document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputError.gif)";
        }
    }
}
function validateOverLength(srcObj,theLength) {
    if (srcObj.value.length>=theLength) {
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputValid.gif)";
    }else{
        document.getElementById(srcObj.id+"Table").style.backgroundImage="url(/skin/inputRequired.gif)";
    }
}
function openTheCalendar(srcObj) {
    var today=new Date();
    showCalendar(srcObj,"setDOB",dob.getFullYear()+"-"+dob.getMonth()+"-"+dob.getDate()+"-0-0",null,today.getFullYear()+"-"+today.getMonth()+"-"+today.getDate()+"-0-0");
}
function setDOB(y,m,d) {
    dob=new Date(y,m,d,0,0,0,0);
    document.getElementById("dobText").innerHTML=dob.toDateString();
    document.getElementById("dobTextTable").style.backgroundImage="url(/skin/inputValid.gif)";
    today=new Date();
    age=today.getFullYear()-dob.getFullYear();
    if (dob.getMonth()==today.getMonth()) {
        if (dob.getDate()>today.getDate()) age--;
    }else if (dob.getMonth()>today.getMonth()) {
        age--;
    }
        
    //myAge=age+" y/o";
    //document.getElementById("dobComment").innerHTML=myAge;
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function checklogin() {
    docUrl="/resource/checkLogin.php?username="+document.getElementById("vb_login_username").value+"&password="+document.getElementById("vb_login_password").value;
    //alert(docUrl);
    sendRequest(docUrl,loginCheckReceived);
}
function loginCheckReceived() {
    if (requesthttp.readyState==4) {
        if (requesthttp.status==200) {
            var res=trim(requesthttp.responseText);
            if (res=="Verified") {
                document.getElementById("loginform").submit();
            }else{
                alert(res);
            }
        }else{
            alert("Problem retrieving XML data:" + requesthttp.statusText+"\n"+requesthttp.responseText);
        }
        requesthttp=null;
    }
}
function alert(message) {

	contentHTML="<table style=\"font-size:11px\" cellspacing=\"8\" height=\"300px\" width=\"340px\"><tr><td class=\"floatingHead\" style=\"color:#fff954;text-align:center\"><b>ALERT</b></td></tr>";
	contentHTML+="<tr><td style=\"text-align:center;font-size:14px;color:#fff954\">";
	contentHTML+=message+"</td></tr>";
	contentHTML+="<tr><td style=\"text-align:center\" colspan=\"2\" class=\"floatingFoot\">";
	contentHTML+="<img src=\"/skin/alertok.gif\" onclick=\"removeTheNode('alert')\" style=\"cursor:pointer\" />";
	contentHTML+="</td></tr></table>";
    
	
    pasteRawHTML(returnRoundedBox("alert",350,contentHTML,56,"lb"),document.body);
    centerObject(document.getElementById("alert"));
}
