/**
* LAST MOD: MAR 04 2009
* ---------------------
*/
function readUserField(i,t,v,o) {
    var brkI=i.split("|");
    var mySession=brkI[0];
    var myID=brkI[1];
    var newI=mySession+"|"+myID;
    var brkV=v.split("|");
    var isUsername=document.getElementById(brkV[0]).value;
    var isUserLength=isUsername.length;
    var isPassword=document.getElementById(brkV[1]).value;
    if(isUserLength<4) {
        alert("Your Username MUST be at least 4 characters.");
        return false;
    }else if(o=="signup_verify" && isUsername=="") {
        alert("Please Fill in the Username to Run a Check.");
        return false;
    }else if(o=="signup_verify" && isUsername!="") {
        callAjax(newI,'checkUserListing',t,isUsername+'|'+isPassword,'get',o);
    }else if(isUsername!="" && isPassword!="") {
        callAjax(newI,'checkUserListing',t,isUsername+'|'+isPassword,'get','');
    }else{
        alert("Please Fill in Both Fields");
    }
}
function popDetails(d) {
    var ww=screen.width;
    var hh=screen.height;
    var isWW=(ww/2)-175;
    var isHH=(hh/2)-155;
    window.open(d,'',config='width=520,height=450,scrollbars=yes,statusbar=no,left='+isWW+',top='+isHH+',resizable=0');
}
/*====UPON SUBMISSION OF REG FORM======================*/
/*=====================================================*/
function errorCheck() {
	var required=new Array("regFirstName","regLastName","regEmail","regReenterEmail","regBizName","regProfession","regStreet","regCity","regZip");
	for(var r=0;r<required.length;r++) {
		var isValue=document.getElementById(required[r]).value;
		isValue=isValue.replace(/ /g,"");
		if(isValue=="") {
			alert("One or more of the REQUIRED fields are blank. Please enter proper information.");
			return false;
		}
	}
	var emailTry1=document.getElementById(required[2]).value;
	var emailTry2=document.getElementById(required[3]).value;
	if(emailTry1!=emailTry2) {
		alert("Your Re-Entry Email did not match the Original.");
		return false;
	}
    var v0=allowed(document.getElementById('createUsername').value);
    if(v0=="bad") {
        alert("No special characters are allowed in the Username.");
        return false;
    }
    var v1=allowed(document.getElementById('createPassword').value);
    if(v1=="bad") {
        alert("No special characters are allowed in the Password.");
        return false;
    }
    fadeContent();
	document.getElementById('sendConfirmationDiv').style.display="block";
}
/*=====================================================*/
/*----------------------------------
V = VALUE
S = CURRENT SESSION
D = AJAX RESPONSE DIV
B = DIV THAT WILL CONTAIN THE RESULT (I.E. A BUTTON BEING AVAILABLE)
t = TYPE OF ACTION
-----------------------------------*/
var allowchars={"a":'',"b":'',"c":'',"d":'',"e":'',"f":'',"g":'',"h":'',"i":'',"j":'',"k":'',"l":'',"m":'',"n":'',"o":'',"p":'',"q":'',"r":'',"s":'',"t":'',"u":'',"v":'',"w":'',"x":'',"y":'',"z":'',"_":'',"-":'',"1":'',"2":'',"3":'',"4":'',"5":'',"6":'',"7":'',"8":'',"9":'',"0":''};
function findUser(v,s,d,b,t) {
    v=v.replace(/ /g,"");
    if(v=="") {
        alert("Please enter a valid username.");
        return false;
    }
    if(v.length<4) {
        alert("Your username MUST be at least 4 characters in length.");
        return false;
    }else if(v.length>15) {
        alert("Your username MUST be 15 characters or less.");
        return false;
    }
    var newV=v.split('');
    for(var i=0;i<newV.length;i++) {
        var makeLower=newV[i].toLowerCase();
        if(makeLower in allowchars) {
            continue;
        }
        alert(makeLower==" " ? "You have a blank space in your Username" : "No special characters are allowed.");
        return false;
    }
    //
    var rq=null;
    if(window.XMLHttpRequest) {
        rq=new XMLHttpRequest();
    }else if(window.ActiveXObject) {
        try {
            rq=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (er) {
            try {
                rq=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (er) {
                alert("It appears your Internet Explorer has ActiveX disabled or is not supported.\nPlease enable your ActiveX or update your Internet Explorer to a version that supports it.");
                return false;
            }
        }
    }else{
        alert("It appears your browser does not support the XMLHttpRequest or ActiveX.\nTo utilize this option, please use a browser with one of the support.");
        return false;
    }
    //
    var timer=window.setTimeout((function(){try{rq.abort();}catch(er){} document.getElementById(d).innerHTML='I lost connection. Please try again.';}),3500);
    //
    var theURL="styles/ajax_find_user.php";
    var params="session="+s+"&value="+v+"&type="+t+"&nocache"+parseInt(Math.random()*999999);
    //
    rq.onreadystatechange=function() {
        if(rq.readyState==4) {
            try{
                window.clearTimeout(timer);
            }catch(er) {
                //nothing needed here
            }
            if(rq.status==200) {
                myInfo=rq.responseText;
                if(t=="check") {
                    if(myInfo=="good") {
                        myInfo="<img src=\"images/icon_checkbox.gif\" border=\"0\" /> &nbsp;CONGRATULATIONS!<br /> This Username is not taken!<br />Quickly secure this Username by clicking on 'Continue'.";
                        if(b!="") {
                            document.getElementById(b).style.visibility="visible";
                        }
                    }
                }
                document.getElementById(d).innerHTML="<div class=\"redBold pad5\">"+myInfo+"</div>";
            }else{
                document.getElementById(d).innerHTML="<div class=\"redBold pad5\">Lost connection. Please try again.</div>";
            }
        }else{
            var msg=(rq.readyState==1 ? "Gathering Info..." : "Connecting...");
            msg=(rq.readyState==2 ? "Processing Request..." : msg);
            msg=(rq.readyState==3 ? "Trying to Finalizing..." : msg);
            document.getElementById(d).innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" />&nbsp; "+msg;
        }
    }
    rq.open('POST',theURL,true);
    rq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    rq.setRequestHeader("Content-Length",params.length);
    rq.setRequestHeader("Connection","close");
    rq.send(params);
}
function revertResponseDiv(d,b) {
    document.getElementById(b).style.visibility="hidden";
    document.getElementById(d).innerHTML="<span class=\"boldIt sky2BG\">HELPFUL TIP</span><p align=\"right\" class=\"px11\">1. Your Username & Password<br />should never be the same.<br /><br />2. Your Username & Password<br />are <span class=\"boldIt\">cAsE sEnSiTiVe</span>.</p>";
}
function tellMeMore(d,d1,d2) {
    if(document.getElementById(d).style.visibility!="visible") {
        document.getElementById(d).style.visibility="visible";
        document.getElementById(d1).style.visibility="hidden";
        document.getElementById(d2).style.visibility="hidden";
    }else{
        document.getElementById(d).style.visibility="hidden";
        //document.getElementById(d1).style.visibility="hidden";
        //document.getElementById(d2).style.visibility="hidden";
    }
}
/*====RE-CREATES THE SUB-OPTION LIST ON THE FLY========*/
/*=====================================================*/
function swapSubcats(i) {
    document.getElementById('regSubcat').options.length=0;
    var dimArray=subOpts[i];
    for(var z=0;z<dimArray.length;z++) {
        document.getElementById('regSubcat').options[z]=new Option(dimArray[z],dimArray[z]);
    }
}
/*=====================================================*/
/*====POP UP REG CONFIRMATION DIALOGUE BOX=============*/
/*=====================================================*/
function sendConfirm(t,s,v) {//t=self reference; s=session ID; v= string: 'free'
    try{
        rq.abort();
    }catch(er) {
        //
    }
    var rq=null;
    if(window.XMLHttpRequest) {
        rq=new XMLHttpRequest();
    }else if(window.ActiveXObject) {
        try {
            rq=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (er) {
            try {
                rq=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (er) {
                alert("It appears your Internet Explorer has ActiveX disabled or is not supported.\nPlease enable your ActiveX or update your Internet Explorer to a version that supports it.");
                return false;
            }
        }
    }else{
        alert("It appears your browser does not support the XMLHttpRequest or ActiveX.\nTo utilize this option, please use a browser with one of the support.");
        return false;
    }
    //
    if(v=="paid") {
        var isFN=document.getElementById('regFirstName').value;
        var isEM=document.getElementById('regEmail').value;
        var isCP=document.getElementById('sendCaptcha').value;
        if((isCP.replace(/ /g,''))=="") {
            alert("Please enter the Captcha code you see above.");
            return false;
        }
        var o=isFN+"|"+isEM+"|"+isCP;
        var act="sendConfirm";
        document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" />&nbsp; sending...";
    }else{
        var o=document.getElementById('enterConfirmation').value;
        if(o=="" || o==" ") {
            alert("Please enter your Confirmation number before verifying.");
            return false;
        }
        var act="verifyConfirm";
        document.getElementById('confirmCheckDiv').innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" />&nbsp; checking...";
    }
    //
    var theURL="styles/ajax.php";
    var params="session="+s+"&method=post&action="+act+"&value="+v+"&options="+o+"&nocache="+parseInt(Math.random() * 999999);
    rq.open('POST',theURL,true);
    rq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    rq.setRequestHeader("Content-Length",params.length);
    rq.setRequestHeader("Connection","close");
    rq.send(params);
    rq.onreadystatechange=function() {
        if(rq.readyState==4) {
            if(rq.status==200) {
                myInfo=rq.responseText;
                //INITIALLY SENDING OFF THE EMAIL + CHECKING CAPTCHA CODE
                if(v=="paid") {
                    if(myInfo=="success") {//------->UPON SUCCESS
                        document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_checkbox.gif\" border=\"0\" /> &nbsp;-successfully sent.";// &nbsp;-Please check your email shortly.
                    }else if(myInfo=="exists") {//-->IF EMAIL ALREADY IS IN USE
                        document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_alert.gif\" border=\"0\" /> &nbsp;-This email is already in use.";
                    }else if(myInfo=="badcaptcha") {//-->IF CAPTCHA IS BAD
                        document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_alert.gif\" border=\"0\" /> &nbsp;-The Captcha code was incorrect.";
                    }else{//------------------------>UNKNOWN FAILURES
                        document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_alert.gif\" border=\"0\" /> &nbsp;-Sorry, I failed. Please try again.";
                    }
                //UPON RECEIPT OF CONFIRMATION EMAIL AND PASTING CODE INTO FIELD
                }else{
                    if(myInfo=="confirmed") {
                        document.getElementById('confirmCheckDiv').innerHTML="<img src=\"images/icon_checkbox.gif\" border=\"0\" />";
                        document.getElementById('continueRegDiv').style.display="block";
                    }else{
                        document.getElementById('confirmCheckDiv').innerHTML="<img src=\"images/icon_alert.gif\" border=\"0\" /> &nbsp; -This doesn't match the confirmation!";
                    }
                }
            }else{
                try{
                    rq.abort();
                }catch(er) {
                    //
                }
                //
            }
        }else{
            if(v=="paid") {
                document.getElementById('sendCheckDiv').innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" /> -sending...";
            }else{
                document.getElementById('confirmCheckDiv').innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" /> -processing...";
            }
        }
    }
}
function fadeContent() {
    var isBody=document.getElementById('subContentDiv');
    var isCover=document.createElement('div');
    isCover.setAttribute('id','coverDiv');
    with(isCover.style) {
        width="100%";
        height="100%";
        position="absolute";
        top="0px";
        left="0px";
        zIndex="98";
        backgroundColor="#c0c0c0";
        opacity="0.7";
        filter="alpha(opacity='70')";
    }
    isBody.appendChild(isCover);
}
function unfadeContent() {
	var isBody=document.getElementById('subContentDiv');
	var isCover=document.getElementById('coverDiv');
	isBody.removeChild(isCover);
    document.getElementById('sendCheckDiv').innerHTML="";
    document.getElementById('sendConfirmationDiv').style.display="none";
}

function dynamicSubmit() {
    document.getElementById('regForm').submit();
}
/*===========================================*/
var increment=24;
var speed=30;
var timer=null;
var maxY=324;
var minY=24;
//LET'S HIDE OUR REGISTRATION OPTION DIV
function collapseRegDiv(t,p) {
    rewriteLink(p)
    var objDiv=document.getElementById('registerOptionDiv');
    var isY=(objDiv.style.height=="" ? maxY+"px" : objDiv.style.height);
        isY=(isY.indexOf('px')!=-1 ? (isY.substr(0,(isY.length-2))*1) : (isY*1));
    objDiv.style.borderBottom="solid 1px #000099";
    if(isY>minY) {
        try{
            objDiv.style.height=(isY-increment)+"px";
            timer=window.setTimeout((function(){collapseRegDiv(t,p);}),speed);
        }catch(er) {
            objDiv.style.height="1px";
        }
    }else{
        objDiv.style.height="1px";
        try{
            clearTimeout(timer);
            timer=null;
        }catch(er) {
            timer=null;
        }
        //NOW LET'S DISPLAY IT TO NONE
        objDiv.style.display="none";
        objDiv.style.borderBottom="none";
    }
}
//LET'S RE-SHOW OUR REGISTRATION OPTION DIV
function expandRegDiv(t) {
    var objDiv=document.getElementById('registerOptionDiv');
    var isY=(objDiv.style.height=="" ? minY+"px" : objDiv.style.height);
        isY=(isY.indexOf('px')!=-1 ? (isY.substr(0,(isY.length-2))*1) : (isY*1));
    objDiv.style.display="block";
    objDiv.style.borderBottom="solid 1px #000099";
    if(isY<(maxY-minY)) {
        try{
            objDiv.style.height=(isY+increment)+"px";
            timer=window.setTimeout((function(){expandRegDiv(t);}),speed);
            //alert(isY);
        }catch(er) {
            objDiv.style.height=maxY+"px";
        }
    }else{
        objDiv.style.height=maxY+"px";
        try{
            clearTimeout(timer);
            timer=null;
        }catch(er) {
            timer=null;
        }
        //NOW LET'S REMOVE THE BORDER
        objDiv.style.borderBottom="none";
    }
}
//REWRITE REGISTRATION LINKS TO GO TO PROPER REG PAGE
function rewriteLink(p) {
    document.getElementById('linkEntrepreneur').href=p+".php?reg_type=entrepreneur&step=0";
    document.getElementById('linkFreelancer').href=p+".php?reg_type=freelancer&step=0";
    document.getElementById('linkEmployer').href=p+".php?reg_type=employer&step=0";
}
function hideTellMe() {
    document.getElementById('tellEntreDiv').style.visibility="hidden";
    document.getElementById('tellFreelDiv').style.visibility="hidden";
    document.getElementById('tellEmploDiv').style.visibility="hidden";
}



