function setLocationPrefs(theObj) {
prefKeyA = "prefJMlocation";
prefValB = getCurrListVal(document.getElementById("prefJMcountry"));
prefValA = getCurrListVal(theObj);
document.location.href = siteWebDir + "/ccki-all.php?ct=90&cc=prefJMcountry&cv=" + prefValB + "&ccOne=prefJMlocation&cvOne=" + prefValA + "&ctOne=90";
}

function doCurrentCountry(theObj) {
prefValA = getCurrListVal(theObj);
if(prefValA == "en_US") {
document.getElementById("div-stateSelect").style.visibility="visible";
document.getElementById("div-stateSelect").style.display="block";
} else {
document.getElementById("div-stateSelect").style.visibility="hidden";
document.getElementById("div-stateSelect").style.display="none";
prefKeyA = "prefJMcountry";
prefKeyB = "prefJMlocation";
prefValB = "all";
document.location.href = siteWebDir + "/ccki-all.php?ct=90&cc=prefJMcountry&cv=" + prefValA + "&ccOne=prefJMlocation&cvOne=" + prefValB + "&ctOne=90";
}
}


function doJMSWSubmit(sTerm, sLocale, sZone) {
document.getElementById("jobSearchWords").value = sTerm;
document.getElementById("currJMcountry").value = sLocale;
document.getElementById("currJMlocation").value = sZone;
document.jmSWordsForm.submit();
}


function getRecentSearches(theObj, theEvent) {
setCurrDivPopUp('getSearches', theObj, theEvent, 250, -1, -1);
}

function doJMPopupSearch(jTerm) {
// waitingDiv = "job" + document.getElementById("jobTopicID").value + "-maincontainer";
// loadWaiting(waitingDiv, "loading...");
hideDivBox('searchesPopUp');
document.getElementById("jmSearchTerm").value = jTerm;
getJMwordDSearch(jTerm);
}

function addSearchLink(jTerm) {
newTerm = "<a href=\"javascript:doJMPopupSearch('" + jTerm + "');\"><u>" + jTerm + "</u></a><br>";
oldLinks = document.getElementById("div-SearchesPopUp").innerHTML;
newLinks = newTerm + oldLinks;
document.getElementById("div-SearchesPopUp").innerHTML = newLinks;
// alert("addSearchLink");
}


function imVisited(obj) {
obj.style.color = "#800080";
}
 
function renderJobs(jobTopicID, jobArray, numRes) {
var theDivObjString = "job" + jobTopicID + "-maincontainer";
var theDivObj = getObjbyID(theDivObjString);
//MAIN FUNCTION: rssdisplaybox("rssfeed_id", "rssbox_id", "rssbox_class")
cssJobRssBox=new rssdisplaybox('job' + jobTopicID, 'job' + jobTopicID, "someclass", jobArray, theDivObj)
cssJobRssBox.set_items_shown(300, numRes) //Fetch 8 entries, but display only 3 at a time (pagination links auto created)
cssJobRssBox.set_template("default") //Use "default" template, which outputs title + description + date
cssJobRssBox.setpagination("manual", "divVPag" + jobTopicID);
cssJobRssBox.start() //Required: start script
}


/* may be to delete */
function hideAllPopUps() {
try {
document.getElementById("pinPopUp").style.visibility="hidden";
document.getElementById("pinPopUp").style.display="none";
document.getElementById("ratePopUp").style.visibility="hidden";
document.getElementById("ratePopUp").style.display="none";
document.getElementById("sendPopUp").style.visibility="hidden";
document.getElementById("sendPopUp").style.display="none";
document.getElementById("locationPopUp").style.visibility="hidden";
document.getElementById("locationPopUp").style.display="none";
} catch (e) {
// alert("hideAllPopUps:: " + e);
}
}




