/**
* LAST MOD: APR 04 2009
* ---------------------
*/
defaultStatus="Freelancer Listing Portfolio::::";
//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>\";";

/*========================================================================*/
/*===DYNAMICALLY LOAD FLASH VID PLAYER SO WE DON'T GET IE SECURITY ISSUE==*/
function createPlayer(u,s,t,w,h,p) {//u=vid url; s=embed code (source code); t=title; w=width; h=height; p=player type
    u=unescape(u);
    s=unescape(s);
    //LET'S FIRST SHOW LOADING ICON
    var isLoading="<div class=\"mt10 ml10 alignL\"><img src=\"images/icon_loading.gif\" border=\"0\" class=\"alignM\" /> &nbsp; <strong>Loading player...</strong> </div>";
    document.getElementById('vidDiv').innerHTML=isLoading;
    //
    document.getElementById('vidDiv').innerHTML=s;
    /*
    if(s==4) {//-->BRIGHTCOVE SPECIFIC
        var emb="<embed src=\""+u+"\" bgcolor=\"#FFFFFF\" "+passF+" base=\"http://admin.brightcove.com\" name=\"flashObj\" width=\""+w+"\" height=\""+h+"\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\"></embed>";// allowscriptaccess=\"always\"
        document.getElementById('vidDiv').innerHTML=emb;
        return;
    }
    var emb="<embed src=\""+u+"\" "+passF+" name=\"flashObj\" width=\""+w+"\" height=\""+h+"\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowscriptaccess=\"always\"></embed>";
    var elements=new Array();
	try{
        var obj=document.createElement('object');
    	obj.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
    	obj.setAttribute('width',w);
    	obj.setAttribute('height',h);
		obj.innerHTML=emb;
	}catch(er) {
        //FOR IE ONLY
        var obj=document.createElement("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" data=\""+u+"\" width=\""+w+"\" height=\""+h+"\"></object>");
	}
	elements[0]=document.createElement('param');
	elements[0].setAttribute('name','movie');
	elements[0].setAttribute("value",u);
	elements[1]=document.createElement('param');
	elements[1].setAttribute('name','allowFullScreen');
	elements[1].setAttribute('value','true');
	elements[2]=document.createElement('param');
	elements[2].setAttribute('name','allowscriptaccess');
	elements[2].setAttribute('value','always');
	if(f!="") {
        elements[3]=document.createElement('param');
        elements[3].setAttribute('name','flashVars');
        elements[3].setAttribute('value',unescape(f));
    }
	for(var i=0;i<elements.length;i++) {
		obj.appendChild(elements[i]);
	}
	var parentObj=document.getElementById('vidDiv');
	parentObj.innerHTML="";
	parentObj.appendChild(obj);
	*/
    //
}
/*===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+" :::";
    //CREATE THE AJAX REQUEST OBJECT
    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) {
                    //
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
    var hh=((document.body.clientHeight)/2)-250;
    with(document.getElementById('dialogueDiv').style) {
        display="block";
        left="160px";
        top="150px";//hh+"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;
    }
    //CREATE THE AJAX REQUEST OBJECT
    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) {
                    //do nothing
                }
            }
            //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;
    //CREATE THE AJAX REQUEST OBJECT
    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) {
                    //do nothing
                }
            }
            //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;
    }
    //CREATE THE AJAX REQUEST OBJECT
    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();
                    submitRating(t,lid,id);
                }catch(er) {
                    //
                }
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
/*============================================================*/
/*====SHARING PROFILE TO OTHERS (SENDING EMAIL)===============*/
function submitShare(s,m,l,v) {//s=session; m=member ID; l=listing ID; v=passed values
    //CREATE THE AJAX REQUEST OBJECT
    var rq=xmlObject(2500,closureFunction);
    if(typeof(rq)!="object") {
        alert(rq);
        return false;
    }
    var theURL=baseURL+"styles/ajax.php";
    var params="session="+s+"&id="+m+"&lid="+l+"&value="+v+"&type=&action=shareit&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;
                if(myInfo.indexOf('following emails')!=-1 || myInfo=="captcha-error") {
                    alert(myInfo);
                }else {
                    document.getElementById('shareSuccessDiv').innerHTML="<img src=\"images/checkmark.jpg\" border=\"0\" />";
                }
                killShare();
            }else{
                try{
                    rq.abort();
                }catch(er) {
                    //do nothing
                }
                alert("I'm sorry but I lost connection.\nPlease refresh the page and try again.");
            }
            document.getElementById('sharingGifDiv').innerHTML="";
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
function openShare(t,p) {//t=self reference; p=profile page
    var c="Check out this profile link:\nwww.freelancerlisting.net/"+p;
    document.getElementById('shareProfileDiv').style.display="block";
    document.getElementById('shareContent').value=c;
}
function killShare() {
    document.getElementById('shareProfileDiv').style.display="none";
}
function shareIt(t,s,m,l) {//t=self reference; s=session; m=member ID; l=listing ID;
    var sendName=document.getElementById('shareName').value;
    var sendTo=document.getElementById('shareTo').value;
    var sendSubject=document.getElementById('shareSubject').value;
    var sendContent=document.getElementById('shareContent').value;
    var captcha=document.getElementById('shareCaptcha').value;
    //
    if(sendName.replace(/ /g,'')=="") {
        alert("Please enter your name.");
        return false;
    }else if(sendTo.replace(/ /g,'')=="") {
        alert("Please enter at least 1 email to share this with.");
        return false;
    }else if(sendContent.replace(/ /g,'')=="") {
        alert("Please enter a message");
        return false;
    }else if(captcha.replace(/ /g,'')=="") {
        alert("Please enter the captcha code you see to the right");
        return false;
    }
    //IF ALL IS GOOD
    var v=sendName+"|"+sendTo+"|"+sendSubject+"|"+sendContent+"|"+captcha;
    document.getElementById('sharingGifDiv').innerHTML=" <img src=\"images/icon_loading.gif\" border=\"0\" class=\"floatL\" /> &nbsp; sharing it now...";
    submitShare(s,m,l,v);
}
function clearSendTo(t) {
    t.value="";
    t.style.color="#000000";
    t.focus();
}

