﻿
/// lyw.js


function LoveYourWork() {
    return void (0);
}


var isIE = (navigator.appName == 'Microsoft Internet Explorer');



function isEnterKey(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
       else if (e.which) code = e.which;
    return (code == 13);
}


function gEl(id) {
    return document.getElementById(id);
}

String.prototype.replaceAll = function(strTarget, strSubString) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);
    while (intIndexOfMatch != -1) {
        strText = strText.replace(strTarget, strSubString)
        intIndexOfMatch = strText.indexOf(strTarget);
    }
    return (strText);
}

function formatPrice(fnPrice) {
    return addCommas(''+parseFloat(fnPrice).toFixed(2));
}

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function cancelBubble(windowEvent) {
    var objEvent;
    try {
        objEvent = windowEvent;
        objEvent.cancelBubble = true;
    } catch (ex) {
    }
}


function __doAsyncPostBack(eventName, eventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }
    //alert(eventName + " // " + eventArgs);
    __doPostBack(eventName, eventArgs);

}

function goPhoto(eventName) {
    __doPostBack(eventName, '/jobseeker/profile/edit/photos/');
}

function clrFmArgs() {
    gEl('aspnetForm').action = 'default.aspx';
}

function popupCenter(url, width, height, name, parms) {
   var left = Math.floor( (screen.width - width) / 2)
   var top = Math.floor( (screen.height - height) / 2)
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width
   //var winParms = "top=200,left=200,height=400,width=300"
   if (parms)winParms += "," + parms
   var win = window.open(url, name, winParms)
   //if (parseInt(navigator.appVersion) >= 4)win.window.focus()
   return win
}

