/**
* LAST MOD: APR 04 2009
* ---------------------
*/
defaultStatus="Freelancer Listing Search Results::::";
//USED INCASE AJAX CRAPS OUT. PREVENT BROWSER HANG AND SHOW THIS MESSAGE
var closureFunction="document.getElementById('dialBody').innerHTML=\"<br /><h3>Lost connection. Please try again.</h3>\";";//"alert(\"I'm sorry but lost connection. Please try again.\");";
/*===CREATE THE POPUP DIV CONTENT ON THE FLY===========*/
/*=====================================================*/
function makeContent(t,s,dt,lid) {//t=self reference; s=session; dt=title; lid=listing ID;
    //FIRST LET'S WRITE THE TITLE
    var isContentType=(dt=="More Info" ? "pullMoreInfo" : (dt=="Contact Me" ? "contactMe" : "rateMe"));
    document.getElementById('dialTitle').innerHTML="::: "+dt+" :::";
    //LET'S CALL AJAX TO FETCH INFO ON THIS LISTING
    var rq=xmlObject(2500,closureFunction);
    if(typeof(rq)!="object") {
        alert(rq);
        return false;
    }
    var theURL=baseURL+"styles/ajax.php";
    var params="session="+s+"&id=&lid="+lid+"&value="+lid+"&type=&action="+isContentType+"&method=post&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;
                document.getElementById('dialBody').scrollTop="0px";
                document.getElementById('dialBody').innerHTML=myInfo;
            }else{
                document.getElementById('dialBody').innerHTML="<h3>Lost connection. Please try again.</h3>";
                try{
                    rq.abort();
                }catch(er) {
                   //do nothing
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
    //WE USE AN 'IF' STATEMENT INCASE IT'S COMING FROM WITHIN THE DIALOGUE BOX
    if(t.parentNode.tagName!="DIV") {
        var nodeTree=t.parentNode;
        var nodeY=t.offsetTop;
        while(nodeTree.id.indexOf('resultListFS_')==-1) {
            nodeTree=nodeTree.parentNode;
            nodeY=nodeTree.offsetTop;
        }
        nodeY=nodeY-80;
        with(document.getElementById('dialogueDiv').style) {
            display="block";
            left="160px";
            top=nodeY+"px";
        }
    }
}
function killContent() {
    document.getElementById('dialBody').innerHTML="<p><br /><br /><img src=\"images/icon_loading.gif\" border=\"0\" />&nbsp; Creating content...</p>";
    document.getElementById('dialBody').scrollTop="0px";
    with(document.getElementById('dialogueDiv').style) {
        display="none";
        left="0px";
        top="0px";
    }
}
/*===UPON SUBMISSION OF 'CONTACT ME'===================*/
/*=====================================================*/
function sendContact(t,s,lid) {//t=self reference; s=session; lid=listing ID
    var cName=document.getElementById('contactName').value;
    var cEmail=document.getElementById('contactEmail').value;
    var cSubject=document.getElementById('contactSubject').value;
    var cDescript=document.getElementById('contactDescript').value;
    if(cName=="" || cEmail=="" || cDescript=="") {
        alert("Please fill out all fields before submitting.");
        return false;
    }
    //IF ALL GOOD, LET'S POST VIA AJAX
    var rq=xmlObject(2500,closureFunction);
    if(typeof(rq)!="object") {
        alert(rq);
        return false;
    }
    var vals=cName+"|"+cEmail+"|"+cSubject+"|"+cDescript;
    var theURL=baseURL+"styles/ajax.php";
    var params="session="+s+"&id=&lid="+lid+"&value="+vals+"&type=&action=contactPost&method=post&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;
                document.getElementById('dialBody').innerHTML="<h4>"+myInfo+"</h4>";
            }else{
                document.getElementById('dialBody').innerHTML="<h3>Lost connection. Please try again.</h3>";
                try{
                    rq.abort();
                    sendContact(t,s,lid);
                }catch(er) {
                    sendContact(t,s,lid);
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
/*===DISPLAY RATING FORM===============================*/
/*=====================================================*/
function showRatingForm() {
    if(document.getElementById('newReviewDiv').style.display!="block") {
        document.getElementById('newReviewDiv').style.display="block";
    }else{
        document.getElementById('newReviewDiv').style.display="none";
    }
}
var snapshot="";
function countChars(t,e) {//t=self reference; e=event
    var charCount=t.value.length;
    maxChar=(charCount>0 ? 256-charCount : 0);
    if(maxChar<0) {
        t.value=snapshot;
        document.getElementById('maxLengthKBD').innerHTML="max length: "+0;
    }else{
        document.getElementById('maxLengthKBD').innerHTML="max length: "+maxChar;
        snapshot=t.value;
    }
    
}
//UPON CLICK OF 'GO' FOR ADDING A RATING
function submitRating(t,s,lid,id) {//t=self reference; s=session ID; lid=listing ID; id=member ID;
    var newRating=document.getElementById('rateMeNow').value;
    //IF ALL GOOD, LET'S POST VIA AJAX
    var rq=xmlObject(2500,closureFunction);
    if(typeof(rq)!="object") {
        alert(rq);
        return false;
    }
    var theURL=baseURL+"styles/ajax.php";
    var params="session="+s+"&id="+id+"&lid="+lid+"&value="+newRating+"&type=&action=addRating&method=post&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;
                document.getElementById('rateMeSelectDiv').innerHTML=(myInfo=="good" ? "<strong>Your rating has been added.</strong>" : "<strong>Your rating could not be added at this moment.</strong>");
            }else{
                document.getElementById('rateMeSelectDiv').innerHTML="<strong>Lost connection. Please try again.</strong>";
                try{
                    rq.abort();
                    submitRating(t,lid,id);
                }catch(er) {
                    submitRating(t,lid,id);
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
//UPON CLICK OF 'SUBMIT REVIEW' FOR ADDING A REVIEW
function submitReview(t,s,lid,id) {//t=self reference; s=session ID; lid=listing ID; id=member ID;
    var newReview=document.getElementById('newReview').value;
    var newSignature=document.getElementById('newSignature').value;
    if(newReview=="" || newSignature=="") {
        alert("Both the 'review' and 'signature' are required.");
        return false;
    }
    //IF ALL GOOD, LET'S POST VIA AJAX
    var rq=xmlObject(2500,closureFunction);
    if(typeof(rq)!="object") {
        alert(rq);
        return false;
    }
    var vals=escape(newReview)+"|"+escape(newSignature);
    var theURL=baseURL+"styles/ajax.php";
    var params="session="+s+"&id="+id+"&lid="+lid+"&value="+vals+"&type=&action=addReview&method=post&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;
                document.getElementById('newReviewDiv').innerHTML=(myInfo!="failed" ? "<strong>Your review has been added.</strong>" : "<strong>Your review could not be added at this moment.</strong>");
                if(myInfo!="failed") {
                    document.getElementById('addReview').style.display="none";
                    document.getElementById('oldReviewDiv').innerHTML=myInfo;
                }
            }else{
                document.getElementById('newReviewDiv').innerHTML="<strong>Lost connection. Please try again.</strong>";
                try{
                    rq.abort();
                    submitReview(t,s,lid,id);
                }catch(er) {
                    submitReview(t,s,lid,id);
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