function doEventPinFeed() {
var canSend = "yes";
var currPinCommentA = document.getElementById("tAreaPinComment").value;
if(currPinCommentA.length > 160) {
currPinCommentA = currPinCommentA.substring(0, 160);
}
currPinCommentB = strip_tags(currPinCommentA);
currPinCommentC = currPinCommentB.replace(/["']{1}/gi,"");
document.getElementById("currFeedComment").value = currPinCommentC;
document.getElementById("currFldrTopic").value = getCurrListVal(document.getElementById("selectPinTopicID"));
doFeedEvent("pinPopUp");
}




 
function doEventApplyFeed(theObj, theEvent, doEType, sendFeedArray, sendFeedAction) {
setEditedJobLetter("noQval");
var canSend = "yes";
if(sendFeedArray == "noQvalue") {
sendFeedArray = document.getElementById("currFeedID").value;
}
var sendFromName = document.getElementById("tfieldApplyFromName").value;
var sendFromEmail = document.getElementById("tfieldApplyFromEmail").value;
var sendToName = document.getElementById("tfieldApplyToName").value;
var sendToEmail = document.getElementById("tfieldApplyToEmail").value;
var sendToPhone = document.getElementById("tfieldApplyToPhone").value;
var sendSubject = document.getElementById("tfieldApplySubject").value;
var secCode = document.getElementById("securityCode").value; 
var confSecCode = document.getElementById("confApplySecCode").value;
var sendComment = document.getElementById("tAreaApplyComment").value;
 


var alertMsg = "";
if(sendFromName.length > 120) {
alertMsg += "Please enter valid First and Last Name.   Max length: 120\n";
canSend = "no";
}


if((sendFromEmail.length > 5) && (sendFromEmail.length < 120)  && (sendFromEmail.indexOf("@") != -1) && (sendFromEmail.indexOf(".") != -1)) {
dummyval = "yes";
}  else {
alertMsg += "Please enter a valid email address.\n";
canSend = "no";
}

if(sendFromName.length > 120) {
alertMsg += "Please enter valid First and Last Name.   Max length: 120\n";
canSend = "no";
} else {
if(sendFromName.length < 2) {
document.getElementById("tfieldApplyFromName").value  = sendFromEmail;
}
}


if((sendToEmail.length > 5) && (sendToEmail.length < 120)  && (sendToEmail.indexOf("@") != -1) && (sendToEmail.indexOf(".") != -1)) {
dummyval = "yes";
}  else {
alertMsg += "Please enter the employers email address.\n";
canSend = "no";
}

if(sendToName.length > 120) {
alertMsg += "Please enter a valid employers name.   Max length: 120\n";
canSend = "no";
} else {
if(sendToName.length < 2) {
document.getElementById("tfieldApplyToName").value  = sendToEmail;
}
}

if(sendFromEmail == sendToEmail) {
alertMsg += "Your email and the employers email cannot be the same.\n";
canSend = "no";
}

if(sendComment.length > 160) {
alertMsg += "Max length on send comment is: 160\n";
canSend = "no";
} else {
thisSendCommentB = strip_tags(sendComment);
thisSendCommentC = thisSendCommentB.replace(/["']{1}/gi,"");
}

if((sendSubject.length > 200) || (sendSubject.length < 2)){
alertMsg += "You must enter an email subject [max: 200 characters]\n";
canSend = "no";
} else {
sendSubject = strip_tags(sendSubject);
sendSubject = sendSubject.replace(/["']{1}/gi,"");
}

if(secCode == confSecCode) {
} else {
alertMsg += "Security codes do not match.\n";
canSend = "no";
}

if(canSend == "no") {
alert(alertMsg);
} else {
// alert("canSEnd == yes");
sendMessage = "";
currApplyFeedAction = document.getElementById("currFeedAction").value;
currApplyJobStatus = document.getElementById("currJobStatus").value
if((currApplyFeedAction == "applyFeed") || (currApplyJobStatus == "sent")) {
sendMessage += "Note: This application has already been sent.\r\n";
}
document.getElementById("currFeedAction").value = "applyFeed";
document.getElementById("currSendFromName").value = sendFromName;
document.getElementById("currSendFromEmail").value = sendFromEmail;
document.getElementById("currSendToName").value = sendToName;
document.getElementById("currSendToEmail").value = sendToEmail;
document.getElementById("currSendToPhone").value = sendToPhone;
document.getElementById("currSendSubject").value = sendSubject;
document.getElementById("currSendComment").value = thisSendCommentC;
sendMessage += "Send job application to: " + sendToEmail + "?";
if(confirm(sendMessage)) {
startEventTimer('divMessagePopUp', "<img src=\"" +  siteWebDir + "/images/misc/loading.gif\">Sending...", "Sorry try Later");
setCurrDivPopUp('getMessagePopUp', theObj, theEvent, 5, 5, 5);
document.actionCommForm.submit();
}
} // end of can send is no
}

/* 
* after job prospect is sent
* page-actionComms-applyFeed will call it back here
*/

function confirmSentApplyFeed() {
try  {
stopEventTimer("divMessagePopUp", "Application sent! <a href=javascript:hideDivBox('messagePopUp');>Close</a>");
// may have to change captcha code on send
setSecCode();
} catch(e) {
}
}

/*
* These are admin functions
* Should be in admin.js
*/

function doAEventRateFeed() {
var canSend = "yes";
var currPinCommentA = document.getElementById("tAreaRateComment").value;
if(currPinCommentA.length > 260) {
currPinCommentA = currPinCommentA.substring(0, 260);
}
currPinCommentB = strip_tags(currPinCommentA, "<a>");
// currPinCommentC = currPinCommentB.replace(/["']{1}/gi,"");
document.getElementById("currFeedImage").value = document.getElementById("tfieldFeedImage").value;
document.getElementById("currFeedComment").value = currPinCommentB;
document.getElementById("currFeedRating").value = getCurrListVal(document.getElementById("selectRate"));
doFeedEvent("ratePopUp");
document.getElementById("currFeedImage").value = '';
document.getElementById("currFeedComment").value = '';
document.getElementById("currFeedComment").value = '';
}

function doEventRateFeed() {
var canSend = "yes";
var currPinCommentA = document.getElementById("tAreaRateComment").value;
if(currPinCommentA.length > 260) {
currPinCommentA = currPinCommentA.substring(0, 260);
}
currPinCommentB = strip_tags(currPinCommentA, "<a>");
// currPinCommentC = currPinCommentB.replace(/["']{1}/gi,"");
document.getElementById("currFeedImage").value = document.getElementById("tfieldFeedImage").value;
document.getElementById("currFeedComment").value = currPinCommentB;
document.getElementById("currFeedRating").value = getCurrListVal(document.getElementById("selectRate"));
doFeedEvent("ratePopUp");
document.getElementById("currFeedImage").value = '';
document.getElementById("currFeedComment").value = '';
document.getElementById("currFeedComment").value = '';
}




function markPage(theObj, theEvent, shortUrlTitle, pageUrl, pageTitle, pageTopic) {
document.getElementById("td-shortUrlTitle").innerHTML = shortUrlTitle;
document.getElementById("hfield-pin-pageUrl").value = pageUrl;
document.getElementById("hfield-pin-pageTitle").value = pageTitle;
document.getElementById("hfield-pin-pageTopic").value = pageTopic;
setCurrDivPopUp('menuFile', theObj, theEvent, -1, -1);
}



function getPinnedUrls(theFolderID) {
document.getElementById("currFeedAction").value = "getPinnedUrls";
document.getElementById("currFldrTopic").value = theFolderID;
document.actionCommForm.submit();
}


function setNumResults(numRess) {
document.getElementById("numResToShow").value = numRess;
refreshPinnedUrls();
}


function showFeedEvent(theObj, theEvent, eventString, feedID, shortUrlTitle, pageUrl, pageTitle, feedTopic) {
hideAllPopUps();
try {
document.getElementById("tfieldFeedImage").value = "";
document.getElementById("tfieldImgSearch").value = "";
document.getElementById("tAreaRateComment").value = "";
} catch(e) {
}


document.getElementById("currShortTitle").value = shortUrlTitle;
document.getElementById("currFeedAction").value = eventString;
document.getElementById("currFeedID").value = feedID;
document.getElementById("currFeedTopic").value = feedTopic;
document.getElementById("currPageUrl").value = pageUrl;
document.getElementById("currPageTitle").value = pageTitle;
var tdCntstring = "td_feedContent" + feedID;
noQfeedContent = strip_quotes(document.getElementById(tdCntstring).innerHTML);
noTfeedContent = strip_tags(noQfeedContent, "<a><b><br><p>");
document.getElementById("currFeedContent").value = noTfeedContent;

var tdCmntString = "tdFeedComment" + feedID;
var tdImgString = "tdFeedImage" + feedID;
// document.getElementById("tAreaRateComment").value = document.getElementById(tdCmntString).innerHTML;

// try and get image src
if(document.getElementById(tdImgString)) {
document.getElementById("tfieldImgSearch").value = document.getElementById(tdImgString).src;
}
setCurrDivPopUp(eventString, theObj, theEvent, 5, 5, 5);
}




function doFeedEvent(theDiv) {
alert("doFeedEvent(theDiv)");
hideDivBox(theDiv);
eventString = document.getElementById("currFeedAction").value;
feedID = document.getElementById("currFeedID").value;
var tdIDstring = "td_" + eventString + feedID;
document.getElementById(tdIDstring).innerHTML = "<img src=\"" +  siteWebDir + "/images/misc/loading.gif\">";
document.actionCommForm.submit();
fEvErrorTimer = setTimeout("throwFeventError()",10000); 
}



function doPinJobPropsect(theObj, theEvent, eventString, feedID, shortUrlTitle, pageUrl, pageTitle, feedTopic, jobDate, jobLocation) {
// hideAllPopUps();
if(Get_Cookie("userNum")) {
document.getElementById("currShortTitle").value = shortUrlTitle;
document.getElementById("currFeedAction").value = eventString;
document.getElementById("currFeedID").value = feedID;
document.getElementById("currFeedTopic").value = feedTopic;
document.getElementById("currPageUrl").value = pageUrl;
document.getElementById("currPageTitle").value = pageTitle;
document.getElementById("currJobDate").value = jobDate;
document.getElementById("currJobLocation").value = jobLocation;
var tdCntstring = "td_feedContent" + feedID;
noQfeedContent = strip_quotes(document.getElementById(tdCntstring).innerHTML);
noTfeedContent = strip_tags(noQfeedContent, "<a><b><br><p>");
document.getElementById("currFeedContent").value = noTfeedContent;
var tdIDstring = "td_" + eventString + feedID;
// alert("tdIDstring: " + tdIDstring);
document.getElementById(tdIDstring).innerHTML = "<img src=\"" +  siteWebDir + "/images/misc/loading.gif\">";
document.actionCommForm.submit();
fEvErrorTimer = setTimeout("throwFeventError()",10000); 
// document.getElementById(tdIDstring).focus();
} else {
gotoLogin();
}
}

function throwFeventError() {
eventString = document.getElementById("currFeedAction").value;
feedID = document.getElementById("currFeedID").value;
var tdIDstring = "td_" + eventString + feedID;
document.getElementById(tdIDstring).innerHTML = "<font color=red>Sorry, try later..</font>";
}

function stopFeventError(fEventString) {
try {
clearTimeout(fEvErrorTimer);
eventString = document.getElementById("currFeedAction").value;
feedID = document.getElementById("currFeedID").value;
var tdIDstring = "td_" + eventString + feedID;
document.getElementById(tdIDstring).innerHTML = fEventString;

} catch(e) {
}
}