function printProfile(lywid,ut)
{
    if(ut.toLowerCase()!="employer") {
        popupCenter('/jobseeker/profile/print/?lywid='+lywid,730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    } else {
        popupCenter('/employer/jobseeker_profile/print/?lywid='+lywid,730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    }
}
function printCompanyProfile(lywid,ut)
{
    if(ut.toLowerCase()!="employer") {
        popupCenter('/jobseeker/employer_profile/print/?lywid='+lywid,730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    } else {
        popupCenter('/employer/profile/print/',730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    }
}
function printJobAd(guid,ut)
{
    if(ut.toLowerCase()!="employer") {
        popupCenter('/jobseeker/jobs_apply/print/?id='+guid,730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    } else {
        popupCenter('/employer/manage_job_ads/print/?id='+guid,730,500,'_blank','toolbars=no,directories=no,scrollbars=no');
    }
}
function showMap(sloc,coords){
    if(coords!=""){
        popupCenter('http://maps.google.com/?q='+coords,1000,600,'_blank','toolbars=no,directories=no,scrollbars=no');
    } else {
        popupCenter('http://maps.google.com/?q='+sloc,1000,600,'_blank','toolbars=no,directories=no,scrollbars=no');
    }
}
function appNwSb(guid, ut, cid) {
    if (ut.toLowerCase() == "jobseeker") {
    
        self.location = '#ja_' + guid;
        __doAsyncPostBack(cid + '_CurrentButton', guid);

    } else {

    alert("Apply for Job ~ Test Successful!\n\nJobseekers will/can apply for this Job\nusing the LoveYourWork.tv Online Job Application Form.\nYou will receive an email each time a Job Application is made,\nand be able to track Job Applications online with LoveYourWork.tv :)");
        
    }
}

function popupHTMLMsg(fsTxt){
  var d = window.open('about:blank')
  d.document.open();
  d.document.write(fsTxt);
  d.document.close();
  d.focus();
}

function xmlOC(bhID, opn) {
    if (opn) {
        $find(bhID)._doOpen();
    } else {
        $find(bhID)._doClose();
    }
}

function kpalv() {
//    alert("Keep Alive v1.0");
    AjaxPost('/_tools/ajaxkeepalive.aspx', 'x='+(Math.floor(Math.random()*100000)), 'kpalvr');
}
function kpalvr(resp) {
//    alert(resp + "\nClick OK to continue");
    if(resp!='alive'){
        alert('We\'re Sorry...\nYour LYW logon session has unexpectedly timed-out.\nPlease return to the home page and login again.');        
    }
}

function stopAd(clid) {
    if (confirm('Are you sure you want to STOP the Job Ad early?\nClick OK to Stop / Pull-Down this Job Ad.')) {
        __doPostBack(clid, 'stop');
    } else {
        prgN(gsPRGGuid);
    }
}

function tstIfce(url,wid){
    popHRIface(url,wid);
}
function popHRIface(url,wid){
    popupCenter(url, wid, (0+(screen.height)-100), '_blank', 'toolbars=no,directory=no,scrollbars=yes');
}

var sbmClid = '';
var sbmJaid = '';
var uploCl = false;
var uploRs = false;
function sbmJbAp(clid, jaid) {
    //hide the error box
    //alert(clid);
    gEl('err_' + jaid).style.display = 'none';
    //check all controls and set error style as required
    var bErr = false;
    if (gEl('Fullname_' + jaid).value == '') {
        gEl('ErrName_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrName_' + jaid).style.color = '';
    }
    if (gEl('Phone_' + jaid).value == '') {
        gEl('ErrPhone_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrPhone_' + jaid).style.color = '';
    }
    if (gEl('Email_' + jaid).value == '') {
        gEl('ErrEmail_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrEmail_' + jaid).style.color = '';
    }
    if (gEl('CountryID_' + jaid).value == '-1') {
        gEl('ErrCountry_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrCountry_' + jaid).style.color = '';
    }   
    if(gEl('ResumeOption1_'+jaid).checked==false &&   
       gEl('ResumeOption2_'+jaid).checked==false &&
       gEl('ResumeOption3_'+jaid).checked==false) {
        gEl('ErrResume1_' + jaid).style.color = 'red';
        gEl('ErrResume2_' + jaid).style.color = 'red';
        gEl('ErrResume3_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrResume1_' + jaid).style.color = '';
        gEl('ErrResume2_' + jaid).style.color = '';
        gEl('ErrResume3_' + jaid).style.color = '';
    }
    if(gEl('CoverLetterOption1_' + jaid).checked == false &&
       gEl('CoverLetterOption2_' + jaid).checked == false &&
       gEl('CoverLetterOption3_' + jaid).checked == false) {
        gEl('ErrCover1_' + jaid).style.color = 'red';
        gEl('ErrCover2_' + jaid).style.color = 'red';
        gEl('ErrCover3_' + jaid).style.color = 'red';
        bErr = true;
    } else {
        gEl('ErrCover1_' + jaid).style.color = '';
        gEl('ErrCover2_' + jaid).style.color = '';
        gEl('ErrCover3_' + jaid).style.color = '';
    }
    if(gEl('CoverLetterOption1_' + jaid).checked && gEl('CoverLetterText_' + jaid).value=='') {
        gEl('ErrCover1_' + jaid).style.color = 'red';
        bErr = true;
    }
    if(gEl('Agreement_' + jaid).checked == false) {
        gEl('ErrAgreement1_' + jaid).style.color = 'red';
        gEl('ErrAgreement2_' + jaid).style.color = 'red';
        bErr = true;
    } else {
       gEl('ErrAgreement1_' + jaid).style.color = '';
       gEl('ErrAgreement2_' + jaid).style.color = '';
    }
    
    //ErrAgreement1_
    //if there are errors, show the error box, otherwise postback.
    if (bErr) {
        gEl('err_' + jaid).style.display = 'block';
        prgN(gsPRGGuid);
    } else {
        
        //disable all controls (but stop short of actually breaking their legs lol).
        sbmJCtrl(true, jaid);

        //setup globals
        uploCl = gEl('CoverLetterOption2_' + jaid).checked
        uploRs = gEl('ResumeOption2_' + jaid).checked
        sbmClid = clid;
        sbmJaid = jaid;
        
        // if there are file uploads then such need to be done first...
        // do uploads of Cover Letter & Resume (if there are ones)
        if (uploCl && (gEl('CoverLetterFile_'+jaid).value=="")) {
            gEl('CoverLetterUploader_' + jaid).contentWindow.upload();
            return;
        } else if (uploRs && (gEl('ResumeFile_'+jaid).value=="")) {
            gEl('ResumeUploader_' + jaid).contentWindow.upload();
            return;
        } else {
            //no files to upload? then just submit the async postback
            //alert('no files');
            sbmPsB()
        }
   
    }
}
function sbmJCtrl(state, jaid) {
    gEl('Fullname_' + jaid).disabled = state;
    gEl('Phone_' + jaid).disabled = state;
    gEl('Email_' + jaid).disabled = state;
    gEl('CommentsText_' + jaid).disabled = state;
    if(gEl('CoverLetterFile_'+jaid).value=="") {
        gEl('CoverLetterText_' + jaid).disabled = state;
        gEl('CoverLetterOption1_' + jaid).disabled = state;
        gEl('CoverLetterOption2_' + jaid).disabled = state;
        gEl('CoverLetterOption3_' + jaid).disabled = state;
        try { gEl('CoverLetterUploader_' + jaid).contentWindow.reactivate(state); } catch (ex) { }
    }
    if(gEl('ResumeFile_'+jaid).value=="") {
        gEl('LYWResume_' + jaid).disabled = state;
        gEl('ResumeOption1_'+jaid).disabled = state; 
        gEl('ResumeOption2_'+jaid).disabled = state;
        gEl('ResumeOption3_' + jaid).disabled = state;
        try { gEl('ResumeUploader_' + jaid).contentWindow.reactivate(state); } catch (ex) { }
    }
    gEl('EmailMe_' + jaid).disabled = state;
    gEl('Agreement_' + jaid).disabled = state;
}
function sbmChk(ja, ft){
    if (ft == 'c') {
        gEl('CoverLetterOption2_'+ja).checked = true;
    } else if (ft == 'r') {
        gEl('ResumeOption2_'+ja).checked = true;
    } else if (ft == 'c1') {
        gEl('CoverLetterOption1_'+ja).checked = true;
    }
}
function upDne(success, ja, ft, fname) {
    if (success == 1) {
        //put filename in hidden field
        if(ft=='c') {
            gEl('CoverLetterFile_'+ja).value=fname;
        } else if (ft=='r') {
            gEl('ResumeFile_'+ja).value=fname;
        }
        //signal next file to upload
        if (ft == 'c' && uploRs && (gEl('ResumeFile_'+sbmJaid).value=="")) {
            gEl('ResumeUploader_' + sbmJaid).contentWindow.upload();
            return;
        } else {
            //no more files, signal complete...
            sbmJCtrl(false, sbmJaid);
            //alert('121');
            setTimeout('sbmPsB()',20);
            return;
        }
    } else {
        //revert to edit mode, re-enable all controls, show an error
        if (ft == 'c') {
            gEl('ErrCover2_' + sbmJaid).style.color = 'red';
        } else {
            gEl('ErrResume2_' + sbmJaid).style.color = 'red';
        } 
        gEl('err_' + sbmJaid).style.display = 'block';
        uploCl = false
        uploRs = false
        sbmClid = '';
        var jaid = sbmJaid;
        sbmJaid = '';
        prgN(gsPRGGuid);
        sbmJCtrl(false, jaid);
    }
}
var sbmPsA = '';
function sbmPsB() {
    var clid = sbmClid
    var jaid = sbmJaid
    //sbmPsA = gEl('aspnetForm').action;
    //gEl('aspnetForm').action = "default.aspx?id=" + jaid;
    uploCl = false
    uploRs = false
    sbmClid = '';
    //self.location = '#ja_' + jaid;
    //setTimeout('sbmJmpBk', 4000);
    __doAsyncPostBack(clid, jaid);
}
function sbmJmpBk() {
    var jaid = sbmJaid
    sbmJaid = '';
    self.location = '#ja_' + jaid;
}
//function rstSbm() {
//    var clid = sbmClid
//    var jaid = sbmJaid
//    sbmClid = '';
//    sbmJaid = '';
//    if(gEl('Agreement_' + jaid))__doAsyncPostBack(clid, '');
//}

function ccpcD() {
    //alert('c=' + gEl('couponCode').value + '&p=' + gnPackageID + '&t=' + Math.floor(Math.random() * 1000));
    AjaxPost('/_tools/checkcouponcode.aspx', 'c=' + gEl('couponCode').value + '&p=' + gnPackageID + '&t=' + Math.floor(Math.random()*1000), 'ccpcR');
}
function ccpcC() {
    gEl('couponCodeMsg').innerHTML = "-";
    gEl('couponCodeAmount').innerHTML = "-";
    gEl('couponSummary').style.visibility = 'hidden';
    gEl('couponSummary').style.height = '0px';
    gEl('actualCouponCode').value='';
    gnCouponAmt = 0;
}
function ccpcR(resp) {
    prgN(gsPRGGuid);
    
    if(resp.indexOf('/')!=-1) {
        var code = resp.split('/');
        var amount = code[1];
        var msg = code[2];
        alert("The Coupon Code has been successfully validated:\n\"" + msg + "\"");
        gnCouponAmt = parseFloat(amount);
        gEl('couponSummary').style.visibility = 'visible';
        gEl('couponSummary').style.height = '32px';
        //setTimeout('colspancp()',100);
        gEl('couponDesc').innerHTML = msg;
        gEl('couponFinalAmt').innerHTML = '<span class=\"colorRed\">$' + gnCouponAmt.toFixed(2) + '</span>';
        gEl('couponCodeMsg').innerHTML = '<span style=\"color:darkgreen\">Code Applied Successfully</span>';
        gEl('couponCodeAmount').innerHTML = '<span class=\"colorRed\">$' + gnCouponAmt.toFixed(2) + '</span>';
        gEl('actualCouponCode').value=gEl('couponCode').value;
        CalcEO();
        
    } else {
        alert(resp);
        gEl('couponCodeMsg').innerHTML = '<span class=\"colorRed\">Code Not Validated</span>';
    }
    
    
}


function noEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}


var mOTimer = null;
var mTObj = null;
var mOObj = null;
var mOClas = '';
var mLObj = null;
var mLClas = null;
function mOva(obj, clas) {
    //if (obj == mTObj) {
    if(mOTimer != null) clearTimeout(mOTimer);
    if(obj != mTObj) {
        if (mLObj) mLObj.className = mLClas;
        mLObj = obj;
        mLClas = obj.className;
    }
    mTObj = obj;
    obj.className = clas;
}
function mHide() {
    mOObj.className = mOClas;
    mOObj = null;
    mOClas = '';
    //alert('hide:'+mOObj+'::'+mOClas);
}
function mOut(obj, clas) {
    if (obj != mLObj) {
        //mLObj.className = mLClas
        clearTimeout(mOTimer);
        return
    }
    mOObj = obj;
    mOClas = clas;
    mOTimer = setTimeout('mHide()', 70);
    //}
    //mOObj.className = mOClas;
}

//looking for jjaClk - search for it (its later in the document with the ajax functions)


function RmImg(fsFn) {
    //if (fiRw == null) fiRw = this.gsRw;
    //if (fiRw > this.iMRw || fiRw < 1) return;
    var sTmpVl = '';
    if (confirm('Remove the photo, ' + unescape(fsFn) + '?\nThis will be Permanent. Click OK if you are sure.\n')) {
        //postback remove request to remove file from disk
        gEl("photo_ac").value = "rm";
        gEl("photo_fn").value = unescape(fsFn);
        return true;
    } else {
        if (gsPRGGuid != '') prgN(gsPRGGuid);
        return false;
    }
}

function RmRsm(fsFn) {
    //if (fiRw == null) fiRw = this.gsRw;
    //if (fiRw > this.iMRw || fiRw < 1) return;
    var sTmpVl = '';
    if (confirm('Remove the resume, ' + unescape(fsFn) + '?\nThis will be Permanent. Click OK if you are sure.\n')) {
        //postback remove request to remove file from disk
        gEl("resume_ac").value = "rm";
        gEl("resume_fn").value = unescape(fsFn);
        return true;
    } else {
        if (gsPRGGuid != '') prgN(gsPRGGuid);
        return false;
    }
}

function emGd(m, w) {
    var h = 17;
    var j = 1;
    document.write('<div style=\"display:inline;width:' + w + ';height:17px;overflow:hidden;z-index:1;\">');
    //alert('emailaddress_02.swf?j=' + j + '&m=' + escape(m) + '&w=' + w);
    document.write('<object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" height=\"' + h + '\" width=\"' + w + '\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"scale\" value=\"noorder\"><param name=\"movie\" value=\"/images/emailaddress_02.swf?j=' + j + '&m=' + escape(m) + '&w=' + w + '\"><param name=\"Src\" value=\"/images/emailaddress_02.swf?j=' + j + '&m=' + escape(m) + '&w=' + w + '\"><param name=\"wmode\" value=\"transparent\"><param name=\"play\" value=\"1\"><param name=\"quality\" value=\"Best\"><param name=\"allownetworking\" value=\"all\"><param name=\"allowfullscreen\" value=\"false\"><embed src=\"/images/emailaddress_02.swf?j=' + j + '&m=' + escape(m) + '&w=' + w + '\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noorder\" wmode=\"transparent\" width=\"' + w + 'px\" height=\"' + h + 'px\"></embed></object>');

    document.write('</div>');
    
}
//products page
var gnPackageID = 0;
var gnCouponAmt = 0;
var gnBonusBasicQty = 0;
var gnBonusStandardQty = 0;
var gnBonusPremiumQty = 0;
var gnAdsBasicQty = 0;
var gnAdsStandardQty = 0;
var gnAdsPremiumQty = 0;
function EMPPkgClk(fsID) {
    if (fsID == "") return;
    ccpcC();
    for (a = 1; a < 20; a++) {
        if (gEl('PackageRow' + a)) {
            gEl('PackageRow' + a).className = 'bodyRow';
        }
    }
    gnPackageID = fsID;
    gEl('PackageRow' + gnPackageID).className = 'bodyRowChoice';
    gEl('PackageRadio' + gnPackageID).checked = true;
    var nPrice = gEl('PackagePrice' + gnPackageID).innerHTML;
    //alert(nPrice);
    gEl('PackageSubTotal').innerHTML = nPrice;
    CalcEO();
}
var gp_jpps = new Array();
function AddJpp(fsID, fsItemName, fsItemDesc, fnPrice, fiBasicAds, fiStandardAds, fiPremiumAds, fiJobBoardAds) {
    gp_jpps[fsID] = [fsItemName, fsItemDesc, fnPrice, fiBasicAds, fiStandardAds, fiPremiumAds, fiJobBoardAds];
}
var gp_jpis = new Array();
function AddJpi(fiPriceID, fiJobAdTypeID, fiQty, fnPrice) {
    gp_jpis[fiPriceID] = [fiJobAdTypeID, fiQty, fnPrice];
}
var gp_jpts = new Array();
function AddJpt(fiJobAdTypeID, fnPriceEach) {
    gp_jpts[fiJobAdTypeID] = fnPriceEach;
}
function CalcJA(fiJobAdTypeID, fiPriceID) {
    //update the row total
    var nPrice = 0;
    nPrice = gp_jpis[fiPriceID][2];
    gEl('JobAdPrice' + fiJobAdTypeID).innerHTML = formatPrice(nPrice);
    CalcEO();
}
function CalcEO() {

    var iIncAds1 = 0;
    var iIncAds2 = 0;
    var iIncAds3 = 0;
    var iIncAds7 = 0;
    var sPackageName = '';
    var sPackageDesc = '';
    var nPackagePrice = 0;
    var bFound = false;
    var sSaving = '';
    var nSaving = 0;
    var nOverallSaving = 0;
    var sOverallSaving = '';
    
    if (gnPackageID > 0) {

        sPackageName = gp_jpps[gnPackageID][0];
        sPackageDesc = gp_jpps[gnPackageID][1];
        nPackagePrice = parseFloat(gp_jpps[gnPackageID][2]).toFixed(2);
        iIncAds1 = parseInt(gp_jpps[gnPackageID][3]);
        iIncAds2 = parseInt(gp_jpps[gnPackageID][4]);
        iIncAds3 = parseInt(gp_jpps[gnPackageID][5]);
        iIncAds7 = parseInt(gp_jpps[gnPackageID][6]);
        bFound = (iIncAds1 != 0) || (iIncAds2 != 0) || (iIncAds3 != 0);
    }

    var nAdType1 = parseInt(gEl('JobAdQty1').value)
    var nPrice1 = parseFloat(gp_jpis[nAdType1][2]);
    var nQty1 = parseInt(gp_jpis[nAdType1][1]);
    var nPEach1 = parseFloat(gp_jpts[gp_jpis[nAdType1][0]]);
    var nSaving1 = (nPEach1 * nQty1) - nPrice1;
    var sSaving1 = (nSaving1 > 0) ? "<i style=\"font-size:11px;color:gray;\">RRP <strike>$" + (nPEach1 * nQty1).toFixed(0) + "</strike></i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " : ""; 
    gEl('JobAds1Qty').innerHTML = nQty1;
    gEl('JobAds1Price').innerHTML = sSaving1 + '$' + formatPrice(nPrice1);

    var nAdType2 = parseInt(gEl('JobAdQty2').value)
    var nPrice2 = parseFloat(gp_jpis[nAdType2][2]);
    var nQty2 = parseInt(gp_jpis[nAdType2][1]);
    var nPEach2 = parseFloat(gp_jpts[gp_jpis[nAdType2][0]]);
    var nSaving2 = (nPEach2 * nQty2) - nPrice2;
    var sSaving2 = (nSaving2 > 0) ? "<i style=\"font-size:11px;color:gray;\">RRP <strike>$" + (nPEach2 * nQty2).toFixed(0) + "</strike></i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " : "";
    gEl('JobAds2Qty').innerHTML = nQty2;
    gEl('JobAds2Price').innerHTML = sSaving2 + '$' + formatPrice(nPrice2);

    var nAdType3 = parseInt(gEl('JobAdQty3').value)
    var nPrice3 = parseFloat(gp_jpis[nAdType3][2]);
    var nQty3 = parseInt(gp_jpis[nAdType3][1]);
    var nPEach3 = parseFloat(gp_jpts[gp_jpis[nAdType3][0]]);
    var nSaving3 = (nPEach3 * nQty3) - nPrice3;
    var sSaving3 = (nSaving3 > 0) ? "<i style=\"font-size:11px;color:gray;\">RRP <strike>$" + (nPEach3 * nQty3).toFixed(0) + "</strike></i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " : "";
    gEl('JobAds3Qty').innerHTML = nQty3;
    gEl('JobAds3Price').innerHTML = sSaving3 + '$' + formatPrice(nPrice3);

    var nAdType7 = parseInt(gEl('JobAdQty7').value)
    var nPrice7 = parseFloat(gp_jpis[nAdType7][2]);
    var nQty7 = parseInt(gp_jpis[nAdType7][1]);
    var nPEach7 = 40; //parseFloat(gp_jpts[gp_jpis[nAdType7][0]]);
    var nSaving7 = (nPEach7 * nQty7) - nPrice7;
    var sSaving7 = (nSaving7 > 0) ? "<i style=\"font-size:11px;color:gray;\">RRP <strike>$" + (nPEach7 * nQty7).toFixed(0) + "</strike></i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " : "";
    gEl('JobAds7Qty').innerHTML = nQty7;
    gEl('JobAds7Price').innerHTML = sSaving7 + '$' + formatPrice(nPrice7);


    var nJobAdsSubTotal = (isNaN(nPrice1) ? 0 : nPrice1) + (isNaN(nPrice2) ? 0 : nPrice2)
                          + (isNaN(nPrice3) ? 0 : nPrice3) + (isNaN(nPrice7) ? 0 : nPrice7);
    
    if (nJobAdsSubTotal < 0) nJobAdsSubTotal = 0;
    
    gEl('JobAdSubTotal').innerHTML = '$' + formatPrice(nJobAdsSubTotal);


    if (gnPackageID > 0) {
        
        var sBuf = "&nbsp;0";
        if (bFound) {
            sBuf = "<div class=\"fineprint\">";
            if (iIncAds1 > 0) sBuf += iIncAds1 + " basic<br />";
            if (iIncAds2 > 0) sBuf += iIncAds2 + " standard<br />";
            if (iIncAds3 > 0) sBuf += iIncAds3 + " premium<br />";
            if (iIncAds7 > 0) sBuf += iIncAds7 + " job&nbsp;board<br />";
            if(nPackagePrice<499){
                nSaving = (iIncAds1 * nPEach1) + (iIncAds2 * nPEach2) + (iIncAds3 * nPEach3)  + (iIncAds7 * nPEach7) + parseInt(nPackagePrice);
            } else {
                nSaving = ((iIncAds1 * nPEach1) + (iIncAds2 * nPEach2) + (iIncAds3 * nPEach3) + (iIncAds7 * nPEach7) + 500);
            }
            if (nSaving > 0) sSaving = "<i style=\"font-size:11px;color:gray;\">RRP <strike>$" + nSaving.toFixed(0) + "</strike></i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            nSaving -= parseInt(nPackagePrice);
            sBuf += "</div>";
        }
        
        gEl('MembershipIncludedAds').innerHTML = sBuf;

        gEl('MembershipSummaryName').innerHTML = sPackageName;
        gEl('MembershipSummaryDesc').innerHTML = sPackageDesc;
        gEl('MembershipSummaryPrice').innerHTML = sSaving + '$' + nPackagePrice;

    }
    var nTotalExGST = 0;
    var nTotalIncGST  = 0;
    //alert(gnCouponAmt);
    if(gnCouponAmt!=0) {
        gEl('couponSummary').style.visibility = 'visible';
        gEl('couponSummary').style.height = '32px';
        //setTimeout('colspancp()',100);
        nOverallSaving = Math.abs(gnCouponAmt);
        nTotalExGST = parseInt((isNaN(nPackagePrice) ? 0 : nPackagePrice)) + parseInt((isNaN(nJobAdsSubTotal) ? 0 : nJobAdsSubTotal)) + gnCouponAmt;
        if(nTotalExGST>0.09){
            nTotalIncGST = (nTotalExGST / 10) * 11;
        } else {
            nTotalIncGST = nTotalExGST;
        }
    } else {
        gEl('couponSummary').style.visibility = 'hidden';
        gEl('couponSummary').style.height = '0px';
        nOverallSaving = parseInt(nSaving) + parseInt(nSaving1) + parseInt(nSaving2) + parseInt(nSaving3) + parseInt(nSaving7);
        nTotalExGST = parseInt((isNaN(nPackagePrice) ? 0 : nPackagePrice)) + parseInt((isNaN(nJobAdsSubTotal) ? 0 : nJobAdsSubTotal));
        nTotalIncGST = (nTotalExGST / 10) * 11;
    }
    if (nOverallSaving > 0) sOverallSaving = "<i style=\"font-size:11px;color:gray;font-weight:normal;\">SAVE $" + nOverallSaving.toFixed(0) + " ~</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

    if (nTotalExGST < 0) nTotalExGST = 0;
    if (nTotalIncGST < 0) nTotalIncGST = 0;
    
    gEl('SummaryExTaxTotal').innerHTML = sOverallSaving + '$' + formatPrice(nTotalExGST);
    gEl('SummaryIncTaxTotal').innerHTML = '$' + formatPrice(nTotalIncGST);
    
}


var helpGuid = '';
var helpTimer = null;
function showHelp(guid, delay) {
    helpGuid = guid;
    if (delay > 0) {
        clearTimeout(helpTimer);
        helpTimer = setTimeout('displayHelp()', delay);
    } else {
        displayHelp();
    }
}
function displayHelp() {
    gEl('help_' + helpGuid).style.display = 'block';
}
function hideHelp(guid) {
    gEl('help_' + guid).style.display = 'none';
    try { clearTimeout(helpTimer); } catch (ex) { }
}


//SHOW or HIDE Watermarks
var wm_cache = new Array();
function sWM(guid) {
    //if(!gEl('wm_'+guid))alert('not found: wm_'+guid);
    if(gEl('wm_' + guid))gEl('wm_' + guid).style.display = 'block'; 
    if (wm_cache.length >= 0) {
        for (a = 0; a < wm_cache.length; a++) {
            if(gEl(wm_cache[a])) {
                switch((gEl(wm_cache[a]).tagName).toLowerCase()){
                    case "input":
                        if (gEl(wm_cache[a]).type=="text"){
                            if((gEl(wm_cache[a]).value).length==0){
                                if(gEl('wm_' + wm_cache[a]))gEl('wm_' + wm_cache[a]).style.display = 'block'; 
                            }
                        }
                    break;
                    case "select":
                        if (gEl(wm_cache[a]).value == '-1' || gEl(wm_cache[a]).value == '') {
                            if(gEl('wm_' + wm_cache[a]))gEl('wm_' + wm_cache[a]).style.display = 'block'; 
                        }
                    break;
                    case "textarea":
                        if((gEl(wm_cache[a]).value).length==0){
                            if(gEl('wm_' + wm_cache[a]))gEl('wm_' + wm_cache[a]).style.display = 'block'; 
                        }
                    break;
                }
            } else {
                if(gEl('wm_' + wm_cache[a]))gEl('wm_' + wm_cache[a]).style.display = 'block'; 
            }
        }
        wm_cache = new Array();
    }
    
}
function hWM(guid) {
    //if (!gEl('wm_' + guid)) alert('not found: wm_' + guid);
    if(gEl('wm_' + guid))gEl('wm_' + guid).style.display = 'none';
    wm_cache.push(guid);
}
function dWM(obj, guid) {
    if (obj.value == '-1' || obj.value == '') {
        sWM(guid);
    } else {
        hWM(guid);
    }
}
function dclWM(guid) {
    if (gEl('v_' + guid).value == '-1' || ''+gEl('v_' + guid).value == '') {
        //alert("noValue showWM: " + gEl('v_' + guid).value);
        sWM(guid);
    } else {
        //alert('hasValue hideWM: ' + gEl('v_' + guid).value);
        hWM(guid);
    }
}
function tWM(obj, tguid, maxlen) {
    if (obj.value == '' && document.activeElement != obj) {
        sWM(tguid);
    } else {
        //alert('xxx:' + tguid);
        try {
          if(obj.value.length>maxlen) {
            obj.value=obj.value.substring(0,maxlen);
            alert('A maximum of ' + maxlen + ' characters - limit reached.');
          }
        } catch(ex){
        }
        hWM(tguid);
    }
}
function oWM(obj) {
    if (obj.value == '' && document.activeElement != obj) {
        sWM(obj.id);
    } else {
        //alert('xxx:' + tguid);
        hWM(obj.id);
    }
}

//XMLField Row Hilighting on Hover
var mROTimer = null;
var mRTObj = null;
var mROObj = null;
var mROClas = '';
var mRLObj = null;
var mRLClas = null;
function hRow(obj) {
    var clas = 'lywXMLTH';
    //if (obj == mTObj) {
    if(mROTimer != null) clearTimeout(mROTimer);
    if(obj != mRTObj) {
        if (mRLObj) mRLObj.className = mRLClas;
        mRLObj = obj;
        mRLClas = obj.className;
    }
    mRTObj = obj;
    obj.className = clas;
}
function nHide() {
    mROObj.className = mROClas;
    mROObj = null;
    mROClas = '';
    //alert('hide:'+mOObj+'::'+mOClas);
}
function nRow(obj)  {
    var clas = 'lywXMLT';
    if (obj != mRLObj) {
        //mLObj.className = mLClas
        clearTimeout(mROTimer);
        return
    }
    mROObj = obj;
    mROClas = clas;
    mROTimer = setTimeout('nHide()', 70);
    //}
    //mOObj.className = mOClas;
}


//Toggle Button
function togBtn(guid) {
    //alert(guid);
    var sVal = gEl(guid + '_ToggleButtonValue').value;
    if (sVal == 'False') {
        gEl(guid + '_ToggleButtonValue').value = 'True';
        gEl('tbon_' + guid).style.display = 'block';
        gEl('tboff_' + guid).style.display = 'none';
        gEl('tbtxon_' + guid).style.display = 'block';
        gEl('tbtxoff_' + guid).style.display = 'none';
    } else {
        gEl(guid + '_ToggleButtonValue').value = 'False';
        gEl('tbon_' + guid).style.display = 'none';
        gEl('tboff_' + guid).style.display = 'block';
        gEl('tbtxon_' + guid).style.display = 'none';
        gEl('tbtxoff_' + guid).style.display = 'block';
    }
    //alert(gEl('v_' + guid).value);
}


var gsPRGGuid = '';

var xmlRs = new Array();
var oRw;
var giRwDx = 0;
var gsFnStor = "";
var gbFnAct = false;
function fXRs(fsRsFn, fiTsTmout) {
    if (gbFnAct) return;
    gsFnStor = fsRsFn;
    gsFnAct = true;
    //alert("executing:\n" + gsFnStor);
    setTimeout('fXRsTo()',fiTsTmout);
}
function fXRsTo() {
    gbFnAct = false;
    if (gsFnStor != "") eval(gsFnStor);
    //alert("executed:\n" + gsFnStor);
}
function selSwp(lst1, lst2) {
    //tmp store lst1 and lst2 selidxs
    var lst1idx = lst1.selectedIndex;
    var lst2idx = lst2.selectedIndex;
    var lst1len = lst1.length;
    //put lst1 opts in tmparray
    var tmparrv = new Array();
    var tmparrt = new Array();
    for (var i1 = 0; i1 < lst1.length; i1++) {
        tmparrv[i1] = lst1.options[i1].value;
        tmparrt[i1] = lst1.options[i1].text;
    }
    //clear lst1
    for (var i1 = 0; i1 < lst1.length; i1++) {
        lst1.options[0] = null;
    }
    //copy lst2 opts to lst1
    for (var i2 = 0; i2 < lst2.length; i2++) {
        lst1.options[i2] = new Option(lst2.options[i2].text, lst2.options[i2].value);
    }
    for (var i2 = 0; i2 < lst2.length; i2++) {
        //clear lst2
        lst2.options[0] = null;
    }
    //set lst1 selidx to lst2 selidx
    lst1.selectedIndex = lst2idx;
    //copy tmp into lst2
    for (var i3 = 0; i3 < lst1len; i3++) {
        lst2.options[i3] = new Option(tmparrt[i3], tmparrv[i3]);
        //clear lst2
    }
    //set lst2 selidx to lst1 selidx
    lst2.selectedIndex = lst1idx;
    //clear arrays
    tmparrv = null;
    tmparrt = null;    
}
function XmlRow (fiIdx, fsXMLNm,fsXMLID) {

    this.fidx = fiIdx
    this.XMLNm = fsXMLNm
    this.XMLID = fsXMLID
    
    //XML Table Row Globals
    this.sTbl = '';
    this.sTbG = '';
    this.b1Rw = false;
    this.b2Rw = false;
    this.b3Rw = false;
    this.iMRw = 0;
    this.iNRw = 0;
    this.iRwV = 0;
    this.iRwP = 0;
    this.iFCn = 0;
    this.gsRw = 0;

    this.vTmp = ""
    //alert("xmlrow:" + fiIdx);
    
    //Row information structures
    this.RwV = new Array()
    for (a5 = 1; a5 < 51; a5++) this.RwV[a5] = new Array()


    //XMLField Table Row Manipulations
    this.xcUp = function(fiRw) {
        if (fiRw == null) fiRw = this.gsRw;
        //alert('move up\njust getting around to this - gw :)');
        if (fiRw == 1) return;
        for (a4 = 1; a4 <= this.iFCn; a4++) {
            //alert(gEl(this.RwV[fiRw][a]).tagName);
            if (gEl(this.RwV[fiRw][a4] + '_checkboxes')) {
                //alert(this.RwV[fiRw][a] + ' == ' + gEl(this.RwV[fiRw][a] + '_displaybox').onchange);
                xcDDCLSw(this.RwV[fiRw][a4], this.RwV[fiRw - 1][a4]);
            } else if (gEl(this.RwV[fiRw][a4]).tagName.toLowerCase() == 'select') {
                selSwp(gEl(this.RwV[fiRw][a4]), gEl(this.RwV[fiRw - 1][a4]));
                //this.vTmp = (0 + gEl(this.RwV[fiRw - 1][a4]).selectedIndex);
                //gEl(this.RwV[fiRw - 1][a4]).options[gEl(this.RwV[fiRw][a4]).selectedIndex].selected = true;
                //gEl(this.RwV[fiRw][a4]).options[this.vTmp].selected = true;

            } else if (gEl(this.RwV[fiRw][a4]).tagName.toLowerCase() == 'textarea' || gEl(this.RwV[fiRw][a4]).type.toLowerCase() == 'text') {
                this.vTmp = gEl(this.RwV[fiRw - 1][a4]).value;
                gEl(this.RwV[fiRw - 1][a4]).value = gEl(this.RwV[fiRw][a4]).value;
                gEl(this.RwV[fiRw][a4]).value = this.vTmp;

            } else if (gEl(this.RwV[fiRw][a4]).type.toLowerCase() == 'checkbox') {
                this.vTmp = gEl(this.RwV[fiRw - 1][a4]).checked;
                gEl(this.RwV[fiRw - 1][a4]).checked = gEl(this.RwV[fiRw][a4]).checked;
                gEl(this.RwV[fiRw][a4]).checked = this.vTmp;
            }
        }
        this.xcWmR(true)
        fXRs('xmlRs[' + this.fidx + '].xcWmR()', 20);
        //setTimeout('xcWmR()', 20);

    }

    this.xcDn = function(fiRw) {
        if (fiRw == null) fiRw = this.gsRw;
        //alert('move down\njust getting around to this - gw :)');
        if (fiRw >= this.iMRw) return;
        if (fiRw == this.iRwV) this.xcAd();
        for (a3 = 1; a3 <= this.iFCn; a3++) {
            //alert(gEl(this.RwV[fiRw][a]).tagName);
            if (gEl(this.RwV[fiRw][a3] + '_checkboxes')) {
                //alert(this.RwV[fiRw][a] + ' == ' + gEl(this.RwV[fiRw][a] + '_displaybox').onchange);
                xcDDCLSw(this.RwV[fiRw][a3], this.RwV[fiRw + 1][a3]);
            } else if (gEl(this.RwV[fiRw][a3]).tagName.toLowerCase() == 'select') {
            
                selSwp(gEl(this.RwV[fiRw][a3]),gEl(this.RwV[fiRw + 1][a3]));

            } else if (gEl(this.RwV[fiRw][a3]).tagName.toLowerCase() == 'textarea' || gEl(this.RwV[fiRw][a3]).type.toLowerCase() == 'text') {
                this.vTmp = gEl(this.RwV[fiRw + 1][a3]).value;
                gEl(this.RwV[fiRw + 1][a3]).value = gEl(this.RwV[fiRw][a3]).value;
                gEl(this.RwV[fiRw][a3]).value = this.vTmp;

            } else if (gEl(this.RwV[fiRw][a3]).type.toLowerCase() == 'checkbox') {
                this.vTmp = gEl(this.RwV[fiRw + 1][a3]).checked;
                gEl(this.RwV[fiRw + 1][a3]).checked = gEl(this.RwV[fiRw][a3]).checked;
                gEl(this.RwV[fiRw][a3]).checked = this.vTmp;
            }
        }


        this.xcWmR(true)
        fXRs('xmlRs[' + this.fidx + '].xcWmR()', 20);
        //setTimeout('xcWmR()', 20);

    }

    this.xcRm = function(fiRw) {
        if (fiRw == null) fiRw = this.gsRw;
        if (fiRw > this.iMRw || fiRw < 1) return;
        var sTmpVl = '';
        if (confirm('Remove the Row?\nClick OK if you are sure.\nAny rows below will move up.')) {
            //debugger;
            for (rr = fiRw; rr <= this.iMRw; rr++) {
                for (aa = 1; aa <= this.iFCn; aa++) {
                    if (gEl(this.RwV[fiRw][aa])) {
                        if (gEl(this.RwV[fiRw][aa] + '_checkboxes')) {
                            //alert(this.RwV[fiRw][a] + ' == ' + gEl(this.RwV[fiRw][a] + '_displaybox').onchange);
                            if (rr == this.iMRw || (fiRw == 1 && this.iRwV == 1)) {
                                if (gEl('v_' + this.RwV[rr][aa]).value != '-1' || gEl('v_' + this.RwV[rr][aa]).value != '') {
                                    try {
                                        xcDDCLr(this.RwV[rr][aa], true, "-1");
                                    } catch (ex) {
                                        alert('3:' + ex);
                                    }
                                }
                            } else {
                                xcDDCLSw(this.RwV[rr + 1][aa], this.RwV[rr][aa])
                                //sTmpVl = gEl('v_' + this.RwV[r + 1][a]).value;
                                //gEl('v_' + this.RwV[r][a]).value = sTmpVl
                                //xcDDCLr(this.RwV[r][a], true, sTmpVl);
                                //alert(sTmpVl)
                                //xcDDCLr(this.RwV[r + 1][a]);
                            }

                        } else if (gEl(this.RwV[fiRw][aa]).tagName.toLowerCase() == 'select') {
                            
                            if (rr == this.iRwV) {
                                gEl(this.RwV[rr][aa]).options[0].selected = true;
                            } else {
                                selSwp(gEl(this.RwV[fiRw][aa]), gEl(this.RwV[fiRw + 1][aa]));
//                                try {
//                                    gEl(this.RwV[rr][aa]).options[gEl(this.RwV[rr + 1][aa]).selectedIndex].selected = true;
//                                } catch (ex) {
//                                    //must be a checklist
//                                    //alert('umm ' + this.RwV[rr][aa]);
//                                    if(gEl('v_' + this.RwV[rr][aa]))gEl('v_' + this.RwV[rr][aa]).value = '-1';
                            //                                }


                            }
                        } else if (gEl(this.RwV[rr][aa]).tagName.toLowerCase() == 'textarea' || gEl(this.RwV[rr][aa]).type.toLowerCase() == 'text') {
                            if (rr >= this.iRwV) {
                                gEl(this.RwV[rr][aa]).value = '';
                            } else if (gEl(this.RwV[rr + 1][aa])) {
                                gEl(this.RwV[rr][aa]).value = gEl(this.RwV[rr + 1][aa]).value;
                            } else {
                                gEl(this.RwV[rr][aa]).value = '';
                            }
                        } else if (gEl(this.RwV[rr][aa]).type.toLowerCase() == 'checkbox') {
                            if (rr >= this.iRwV) {
                                gEl(this.RwV[rr][aa]).checked = false;
                            } else if (gEl(this.RwV[rr + 1][aa])) {
                                gEl(this.RwV[rr][aa]).checked = gEl(this.RwV[rr + 1][aa]).checked;
                            } else {
                                gEl(this.RwV[rr][aa]).checked = false;
                            }
                        }
                    } else {
                        break;
                    }
                }
            }
            if (this.iRwV > this.iNRw) {
                this.xcHdRow(this.iRwV);
                this.iRwV--;
            }
            this.xcWmR(true)
            fXRs('xmlRs[' + this.fidx + '].xcWmR()', 20);
            //setTimeout('this.xcWmR()', 20);

            if (this.iRwV < this.iMRw) {
                gEl('pAp_' + this.sTbG).style.display = 'none';
                gEl('pAb_' + this.sTbG).style.display = 'block';
            }
        } else {
            if (gsPRGGuid != '') prgN(gsPRGGuid);
        }
    }
    this.xcAd = function() {
    //alert('Add New Item\njust getting around to this - gw :)');
        //alert(this.iRwV);
        if (this.iRwV < this.iMRw) {
            this.iRwV++;
            
            this.xcShRow(this.iRwV);
        }
    }
    this.xcCt = function() {
        alert('Continue ...\njust getting around to this - gw :)');
    }
    this.xcShRow = function(fiRw) {
        gEl(this.sTbl + '_' + fiRw).style.display = 'block';
        if (gsPRGGuid != '') prgN(gsPRGGuid);
        if (fiRw == this.iMRw) {
            gEl('pAp_' + this.sTbG).style.display = 'block';
            gEl('pAb_' + this.sTbG).style.display = 'none';
        }
        this.xcWmR(true)
        fXRs('xmlRs[' + this.fidx + '].xcWmR()', 20);
    }
    this.xcHdRow = function(fiRw) {
        gEl(this.sTbl + '_' + fiRw).style.display = 'none';
        if (gsPRGGuid != '') prgN(gsPRGGuid);
        if (fiRw < this.iMRw) {
            gEl('pAp_' + this.sTbG).style.display = 'none';
            gEl('pAb_' + this.sTbG).style.display = 'block';
        }
        this.xcWmR(true)
        fXRs('xmlRs[' + this.fidx + '].xcWmR()', 20);
    }
    this.xcWmR = function(forcehide) {
        //reset watermarks
        var bHV = false;
        for (r1 = 1; r1 <= this.iMRw; r1++) {
            for (a1 = 1; a1 <= this.iFCn; a1++) {
                bHV = false
                if (gEl(this.RwV[r1][a1] + '_checkboxes')) {
                    if (gEl('v_' + this.RwV[r1][a1]).value != '-1' && gEl('v_' + this.RwV[r1][a1]).value != '') bHV = true;
                    //alert(gEl('v_' + this.RwV[r][a]).value + "\n" + bHV);
                } else if (gEl(this.RwV[r1][a1]).tagName.toLowerCase() == 'select') {
                    if (gEl(this.RwV[r1][a1]).selectedIndex > 0) bHV = true;
                } else if (gEl(this.RwV[r1][a1]).tagName.toLowerCase() == 'textarea' || gEl(this.RwV[r1][a1]).type.toLowerCase() == 'text') {
                    if (gEl(this.RwV[r1][a1]).value != '') bHV = true;
                }
                if (!gEl(this.RwV[r1][a1] + '_checkboxes') && gEl(this.RwV[r1][a1]).type.toLowerCase() == 'checkbox') {
                } else {
                    try {
                        if (bHV || forcehide == true) {
                            //gEl("wm_" + this.RwV[r][a]).style.display = "inline-block";
                            //gEl("wm_" + this.RwV[r][a]).style.position = "relative";
                            gEl("wm_" + this.RwV[r1][a1]).style.display = "none";
                        } else {
                            gEl("wm_" + this.RwV[r1][a1]).style.display = "block";
                            //gEl("wm_" + this.RwV[r][a]).style.position = "absolute;";
                        }
                        //if (isIE && forcehide == true) {
                        //    gEl("wm_" + this.RwV[r][a]).style.position = "relative";
                        //} else if(isIE) {
                        //    gEl("wm_" + this.RwV[r][a]).style.position = "absolute;";
                        //}
                    } catch (ex) {
                        alert("wm_" + this.RwV[r1][a1]+"\n"+ex);
                    }
                }
            }
        }
        if (gsPRGGuid != '') prgN(gsPRGGuid);
    }

    this.xcSv = function() {
        //save

        //fill a hidden field with the control names of all fields in rows.

        var sNm = '';
        var r2 = 0;
        var a2 = 0;
        for (r2 = 1; r2 <= this.iRwV; r2++) {
            if (r2 > 1) sNm += '|'; //row separator on 2nd and subsequent
            for (a2 = 1; a2 <= this.iFCn; a2++) {
                if (a2 > 1) sNm += ','; //field separator on 2nd and subsequent
                sNm += this.RwV[r2][a2];
            }
        }
        //alert(sNm); //debug only
        gEl('xc_' + this.fidx + '_fc').value = sNm;
        
        gEl('xc_' + this.fidx + '_ac').value = "sv";
        gEl('xc_' + this.fidx + '_cx').value = this.fidx;

        //*** HELP how does processor know which XML Field ID to process?
        //gEl('xc_cx').value = this.fidx;

        //button triggers postback implicitly
        return true;
    }

}
this.xcEdt = function(fidx) {
    gEl('xc_' + fidx + '_ac').value = "ev";
    gEl('xc_' + fidx + '_cx').value = fidx;
    return true;
}


function xcDDCLSw(fromobjid, toobjid) {
    //alert("swap from DDCL named, " + fromobjid + '\nto DDCL named, ' + toobjid);
    try {
        xcDDCLr(fromobjid, false, null);
    } catch (ex) {
    alert('4:' + ex);
    }        
    try {
        xcDDCLr(toobjid, false, null);
    } catch (ex) {
    alert('5:' + ex);
    }
    //swap v_ fields
    //alert('before: ' + gEl('v_' + fromobjid).value);
    var sFromValues = gEl('v_' + fromobjid).value
    var sToValues = gEl('v_' + toobjid).value
    gEl('v_' + fromobjid).value = gEl('v_' + toobjid).value
    gEl('v_' + toobjid).value = sFromValues
    //alert('after: ' + gEl('v_' + fromobjid).value);
    
    var fromobjname = fromobjid.replace(/_/g, '$');
    var toobjname = toobjid.replace(/_/g, '$');
    //alert('before: ' + gEl(fromobjid + '_checkboxes').innerHTML);
    //swap contents of _checkboxes divs (attempt to only do this if it is a dependent child control)
    sTmp = (gEl(fromobjid + '_checkboxes').innerHTML).replaceAll(fromobjid, toobjid).replaceAll(fromobjname, toobjname);
    gEl(fromobjid + '_checkboxes').innerHTML = (gEl(toobjid + '_checkboxes').innerHTML).replaceAll(toobjid, fromobjid).replaceAll(toobjname, fromobjname); 
    gEl(toobjid + '_checkboxes').innerHTML = sTmp;
    //alert('after: ' + gEl(fromobjid + '_checkboxes').innerHTML);
    //alert('tmp: ' + sTmp);
    try {
        xcDDCLr(fromobjid, true, sToValues);
    } catch (ex) {
    alert('6:' + ex);
    }        
    try {
    xcDDCLr(toobjid, true, sFromValues);
    } catch (ex) {
    alert('7:' + ex);
    }        

}
var xcDDCLrOh = '';
function xcDDCLr(objid, rewire, ensurechecks) {
    //resets a drop down checklist
    //alert("reset DDCL named, " + objid);
    if (objid == xcDDCLrOh) return;
    var i = 0;
    var ecs = ',' + ensurechecks + ','
    //alert(ecs);
    var obj = DDCL_GetObject(objid)
    if (obj != null) {
        if (rewire) {
            var e = obj.divCheckboxes.getElementsByTagName("input");
            for (i = 0; i < e.length; i++) {
                if (e[i]) {
                    if (e[i].type == "checkbox") {
                        e[i].onclick = DDCL_HandleCheckboxClick;
                        if (ensurechecks == '-1' || ensurechecks == '') {
                            e[i].checked = (i == 0);
                        } else {
                            if (ecs.indexOf(',' + e[i].value + ',') == -1) {
                                e[i].checked = false;
                            } else {
                                e[i].checked = true;
                            }
                        }
                        //alert(ecs + '\n' + e[i].value + '\n' + ecs.indexOf(',' + e[i].value + ','));
                    }
                } else {
                    break;
                }
            }
            //alert(this.id + ' = ' + i);
        }
        obj.DisplayCheckedItems();
        xcDDCLrOh = objid;
    }
}


//ajax check username
var goUObj = null;
var goUGuid = null;
var goUTheme = null;
var goUTmr = null;
var gbUXAJ = false;
function chkUN(obj, guid, theme) {
    if (goUTmr) clearTimeout(goUTmr);
    goUObj = obj;
    goUGuid = guid;
    goUTheme = theme;
    if ((obj.value).length < 4) {
        //alert((obj.value).length);
        setTimeout('chkHD()',50);
        return;
    }
    if (gbXCAJ) { alert('Please wait for the current request to complete,\nor hit reload/refresh on your browser to reset the form.'); return false; }
    gEl("av_" + guid).innerHTML = '<img src=\"/images/buttons/progress10.gif\" width=\"10\" height=\"10\" border=\"0\" align=\"absmiddle\" />&nbsp;Checking...';
    gEl("av_" + guid).style.color = 'blue';
    gEl("av_" + guid).style.display = 'block';
    //timer
    //alert("about to ajax:\n" + gbXCAJ + '\n FF:' + gsFF + '\n CG:' + gsCG + '\n CCC:' + gsCCCID);
    //alert("timer");
    goUTmr = setTimeout('chkUNp()', 500);
}
function chkHD() {
    gbXCAJ = false;
    //alert(goUObj.id);
    gEl("av_" + goUGuid).style.display = 'none';
    tWM(goUObj, goUObj.id);
    //if (goUTmr) clearTimeout(goUTmr);
}
function chkUNp() {
    gbUXAJ = true;
    AjaxPost('/_tools/ajaxcheckname.aspx', 'nm=' + goUObj.value + '&t=' + goUTheme, 'chkUNc');
}
function chkUNc(xml) {
    if (!gbUXAJ) {
        //gEl("av_" + goUGuid).style.display = 'none';
        return;
    }
    if (xml == 'True') {
        gEl("av_" + goUGuid).innerHTML = 'Available :)';
        gEl("av_" + goUGuid).style.color = 'darkgreen';
        gEl("av_" + goUGuid).style.display = 'block';
    } else {
        gEl("av_" + goUGuid).innerHTML = 'Not Available :(';
        gEl("av_" + goUGuid).style.color = 'red';
        gEl("av_" + goUGuid).style.display = 'block';    
    }
}

var gbXCAJ = false; //isProcessing (so only 1 ajax operation at a time)
var gsFF = ""; // Filter Field
var gsCG = ""; // CtrlGUID
var gsCCCID = ""; // ChildControlClientID
var gsCCCTBL = ""; //ChildControlLookupTable
var gsPCCID = ""; // ParentControlClientID - DropDownCheckList only
var gsWMC = ""; // Watermark Cache
var gsPVL = ""; // Current Parent Value- DropDownCheckList only
var gsPVLC = ""; // Current Parent Value Cache- DropDownCheckList only
var gsVL = ""; // Current Value
var gsVLC = ""; // Value Cache
var goObj = null;
//fsFilterField, fsCtrlGuid, fsChildControlClientID
function xcAj(obj, fsFF, fsCG, fsCCID, fsCCTBL, fsPCID) {
//alert("ff_" + fsCCID + "\nctl00_content_locStateDropDown_lywDDLDropDownList");
    if (gbXCAJ) { alert('Please wait for the current request to complete,\nor hit reload/refresh on your browser to reset the form.'); return false; }
    //if (fsCCID != fsCCID) return;
    gbXCAJ = false;
    goObj = obj;
    
    gsFF = gEl("ff_" + fsCCID).value;
    gsCG = fsCG;
    gsCCCID = fsCCID;
    gsCCCTBL = fsCCTBL;
    if (fsPCID) {
        gsPCCID = fsPCID;
    } else {
        gsPCCID = "";
    }
    if (gsPCCID.indexOf("lywDDLCheckList") >= 0) {
        gsPVL = gEl("v_" + gsPCCID).value;
        gsPVLC = gEl("vc_" + gsPCCID).value;
        gsVL = gEl("v_" + gsCCCID).value;
        gsVLC = gEl("vc_" + gsCCCID).value;
        
        //gsVLC = gEl(fsCCID).value;
    } else {
        gsPVL = "";
        gsPVLC = "";
        gsVL = obj.value;
        //gsVLC = gEl("vc_" + fsCCID).value;
        gsVLC = gEl(fsCCID).value;
    }
    //alert(gsFF + ' -a- ' + gsCG + ' -b- ' + gsCCCID + '-c-' + gsCCCTBL + ' -d- ' + gsVL + ' -e- ' + gsVLC + ' -f- ' + gsPVL + ' -g- ' + gsPVLC);

    if (gsFF != '' && gsCG != '' && gsCCCID != '' && (gsVL != gsVLC || gsPVL != gsPVLC)) {
        //alert(gsVL + ' -- ' + gsVLC);
        //say "Please wait" processing on control
        //alert("wm_" + fsCCID);
        if (gEl("wm_" + fsCCID)) {
            gsWMC = gEl("wm_" + fsCCID).innerHTML
            gEl("wm_" + fsCCID).innerHTML = 'List Refreshing :) One Moment...';
            gEl("wm_" + fsCCID).style.display = 'block';
        }
        //timer
        //alert("about to ajax:\n" + gbXCAJ + '\n FF:' + gsFF + '\n CG:' + gsCG + '\n CCC:' + gsCCCID);
        //alert("timer");
        setTimeout('xcAjP()', 250);
    }
    return true;
}




var mcOTimer = null;
var mcTObj = null;
var mcOObj = null;
var mcOClas = '';
var mcLObj = null;
var mcLChkID = null;
var mcLClas = null;
function mcOva(obj, chkid, clas) {
    //if (obj == mTObj) {
    if (mcOTimer != null) clearTimeout(mcOTimer);
    if (obj != mcTObj) {
        if (mcLObj) {
            if (gEl(mcLChkID).checked) {
                mcLObj.className = mcLClas + "_S";
            } else {
                mcLObj.className = mcLClas;
            }
        }
        mcLObj = obj;
        mcLChkID = chkid;
        mcLClas = clas;
    }
    mcTObj = obj;
    obj.className = clas + "_H";
}
function mcHide() {
    mcOObj.className = mcOClas;
    mcOObj = null;
    mcOClas = '';
}
function mcOut(obj, chkid, clas) {
    if (obj != mcLObj) {
        clearTimeout(mcOTimer);
        return
    }
    mcOObj = obj;
    if (gEl(chkid)) if (gEl(chkid).checked) {
        mcOClas = clas + "_S";  
    } else {
        mcOClas = clas;
     }

    mcOTimer = setTimeout('mcHide()', 125);
}

var jaDivId = '';
var jaClas = '';

function jjaClk(bDiv, cbID, divID, jaGUID, fsT, fsR, sClas) {
    //1,'" + ((CheckBox)BasicJobAdView.FindControl("BasicJobAdCheckBox")).ClientID + "','BasicJobAdDiv','" + JobAdGuid + "')
    //fsT=t=jad|jss|jsk|es -fsR=rating 1-10
    var bChk = (gEl(cbID).checked)
    if (("" + bDiv) == "0" || ("" + bDiv) == "1") {
        bChk = !bChk;
    }
    gEl(cbID).checked = bChk;
    if (("" + bDiv) == "1" || ("" + bDiv) == "2") {
        jaDivId = divID;
        if(bChk){
            jaClas = sClas + "_S";
        } else {
            jaClas = sClas;
        }
    }
    xcAjT(fsT, (bChk ? "a" : "x"), jaGUID, fsR, '');
}

function jjbClk(bDiv, cbID, divID, jaGUID, fsT, fsR, fsD) {
    //jjbClk('1',this.id,'c_'+this.id,'272f6f1a-30f5-4c5d-b86f-0ce6a2a21306','jad', 0, '2010-5-18');
    //fsT=t=jad|jss|jsk|es -fsR=rating 1-10|d=
    var bChk = (gEl(cbID).checked)
    //gEl(cbID).checked = bChk;
    if (""+bDiv == "1") {
        jaDivId = divID;
        if (bChk) {
            jaClas = 'bodyRow';
        } else {
            jaClas = 'removedRow';
        }
        xcAjT(fsT, (bChk ? "a" : "x"), jaGUID, fsR, fsD);
    }
}
function xcAjT(fsT,fsA,fsID,fsR,fsD) {
    //do ajax to set a saved item or delete it
    //t=jad|jss|jsk|ess &a=a|x &id=guid-0000 &r=rating
    AjaxPost('/_tools/ajaxsave.aspx', 't=' + fsT + '&a=' + fsA + '&id=' + fsID + '&r=' + fsR + '&d=' + fsD, 'xcAjTC');
}
function xcAjTC(xmlresponse) {
    if (xmlresponse != "OK" && xmlresponse != "") {
        alert(xmlresponse);
    }
    //alert(jaDivId + ' == ' + jaClas);
    if (gEl(jaDivId)) gEl(jaDivId).className = jaClas;
}

// SvScAc(this, 'c', '" + sTkID + "', '" + Server.UrlEncode(sLabel) + "');
var SvSFsW = false;
var SvSFsT = '';
var SvSCbObj = null;
var SvSAhObj = null;
var SvSDvObj = null;
function SvScAc(obj, fsA, fsT, fsK, fsL) {
    if (SvSFsW) return;
    SvSFsW = true;
    id = obj.id
    if( fsA=="j"){
        SvSFsT = "";
    } else if (fsA == "r") { 
        //store based on hyperlink id - ar_" + sTkID +
        SvSFsT = "r";
        SvSAhObj = obj;
        SvSCbObj = gEl((obj.id+'').substring(1))
        SvSDvObj = gEl('c_' + obj.id)
    }
    //***
    SvScAj(fsT, fsA, fsK, fsL);        
}
function SvScAj(fsT, fsA, fsK, fsL) {
    //do ajax to set a saved item or delete it
    //t=jad|jss|jsk|ess &a=a|x &id=guid-0000 &r=rating
    //alert('t=' + fsT + '&a=' + fsA + '&k=' + fsK + '&l=' + escape(fsL));
    AjaxPost('/_tools/ajaxsave.aspx', 't=' + fsT + '&a=' + fsA + '&k=' + fsK + '&l=' + escape(fsL), 'SvScAjR');
}
function SvScAjR(xmlresponse) {
    SvSFsW = false;
    if (xmlresponse != "OK" && xmlresponse != "") {
        alert(xmlresponse);
    } else {
        var clas = '';
        //update the look of the row
        if(SvSFsT=='r') {
            if(SvSDvObj)clas=SvSDvObj.className;
            if(clas=="removedRow") {
                if (SvSDvObj) SvSDvObj.className = "bodyRow";
                if (SvSAhObj) SvSAhObj.innerHTML = "Remove &raquo;";
                if (SvSCbObj) SvSCbObj.disabled = false;
            } else {
                if (SvSDvObj) SvSDvObj.className = "removedRow";
                if (SvSAhObj) SvSAhObj.innerHTML = "Restore &raquo;";
                if (SvSCbObj) SvSCbObj.disabled = true;
            }
        } else if(SvSFsT=='r') {
        }

    }
    SvSFsT = '';
}




function xcAjP() {
    //do ajax to get a list
    gbXCAJ = true;
    if (gsPCCID.indexOf("lywDDLCheckList") >= 0 && gsPVL != '') {
        AjaxPost('/_tools/ajaxlist.aspx', 'tb=' + gsCCCTBL + '&ff=' + gsFF + '&ccc=' + gsPVL, 'xcAjC');
    } else {
        AjaxPost('/_tools/ajaxlist.aspx', 'tb=' + gsCCCTBL + '&ff=' + gsFF + '&ccc=' + gsVL, 'xcAjC');
    }
}
function xcAjC(xmlresponse) {
    //process ajax into the control, keep values that are already set (unless group changes away, then discard).
    //alert(xmlresponse);

    //try {
        var valueArr = eval(xmlresponse);
        var a = 0;
        var b = 0;
        var i = 0;
        if (gsPCCID.indexOf("lywDDLCheckList") >= 0 && gsPVL != '') {
            var sOpts = "";
            var sVals = "";            
            //alert("Update Child Checklist Values to: " + xmlresponse);
            //<div class="i"><input id="ctl00_content_WorkLicencesXMLField_ctl06_lywDDLCheckList_0" type="checkbox"  value="-1" name="ctl00$content$WorkLicencesXMLField$ctl06$lywDDLCheckList$0" /><label for="ctl00_content_WorkLicencesXMLField_ctl06_lywDDLCheckList_0">none</label></div>
            for (a = 2; a < valueArr.length - 1; a += 2) {
                if (valueArr[a] != '') {
                    //var opt = new Option(valueArr[a + 1], valueArr[a], null, ('' + valueArr[a] == '' + gsVL));
                    //gEl(gsCCCID).options.add(opt, gEl(gsCCCID).options.length);
                    sOpts += '<div class="i"><input id="' + gsCCCID + '_' + i + '" type="checkbox" value="' + valueArr[a] + '" name="' + gsCCCID.replaceAll('_','$') + '$' + i + '" /><label for="' + gsCCCID + '_' + i + '">' + valueArr[a + 1] + '</label></div>\n';
                    if (gsVL.indexOf(valueArr[a])>=0) sVals += (sVals != '' ? ',' : '') + valueArr[a];
                    i++;
                    // alert(valueArr[a] + ' = ' + valueArr[a + 1]);
                }
            }
            //alert(sVals);
            gEl(gsCCCID).innerHTML = sOpts;
            try {
                //alert('byajax');
                xcDDCLr(gsCCCID, true, sVals);
            } catch (ex) {
                alert('1:'+ ex);
            }
            gEl(gsCCCID).scrollTop = 0;
            
        } else {
            while (gEl(gsCCCID).options.length >= 1) { gEl(gsCCCID).remove(0); }
            //destroy current list items
            for (a = 2; a < valueArr.length - 1; a += 2) {
                if (valueArr[a] != '') {
                    var opt = new Option(valueArr[a + 1], valueArr[a], null, ('' + valueArr[a] == '' + gsVL));
                    gEl(gsCCCID).options.add(opt, gEl(gsCCCID).options.length);
                    i++;
                    // alert(valueArr[a] + ' = ' + valueArr[a + 1]);
                }
            }
        }
    //} catch (ex) {
    //    alert('We\'re Sorry... there was a problem updating the dependent list.\nRefresh/Reload the page and try again.\n' + xmlresponse);
    //}

    //for (b = i; b < gEl(gsCCCID).options.length; b++) {

    //    gEl(gsCCCID).options[b] = null;
    //}
    //alert(valueArray[5] + "," + valueArray[6]);

    //alert("ajax, happens!\npVAL:" + gsVL + '\n FF:' + gsFF + '\n CG:' + gsCG + '\n CCC:' + gsCCCID);

    gbXCAJ = false;
    if(gsPCCID && gsPCCID!="")gEl("vc_" + gsPCCID).value = gsPVLC;
    gEl("vc_" + gsCCCID).value = gsVLC;
    if (gEl("wm_" + gsCCCID)) {
        gEl("wm_" + gsCCCID).innerHTML = gsWMC
    }
    //if (gEl("v_" + fsCCID).value == '-1') {
    //} else {
    //    gEl("wm_" + gsCCCID).style.display = 'none';
    //}

}



/*
"  var this.sTbl = '" + sTableId + "'\n"+
"  var this.b1Rw = " + ((sPrimaryRow != "") ? "true" : "false")+"\n"+
"  var this.b2Rw = " + ((sSecondaryRow != "") ? "true" : "false")+"\n"+
"  var this.b3Rw = " + ((sTertiaryRow != "") ? "true" : "false")+"\n"+
"  var this.iMRw = " + maxRowCount + "\n"+
"  var iNRw = " + maxRowCount + "\n"+
"  var this.iRwP = " + howManyRowsPopulated + "\n"+
"  var this.iRwV = " + howManyRowsVisible + "\n"+
"  var this.iFCn = " + fieldCount + "\n"+
*/


function AjaxPost(strURL, strSubmit, strResultFunc) {

    var xmlHttpReq = false;
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert('Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.');
    }

    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            eval(strResultFunc + '(xmlHttpReq.responseText)');
        }
    }
    xmlHttpReq.send(strSubmit);
}

//progress indicator show/hides
function prgY(guid) {
    gsPRGGuid = guid;
    //alert(gsPRGGuid);
    gEl('pb_' + guid).style.display = "block";
    if (!isIE) {
        gEl('py_' + guid).style.display = "inline";
        gEl('pn_' + guid).style.display = "none";
    }
}
function prgY2() {
    //alert('y2|'+gsPRGGuid);
    try {
        gEl('pb_' + gsPRGGuid).style.display = "block";
        gEl('py_' + gsPRGGuid).style.display = "inline";
        gEl('pn_' + gsPRGGuid).style.display = "none";
    } catch (ex) {
    }
}
function prgN(guid) {
    gsPRGGuid = '';
    if(!gEl('pb_' + guid))return;
    gEl('pb_' + guid).style.display = "none";
    gEl('py_' + guid).style.display = "none";
    gEl('pn_' + guid).style.display = "inline";
}

/************************************************************************
* DropDownCheckList.js
* 
*  Client-side javascript to support the ASP.NET DropDownCheckList 
*  server control.
*
*  written by Mike Ellison, 20-September-2005
*
************************************************************************
*  Copyright (c) 2005 Mike Ellison.  All rights reserved.
*  
*  Redistribution and use in source and binary forms, with or without 
*  modification, are permitted provided that the following conditions are met:
*  
*    * Redistributions of source code must retain the above copyright notice, 
*      this list of conditions, the following disclaimer, and the following
*      acknowledgements. 
*  	
*    * Redistributions in binary form must reproduce the above copyright notice, 
*      this list of conditions and the following disclaimer in the documentation 
*  	and/or other materials provided with the distribution.
*  	
*    * The name of the author may not be used to endorse or promote products 
*      derived from this software without specific prior written permission. 
*  
*  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 
*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
*  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
*  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
*  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
*  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*  Acknowledgements:
*      - The "shim" technique used to support Internet Explorer 6.x
*        is courtesy Joe King of Coalesys, Inc., 
*        http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
*
*      - Javascript functions findPosX and findPosY for locating objects absolutely
*        are courtesy Peter-Paul Koch, http://www.quirksmode.org
*  
************************************************************************/

/************************************************************************
* Utility Functions (global to the page)
************************************************************************/
var DDCL_DROPDOWNMODE_INLINE = 0;
var DDCL_DROPDOWNMODE_ONTOP = 1;
var DDCL_DROPDOWNMODE_ONTOPWITHSHIM = 2;
var DDCL_DISPLAYTEXTLIST_LABELS = 0;
var DDCL_DISPLAYTEXTLIST_VALUES = 1;

ddcl_Objects = new Array();
function DDCL_GetObject(id) {
    for (var i = 0; i < ddcl_Objects.length; i++) {
        // alert(id.substring(ddcl_Objects[i].length) + ", " + ddcl_Objects[i].id);
        if (id.substring(0, ddcl_Objects[i].id.length) == ddcl_Objects[i].id) {
            // alert('gotit');
            return ddcl_Objects[i];
        }
    }
    return null;
}

// -----------------------------------------------------
function DDCL_findPosX(obj) {
    /***
    Original script by Peter-Paul Koch, http://www.quirksmode.org
    ***/
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function DDCL_findPosY(obj) {
    /***
    Original script by Peter-Paul Koch, http://www.quirksmode.org
    ***/
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
// -----------------------------------------------------


function DDCL_HandleCheckboxClickById(id) {
    var obj = DDCL_GetObject(id);
    obj.HandleCheckboxClick();
}

// called as the onclick event handler for a check box
function DDCL_HandleCheckboxClick(e) {
    if (!e) var e = window.event;
    if (e) {
        var elem = this;
        //alert(elem.id);
        if (elem) {
            //alert(elem.id + ' = ' + elem.value);
            if (elem.value != "-1") {
                var sElm = elem.id;
                sElm = sElm.substring(0, sElm.lastIndexOf('_')) + '_checkboxes';
                //alert(sElm);
                //gEl((elem.id).replace'ctl00_content_WorkLicencesXMLField_ctl06_lywDDLCheckList_0').checked = false;
                if (gEl(sElm)) {
                    var el = gEl(sElm).getElementsByTagName("input");
                    //alert('hmmm' + el.length);
                    for (var i = 0; i < el.length; i++) {
                        if (el[i].type == "checkbox" && (el[i].value == "-1" || el[i].value == "") ) {
                            el[i].checked = false;
                            //alert('there');
                            break;
                        }
                    }
                }
            } else {
                var sElm = elem.id;
                sElm = 'v_' + sElm.substring(0, sElm.lastIndexOf('_'));
                try {
                   xcDDCLr(sElm, true, '-1');
                } catch (ex) {
                    alert('2:' + ex);
                }
                //gEl(sElm).value = '-1';
                //alert(sElm);
                //xcWmR();
            }
            var obj = DDCL_GetObject(elem.id);
            if (obj) {
                obj.HandleCheckboxClick();
                obj.inCheckboxDiv = true;
            }
        }
    }
}


// called as the onclick event handler for a display box
function DDCL_HandleDisplayBoxClick(e) {
    if (!e) var e = window.event;
    if (e) {
        var elem = this;
        if (elem) {
            var obj = DDCL_GetObject(elem.id);
            if (obj) {
                obj.HandleDisplayBoxClick();
                obj.inCheckboxDiv = true;
            }
        }
    }
}

// called as the onclick event handler for a checkbox div
function DDCL_HandleCheckboxDivClick(e) {
    if (!e) var e = window.event;
    if (e) {
        var obj = DDCL_GetObject(this.id);
        if (obj)
            obj.inCheckboxDiv = true;
    }
}

function DDCL_HandleDocumentClick(id) {
    var obj = DDCL_GetObject(id);
    if (obj) {
        if (obj.inCheckboxDiv == true)
            obj.inCheckboxDiv = false;
        else
            obj.CloseCheckList();
    }
}


/************************************************************************
* Object definition
************************************************************************/
// constructor; takes a required id as a parameter; this will be the
// same as the ClientID of the ASP.NET control
function DDCL_DropDownCheckList(id, textWhenNone, separator, truncateString, dropDownMode, allowExpand, displayList) {
    // remember the id, displayMode, and text to display when no
    // boxes are checked
    this.id = id;
    //alert('ddl:'+id);
    this.textWhenNone = textWhenNone;
    this.separator = separator;
    this.truncateString = truncateString;
    this.dropDownMode = dropDownMode;
    this.allowExpand = allowExpand;
    this.displayList = displayList;

    // get the elements representing the display box div and
    // checklist div; these will be referenced by object methods
    this.divCheckboxes = document.getElementById(id + "_checkboxes");
    this.divBoundingBox = document.getElementById(id + "_boundingbox");
    this.divText = document.getElementById(id + "_text");
    this.divDisplayBox = document.getElementById(id + "_displaybox");
    this.img = document.getElementById(id + "_img");
    this.shim = document.getElementById(id + "_shim");

    this.boundingBoxWidth = this.divBoundingBox.offsetWidth;

    this.divCheckboxes.style.display = "none";

    // wire click events for the display box div and the checkboxes div
    this.divDisplayBox.onclick = DDCL_HandleDisplayBoxClick;
    this.divCheckboxes.onclick = DDCL_HandleCheckboxDivClick;

    // wire click events for the checkboxes
    var e = this.divCheckboxes.getElementsByTagName("input");
    for (var i = 0; i < e.length; i++) {
        if (e[i].type == "checkbox") {
            e[i].onclick = DDCL_HandleCheckboxClick;
        }
    }

    // if the browser supports bubbling events, install a default click
    // handler for the document too, that will close the checkboxes div
    // if there is a click outside it
    if (document.attachEvent) {
        document.attachEvent('onclick'
                              , function() { eval("DDCL_HandleDocumentClick('" + id + "');") }
                             );
    }
    else if (document.addEventListener) {
        document.addEventListener('click'
                              , function() { eval("DDCL_HandleDocumentClick('" + id + "');") }
                              , false);
    }


    // initial display of checked items, or the textWhenNone string
    this.DisplayCheckedItems();

    // add this object to our reference array on the page so we can get it 
    // back later
    ddcl_Objects.push(this);

}


// get a label given a checkbox element
function DDCL_DropDownCheckList_GetLabelForCheckbox(elem) {
    var e = this.divCheckboxes.getElementsByTagName("label");
    for (var i = 0; i < e.length; i++) {
        if (e[i].htmlFor == elem.id) {
            for (var j = 0; j < e[i].childNodes.length; j++) {
                if (e[i].childNodes[j].nodeType == 3) //text type
                {
                    return e[i].childNodes[j].nodeValue;
                }
            }
        }
    }

    // still here?  no <label> for this checkbox then
    return null;
}


// refresh the checked items listing in the display box
function DDCL_DropDownCheckList_DisplayCheckedItems() {
    var sCheckedValues = "";
    var sLabel = "";
    var sCurrent = "";
    var sFull = "";
    var sBefore = "";
    var sCompText = "";
    var bEllipsisAdded = false;
    var bClear = false;

    // get all checkboxes in the checklist
    var e = this.divCheckboxes.getElementsByTagName("input");
    // clear the display text
    this.divText.innerHTML = "";
    // clear the title (tooltip) attribute
    this.divDisplayBox.title = "";
    //alert(e);
    // loop through all checkboxes in the checklist to see 
    // which ones are checked;
    for (var i = 0; i < e.length; i++) {
        if (e[i]) {
            if (e[i].type == "checkbox" && e[i].checked) {
                if (bClear) {
                    e[i].checked = false;
                } else {

                    // if the checkbox is checked, get its associated label text
                    if (this.displayList == DDCL_DISPLAYTEXTLIST_LABELS)
                    // get the label for the checkbox
                        sLabel = this.GetLabelForCheckbox(e[i]);
                    else
                    // get the value for the checkbox
                        sLabel = e[i].value;

                    if (e[i].value == "-1") {
                        bClear = true;
                        sFull = this.textWhenNone;
                        sCurrent = this.textWhenNone;
                        sCheckedValues = "-1";

                    } else {

                        // add the list separator if necessary
                        if (sCurrent != "") {
                            sCurrent += this.separator;
                            sFull += this.separator;
                        }

                        sFull += sLabel;
                        sCurrent += sLabel;
                        sCheckedValues += e[i].value + ','
                    }

                    if (bEllipsisAdded == false) {
                        // add this one to the text box, then test for the
                        // width against the display box
                        this.divText.innerHTML = "<nobr>" + sCurrent + "</nobr>";
                        if (this.divText.offsetWidth > this.boundingBoxWidth && this.allowExpand == false) {
                            // too big; shrink by what we can and add the ellipsis (or other trunacte string)
                            while (this.divText.offsetWidth > this.boundingBoxWidth && sCurrent.length > 0) {
                                sCurrent = sCurrent.substr(0, sCurrent.length - 1);
                                this.divText.innerHTML = "<nobr>" + sCurrent + this.truncateString + "</nobr>";
                            }

                            // and indicate the ellipsis (or other truncate text) has been added
                            bEllipsisAdded = true;
                        }
                    }
                }
            }
        } else {
            break;
        }
    }

    if (!bClear) {
        for (var i = 0; i < e.length; i++) {
            if (e[i]) {
                if (e[i].type == "checkbox" && e[i].value == "-1") {
                    e[i].checked = false;
                    break;
                }
            } else {
                break;
            }
        }
    }

    // finally, if there are no contents, display the textWhenNone message
    if (this.divText.innerHTML == "") {
        if (this.textWhenNone == "")
            this.divText.innerHTML = "&nbsp;";
        else
            this.divText.innerHTML = this.textWhenNone;
    }

    // if we added the ellipsis, set the title attribute to the full string
    // (which will display as a tooltip in most browsers)
    if (bEllipsisAdded)
        this.divDisplayBox.title = sFull;
    else
        this.divDisplayBox.title = "";

    if (sCheckedValues != "-1") sCheckedValues = sCheckedValues.substring(0, sCheckedValues.length - 1);
    gEl("v_" + this.id).value = sCheckedValues;
    //alert("values = " + gEl("v_" + this.id).value);
    dclWM(this.id);
}

// handle a click in a participating checkbox
function DDCL_DropDownCheckList_HandleCheckboxClick() {
    // refresh the checked items display box
    this.DisplayCheckedItems();
}

// handle a click in the display box
function DDCL_DropDownCheckList_HandleDisplayBoxClick() {
    // toggle the display of the checklist
    this.ToggleCheckList();
}

// toggle the display of the checklist boxes
function DDCL_DropDownCheckList_ToggleCheckList() {
    if (this.divCheckboxes.style.display != "none")
        this.CloseCheckList();

    else
        this.OpenCheckList();
}

// explicitly close the checklist
function DDCL_DropDownCheckList_CloseCheckList() {
    // hide the checkboxes div
    if (this.divCheckboxes.style.display != "none") {
        if (isIE) {
            eval(this.divDisplayBox.onchange);
        } else {
            try {
                this.divDisplayBox.onchange();
            } catch (e) {
            }
        }
    }
    this.divCheckboxes.style.display = "none";

    // if we're using a shim, hide it as well
    if (this.dropDownMode == DDCL_DROPDOWNMODE_ONTOPWITHSHIM)
        this.shim.style.display = "none";
}

// explicitly open the checklist
function DDCL_DropDownCheckList_OpenCheckList() {
    // open the checkboxlist; first, position it below the displaybox

    // determine the position based on the dropDownMode
    if (this.dropDownMode == DDCL_DROPDOWNMODE_INLINE) {
        // inline mode; we're already setup as we need to be
        this.divCheckboxes.style.display = "block";
    }
    else {
        // on top modes; position the box
        this.divCheckboxes.style.left = DDCL_findPosX(this.divDisplayBox);
        this.divCheckboxes.style.top = DDCL_findPosY(this.divDisplayBox) + this.divDisplayBox.offsetHeight;
        this.divCheckboxes.style.width = 320 + 'px';
        this.divCheckboxes.style.display = "block";
        // if we want the shim, apply that now
        if (this.dropDownMode == DDCL_DROPDOWNMODE_ONTOPWITHSHIM) {
            this.shim.style.width = this.divCheckboxes.offsetWidth;
            this.shim.style.height = this.divCheckboxes.offsetHeight;
            this.shim.style.top = this.divCheckboxes.style.top;
            this.shim.style.left = this.divCheckboxes.style.left;
            this.shim.style.zIndex = this.divCheckboxes.style.zIndex - 1;
            this.shim.style.display = "block";
        }


    }
}

// wire methods as prototypes
DDCL_DropDownCheckList.prototype.DisplayCheckedItems = DDCL_DropDownCheckList_DisplayCheckedItems;
DDCL_DropDownCheckList.prototype.GetLabelForCheckbox = DDCL_DropDownCheckList_GetLabelForCheckbox;
DDCL_DropDownCheckList.prototype.HandleCheckboxClick = DDCL_DropDownCheckList_HandleCheckboxClick;
DDCL_DropDownCheckList.prototype.HandleDisplayBoxClick = DDCL_DropDownCheckList_HandleDisplayBoxClick;
DDCL_DropDownCheckList.prototype.ToggleCheckList = DDCL_DropDownCheckList_ToggleCheckList;
DDCL_DropDownCheckList.prototype.CloseCheckList = DDCL_DropDownCheckList_CloseCheckList;
DDCL_DropDownCheckList.prototype.OpenCheckList = DDCL_DropDownCheckList_OpenCheckList;




if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = SureClientWidth() + SureScrollLeft();
        yMousePosMax = SureClientHeight() + SureScrollTop();
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        //document.getElementById('testdiv').innerHTML = 'wex: ' + window.event.x + '; wey: ' + window.event.y + '; sl: ' + SureScrollLeft() + '; st: ' + SureScrollTop() + '; cw: ' + SureClientWidth() + '; ch: ' + SureClientHeight() + ';;\n';
        //document.body.appendChild(tn)
        //if(document.documentElement){
        //  xMousePos = window.event.x + document.documentElement.scrollLeft;
        //  yMousePos = window.event.y //+document.documentElement.scrollTop;
        //  xMousePosMax = document.body.clientWidth+document.documentElement.scrollLeft;
        //  yMousePosMax = document.body.clientHeight+document.documentElement.scrollTop;
        //} else {
        xMousePos = window.event.x + SureScrollLeft();
        yMousePos = window.event.y //+ SureScrollTop();
        xMousePosMax = SureClientWidth() + SureScrollLeft();
        yMousePosMax = SureClientHeight() + SureScrollTop();
        //}
    } else if (document.getElementById) {
        //var tn = document.createTextNode('pgx: ' + e.pageX + '; pgy: ' + e.pageY + '; wiw: ' + window.innerWidth + '; wih: ' + window.innerHeight + '; pxo: ' + window.pageXOffset + '; pyo: ' + window.pageYOffset + ';');
        //document.body.appendChild(tn)
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = SureClientWidth() + SureScrollLeft();
        yMousePosMax = SureClientHeight() + SureScrollTop();
    }
}


function SureClientWidth() {
    return filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function SureClientHeight() {
    return filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function SureScrollLeft() {
    return filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function SureScrollTop() {
    return filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function showFloatingMedia(obj, imagefile, border, floatstyle, offset) {
    try {
        if (imagefile.indexOf('no_image') > 0) return;
        var sHtml = '<img src="' + imagefile + '" width="400" />'
        var pT = document.createElement('div')
        if(offset)gFMOffset = offset;
        pT.id = 'js_floating_media_x'
        pT.onmousemove = function() { alignFloatingMedia(); }
        pT.style.zIndex = 511;
        pT.style.backgroundColor = 'white';
        pT.style.backgroundImage = 'url(/_lib/loading.gif)';
        pT.style.backgroundPosition = 'top center';
        pT.style.backgroundRepeat = 'no-repeat';
        //if(border==null||border==''){
        pT.style.border = '2px #A8BBB3 inset';
        //} else {
        //  pT.style.border = border;
        //}
        pT.style.width = 'auto';
        pT.style.position = 'absolute';
        pT.style.top = '0px';
        pT.style.left = '0px';
        pT.style.margin = 'auto';
        pT.style.display = 'none';
        pT.style.zIndex = 511;
        pT.innerHTML = sHtml
        document.body.appendChild(pT)
        //document.body.insertAdjacentHTML ("beforeEnd", sHtml);
        if (floatstyle == "2") {
            setTimeout('alignFloatingMedia2()', 20)
        } else {
            setTimeout('alignFloatingMedia()', 20)
        }
    } catch (ex) {
        alert(ex.message)
    }
}
var gFMOffset = 120;
function alignFloatingMedia2() {
    var fm = gEl('js_floating_media_x');
    if (fm) {
        fm.style.display = 'block'; 
        var ht = fm.offsetHeight
        var wd = fm.offsetWidth
        var oht = ((SureClientHeight() - ht) / 2) + SureScrollTop();
        //if(xMousePos>(SureClientWidth()/2)+40){
        //  fm.style.left = (xMousePos-40-wd) +'px';
        ///  fm.style.top = oht +'px';
        //}else{
        fm.style.left = gFMOffset + xMousePos + 'px';
        fm.style.top = oht + 'px';
        //}
        //fm.style.display='block';
    }
}

function alignFloatingMedia() {
    var fm = gEl('js_floating_media_x');
    if (fm) {
        fm.style.display = 'block';
        var ht = fm.offsetHeight
        var wd = fm.offsetWidth
        var oht = ((SureClientHeight() - ht) / 2) + SureScrollTop();
        if (xMousePos > (SureClientWidth() / 2) + 40) {
            fm.style.left = (xMousePos - 40 - wd) + 'px';
            fm.style.top = oht + 'px';
        } else {
            fm.style.left = 40 + xMousePos + 'px';
            fm.style.top = oht + 'px';
        }
        fm.style.display = 'block';
    }
}

function hideFloatingMedia() {
    try {
        var fm = gEl('js_floating_media_x');
        if (fm) fm.parentNode.removeChild(fm); //document.body.removeElement(fm);
        //var sHtml = '<div id="js_floating_media_x" style="z-index:512;width:auto;position:absolute;display:inline;"><img src="' + imagefile + '" /></div>'
        //document.body.insertAfter(sHtml);
    } catch (ex) {
        alert(ex.message)
    }
}

var gsEmailTemplate = "";
var gsEmailFrom = "";
var gsEmailTo = "";
var gsEmailSubject = "";
var gsEmailMsg = "";
var gsEmailJobAdId = "";
var gsEmailJobseekerId = "";
var EmailerBox;

function SendEmailBox(fsTempate, fsTo, fsFrom, fsSubj, fsMsg, fsJobAdId, fsJobseekerId) {
    gsEmailTemplate = '' + fsTempate;
    gsEmailFrom = '' + fsFrom;
    gsEmailTo = '' + fsTo;
    gsEmailSubject = '' + fsSubj;
    gsEmailMsg = '' + fsMsg;
    gsEmailJobAdId = '' + fsJobAdId;
    gsEmailJobseekerId = '' + fsJobseekerId;
    EmailerBox = new Boxy('<div id=\"dialogSendEmail\" style=\"text-align:center;width:720px;' + (SureClientHeight()-140) + 'px\"><iframe width=\"730\" height=\"' + (SureClientHeight()-140) + '\" src=\"/_tools/ajaxsendemail.aspx?p=' + gsEmailTemplate + '&t=' + gsEmailTo + '&f=' + gsEmailFrom + '&s=' + escape(gsEmailSubject) + '&m=' + escape(gsEmailMsg) + '&a=' + gsEmailJobAdId + '&j=' + gsEmailJobseekerId + '\" frameborder=\"0\"></iframe></div>', { title: 'Send Email', modal: true, center: true, unloadOnHide: true });
}
