function fillOther(v,w,ww) {
var f = document.forms["jobfairForm"];
f.elements[w].value=v;
f.elements[ww].value=v;
}

function processform() {
var f = document.forms["jobfairForm"];


if (f.billingMethod[1].checked) {

if(f.invoiceCompanyName.value.length==0) {
alert('Invoice billing: Company Name is missing.');return(false);
}
if(f.invoiceFname.value.length==0||f.invoiceLname.value.length==0) {
alert('Please provide a Name for Invoicing.');return(false);
}
if(f.invoiceAddress.value.length==0) {
alert('Please provide Invoicing Billing Address.');return(false);
}
if(f.invoiceCity.value.length==0) {
alert('Invoice Billing: City is missing.');return(false);
}
if(f.invoiceState.value.length==0) {
alert('Invoice Billing: State is missing.');return(false);
}
if(f.invoiceZipcode.value.length==0) {
alert('Invoice Billing: Zip Code is missing.');return(false);
}
if(f.invoiceAreacode.value.length==0) {
alert('Invoice Billing: Phone Areacode is missing.');return(false);
}

} // end if (f.billingMethod[1].checked)

if (!f.packageType[0].checked&&!f.packageType[1].checked&&!f.packageType[2].checked) {
alert('You have not selected a jobfair Package.'); 
return(false);
}

if(f.companyName.value.length==0) {
alert('You have not entered your Company Name');
return(false);
}

if(f.fname.value.length==0||f.lname.value.length==0) {
alert('Please provide a Contact person');
return(false);
}

if(f.address.value.length==0||f.city.value.length==0||f.state.value.length==0||f.zipcode.value.length==0) {
alert('Your company address info is incomplete.');
return(false);
}

if(f.areacode.value.length==0||f.phoneNumber.value.length==0||f.email.value.length==0) {
alert('Please provide your company Phone Number and Email address');
return(false);
}

if (!f.billingMethod[0].checked&&!f.billingMethod[1].checked&&!f.billingMethod[2].checked) {
alert('Please select a billing method.'); 
return(false);
}



if (f.billingMethod[0].checked) {
if(f.ccType.selectedIndex==0) {
alert('Please select Credit Card type.');return(false);
}
if(f.ccFname.value.length==0||f.ccLname.value.length==0) {
alert('Please provide Creditcard holder\'s Name.');return(false);
}

if(f.ccAddress.value.length==0) {
alert('Please provide Creditcard Billing Address.');return(false);
}
if(f.ccCity.value.length==0) {
alert('Credit card Billing City is missing.');return(false);
}
if(f.ccState.value.length==0) {
alert('Credit card Billing State is missing.');return(false);
}
if(f.ccZipcode.value.length==0) {
alert('Credit card Billing Zip Code is missing.');return(false);
}
if(f.ccAreacode.value.length==0) {
alert('Credit card Billing Phone Areacode is missing.');return(false);
}
if(f.ccNumber.value.length==0) {
alert('Credit card Number is missing.');return(false);
}
if(f.ccExpirationMonth.value.length==0) {
alert('Credit card Expiration Month is missing.');return(false);
}
if(f.ccExpirationYear.value.length==0) {
alert('Credit card Expiration Year is missing.');return(false);
}

} // end if (f.billingMethod[0].checked)
f.action="processForm.php";

}









function clearIt(w) {
document.getElementById(w).value='';
}









function validateNewFair(w) {
var f = document.forms[w];

if(f.city.value.length==0) {
alert('City is missing.');
f.city.focus();
return(false);
}

if(f.jobfairDate.value.length==0) {
alert('Date is missing.');
f.jobfairDate.focus();
return(false);
}


if(f.jobfairTime.value.length==0) {
alert('Time is missing.');
f.jobfairTime.focus();
return(false);
}


if(f.venue.value.length==0) {
alert('Venue is missing.');
f.venue.focus();
return(false);
}


if(f.pkg1.value.length==0) {
alert('Enter pkg1 price.');
f.pkg1.focus();
return(false);
}


if(f.pkg2.value.length==0) {
alert('Enter pkg2 price.');
f.pkg2.focus();
return(false);
}

f.action='edit.jobfair.php';
}




/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function






function getData() {
var el = document.forms['newFair'].elements['listFairs'];
var id = el.options[el.selectedIndex].value, url = 'get.data4editing.php?id='+id;
window.frames["dataSrc"].location.replace(url);
}



function fillForm(c,s,jD,jT,v,p1,p2,p3,i,d) {

var obj = parent.document.forms['newFair'];

obj.city.value=c;
obj.state.selectedIndex=s-1;
obj.jobfairDate.value=jD;
obj.jobfairTime.value=jT;
obj.venue.value=v;
obj.pkg1.value=p1;
obj.pkg2.value=p2;
obj.pkg3.value=p3;
obj.id.value=i;
obj.deduction.value=d;

}


function delData() {

var el = document.forms['newFair'].elements['listFairs'];
var label = el.options[el.selectedIndex].text;
var id = el.options[el.selectedIndex].value;

if(confirm('Are you sure you want to delete the jobfair\n\n'+label)) {
window.frames["dataSrc"].location.href='get.data4editing.php?delData=&id='+id;
}
}

function fillCodeForm(c,d,i,r,p,e) {

var obj = parent.document.forms['newFair'];
p=(p>0)?p:''; r=(r>0)?r:'';
obj.discountCode.value=c;
obj.descr.value=d;
obj.id.value=i;
obj.dollarDiscount.value=r;
obj.percentDiscount.value=p;
obj.expires.value=e;

}

function validateNewCode(w) {
var f = document.forms[w],p=f.percentDiscount;
var d=f.dollarDiscount, c = f.discountCode;

if(c.value.length==0) {
alert('Code is missing.');
c.focus();
return(false);
}


if(p.value.length==0 && d.value.length==0) {
alert('Indicate discount type as DOLLAR AMOUNT, or PERCENTAGE.');
d.focus();
return(false);
} 


if(p.value.length>0 && d.value.length>0) {
alert('Discount cannot be both DOLLAR AMOUNT and PERCENTAGE.');
d.focus();
return(false);
} 


if(p.value.length>0 && isNaN(parseInt(p.value))) {
alert('Numbers only.');
p.value='';
p.focus();
return(false);
} 


if(d.value.length>0 && isNaN(parseInt(d.value))) {
alert('Numbers only.');
d.value='';
d.focus();
return(false);
} 
if(f.expires.length<1) {
alert('Enter expiration date.');
f.expires.focus();
return(false);
} 



f.action='edit.discount.code.php';
}


function getCode() {
var el = document.forms['newFair'].elements['listCodes'];
var id = el.options[el.selectedIndex].value;
window.frames["dataSrc"].location.href='get.code4editing.php?id='+id;

}


function delCode() {

var el = document.forms['newFair'].elements['listCodes'];
var label = el.options[el.selectedIndex].text;
var id = el.options[el.selectedIndex].value;

if(confirm('Are you sure you want to delete the code\n\n'+label)) {
window.frames["dataSrc"].location.href='get.code4editing.php?delData=&id='+id;
}

}





function validateNewRep(w) {
var f = document.forms[w];

if(f.fname.value.length==0) {
alert('First Name is missing.');
f.fname.focus();
return(false);
}

if(f.lname.value.length==0) {
alert('Last Name is missing.');
f.lname.focus();
return(false);
}

if(f.city.value.length==0) {
alert('City is missing.');
f.city.focus();
return(false);
}

if(f.zipcode.value.length==0) {
alert('Zipcode is missing.');
f.zipcode.focus();
return(false);
}

if(f.phoneHome.value.length==0) {
alert('Home Phone is missing.');
f.phoneHome.focus();
return(false);
}

if(f.phoneCell.value.length==0) {
alert('Cell Phone is missing.');
f.phoneCell.focus();
return(false);
}

if(f.login.value.length==0) {
alert('Enter a Login name.');
f.login.focus();
return(false);
}

if(f.password.value.length==0 || f.password.value!=f.password2.value) {
alert('Passwords do not match, or are blank.');
f.password.focus();
return(false);
}

if(f.email.value.length==0) {
alert('Enter email address.');
f.email.focus();
return(false);
}

f.action='edit.rep.php';
}











function validateNewEmpl(w) {
var f = document.forms[w];

if(f.companyName.value.length==0) {
alert('Company Name is missing.');
f.companyName.focus();
return(false);
}

if(f.cityOfInterest.selectedIndex==0) {
alert('In what city are you likely to attend a jobfair?.');
f.cityOfInterest.focus();
return(false);
}


if(f.fname.value.length==0) {
alert('First Name is missing.');
f.fname.focus();
return(false);
}

if(f.lname.value.length==0) {
alert('Last Name is missing.');
f.lname.focus();
return(false);
}

if(f.city.value.length==0) {
alert('City is missing.');
f.city.focus();
return(false);
}

if(f.zipcode.value.length==0) {
alert('Zipcode is missing.');
f.zipcode.focus();
return(false);
}

if(f.areacode.value.length==0) {
alert('Areacode is missing.');
f.areacode.focus();
return(false);
}

if(f.phoneNumber.value.length==0 || f.phoneNumber2.value.length==0) {
alert('Phone Number is missing.');
f.phoneNumber.focus();
return(false);
}

if(f.login.value.length==0) {
alert('Enter a Login name.');
f.login.focus();
return(false);
}

if(f.password.value.length==0 || f.password.value!=f.password2.value) {
alert('Passwords do not match, or are blank.');
f.password.focus();
return(false);
}

if(f.login.value==f.password.value) {
alert('Login cannot be the same as the Password.');
f.password.focus();
return(false);
}

if(f.email.value.indexOf('@',0) == -1 || f.email.value.indexOf('.',0) == -1){
alert("Invalid email address.\nPlease check and re-enter your email address.");
f.email.focus();
return(false);
}

f.action='edit.empl.php';

}






function getRepData() {
var el = document.forms['newRep'].elements['listReps'];
var id = el.options[el.selectedIndex].value;
window.frames["dataSrc"].location.href='get.rep.data4editing.php?id='+id;

}

function delRepData() {
var el = document.forms['newRep'].elements['listReps'];
var id = el.options[el.selectedIndex].value;
var rep = el.options[el.selectedIndex].text;
window.frames["dataSrc"].location.href='get.rep.data4editing.php?id='+id;

   if(confirm('Are you sure you want to delete the Rep: '+rep+'?')){
      window.frames["dataSrc"].location.href='get.rep.data4editing.php?id='+id+'&delData=';
   }
   else {
      alert('The Rep: '+rep+' not deleted');
   }

}


function fillRepForm(ln,fn,c,s,z,pH,pC,l,p,i,h,e,cP) {

var obj = parent.document.forms['newRep'];

obj.fname.value=fn;
obj.lname.value=ln;
obj.email.value=e;
obj.city.value=c;
obj.state.selectedIndex=s-1;
obj.zipcode.value=z;
obj.phoneHome.value=pH;
obj.phoneCell.value=pC;
obj.login.value=l;obj.login.disabled=true;
obj.password.value=obj.password2.value=p;
obj.id.value=i;
obj.comments.value=h;
obj.percentCommision.value=cP;

}


function valideAgentLogin() {
var f = document.forms['authForm'];
   if(f.elements['login'].value.length<1) {
      alert('Enter your Agent login name');f.elements['login'].focus();
      return false;
   }
   if(f.elements['passwd'].value.length<1) {
      alert('Enter your password');f.elements['passwd'].focus();
      return false;
   }
f.action='cookie2.php';
}






function validateNewRep2(w) {
var f = document.forms[w];

if(f.fname.value.length==0) {
alert('First Name is missing.');
f.fname.focus();
return(false);
}

if(f.lname.value.length==0) {
alert('Last Name is missing.');
f.lname.focus();
return(false);
}

if(f.city.value.length==0) {
alert('City is missing.');
f.city.focus();
return(false);
}

if(f.zipcode.value.length==0) {
alert('Zipcode is missing.');
f.zipcode.focus();
return(false);
}

if(f.areacode.value.length==0) {
alert('Areacode is missing from your phone number.');
f.areacode.focus();
return(false);
}

if(f.phoneNumber.value.length==0||f.phoneNumber2.value.length==0) {
alert('Phone Number is missing.');
f.phoneNumber.focus();
return(false);
}


if(f.email.value.indexOf('@',0) == -1 || f.email.value.indexOf('.',0) == -1){
alert("Invalid email address.\nPlease check and re-enter your email address.");
f.email.focus();
return(false);
}

if(f.login.value.length==0) {
alert('Enter a Login name.');
f.login.focus();
return(false);
}

if(f.password.value.length==0 || f.password.value!=f.password2.value) {
alert('Passwords do not match, or are blank.');
f.password.focus();
return(false);
}


if(f.login.value== f.password.value) {
alert('Password cannot be the same as Username.');
f.password.value=f.password2.value='';f.password.focus();
return(false);
}

f.action='update.rep.php';
}


function chkName(v) {
window.frames['frm'].document.location.href='verify.login.php?login='+v;
}


function chkName2(v) {
window.frames['frm'].document.location.href='verify.login.php?login='+v;
}


function chkEmail2(v) {
window.frames['frm'].document.location.href='verify.login.php?email='+v;
}


function chkPsswd(p) {
window.frames['frm'].document.location.href='verify.pass.php?passwd='+p;
}


function validatePassForm(oP,nP,nP2) {
var f = window.frames['frm'].document.signupForm;

if(oP.length=='') {
alert('Old Password is empty.'); return(false);
}

if(nP.length=='') {
alert('New Password is empty.'); return(false);
}

if(nP2.length==''||nP!=nP2) {
alert('New Passwords do not match.'); return(false);
}

window.frames['frm'].document.location.href='verify.pass.php?oP='+oP+'&nP='+nP+'&nP2='+nP2;

}



function chkEmpl(v,lmt,w) {
   //alert('chk.empl.php?val='+v+'&lmt='+lmt+'&contactType='+w);
   //window.frames['frm'].document.location.href='chk.empl.php?val='+v+'&lmt='+lmt+'&contactType='+w;
   window.frames['frm'].location='chk.empl.php?val='+v+'&lmt='+lmt+'&contactType='+w;
}



var rq;

function chkJFStatus(f,eid) {

var url = 'chk.jfstatus.php?JFID='+f.jfValHolder.value+'&empID='+eid;

    if (window.XMLHttpRequest) {
        rq = new XMLHttpRequest();
        rq.onreadystatechange = processResp;
        rq.open("GET", url, true);
        rq.send(null);

    } else if (window.ActiveXObject) {
        rq = new ActiveXObject("Microsoft.XMLHTTP");
        if (rq) {
            rq.onreadystatechange = processResp;
            rq.open("GET", url, true);
            rq.send();
        }
    }
}
function processResp() {
    if (rq.readyState == 4) {
        if (rq.status == 200) {
var myArr = rq.responseText.split('::');

	   if(myArr[1]==1) {
	      alert("WARNING: Employer is already signed up for selected Job Fair. However multiple sign-ups are OK.\nAre you sure you want to sign them up for another booth?");
	   }
        } 

    }
}


function matchDom(v,lmt) {
window.frames['frm'].document.location.href='chk.empl.php?val='+v+'&lmt='+lmt;
}

function hideThs(e) {
e.style.visibility="hidden";
}


function popReply(id) {
var opts = 'width=600,height=460,scrollbars=yes,resizable=yes,toolbars=yes';
var new_win = window.open('./sendmail.php?id='+id,'reply',opts);
new_win.focus(); return false;
}

function OpenEditWin(theVar){
var new_window = window.open('get.predefined.email4Edit.php?type='+theVar,'richie','width=500,height=350,scrollbars,resizable'); new_window.focus(); return false;
}


function getEmailMsgFromDb(theMsg){
top.getMsgsFromDb.location.href='get.msg.from.db.php?type='+theMsg;
}

function popNotes() {
var n_win=window.open('filter.help.html','help','width=400,height=300,left=200,top=210');
n_win.focus();
}

function popHist(e,c) {
var h_win = document.open('./msg.history.php?mail='+e+'&cityOfInterest='+c,'histwin','width=650,height=400,left=100,top=100,scrollbars=yes,resizable=yes'); h_win.focus();
}


function addPayment() {

var h_win = document.open('./add.payment.php','histwin','width=790,height=450,left=0,top=100,scrollbars=yes,resizable=yes'); h_win.focus();
}


function checkPayForm() {
var f = document.paymentForm;

if(f.selectType[1].checked) {

   if(f.checkNumber.value.length==0) {
      alert('Enter check number.'); 
      return(false);
   }

   if(f.chkAmt.value.length==0) {
      alert('Enter check amount.'); 
      f.chkAmt.focus(); return(false);
   }
}

if(f.selectType[0].checked) {

   if(f.ccRefNum.value.length==0) {
      alert('Enter Credit card reference number.'); 
      f.ccRefNum.focus(); return(false);
   }

   if(f.ccAmt.value.length==0) {
      alert('Enter credit card payment amount.'); 
      f.ccAmt.focus(); return(false);
   }

}
document.action='add.payment.php';
}




function popGen(url,width,height,resizable,scrollbars,name,leftpos,toppos)
{
   if(name=='')   {    var name='genericWin';   }
   if(width=='')   {    var width=600;   }
   if(height=='')   {    var height=600;   }
   if(resizable=='')   {    var resizable=1;   }
   if(scrollbars=='')   {    var scrollbars=1;   }
   if(leftpos=='')   {    var leftpos=10;   }
   if(toppos=='')   {    var toppos=40;   }

   var genericWin = window.open(url, name, 'width='+width+', height='+height+', resizable='+resizable+', scrollbars='+scrollbars+', top='+toppos+', left='+leftpos);
   genericWin.creator=self;
   genericWin.focus();
}

function sortByRep(ndx) {
var qStr = 'rep='+document.sortForm.rep.options[ndx].value+'&ndx='+ndx;
document.location.href='view.commisions.php?'+qStr;
}



function warn(w,p,n) {
if( w.checked == true ){ 

if(p<n) {
alert('\n\n\nImportant Alert:\n\nOnly partial payment received.\n\nDo you really want to pay commision on it now?\n\n\n\n'); 
}
}
return;
}

function getFair(ndx,val) {
document.location.href="/adrequest/?ndx="+ndx+"&val="+val;
}

function prefill(f,v) {
f.ccState.selectedIndex=f.invoiceState.selectedIndex=v;
}


var req;

function getDetails(r,f,p) {
document.getElementById('mat').innerHTML='';
document.getElementById('display').style.visibility='visible';
var url = 'get.details.php?rep='+r+'&fair='+f+'&filter='+p;
//alert(url);
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);

    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
		document.getElementById('mat').innerHTML=req.responseText;
		document.getElementById('display').style.visibility='hidden';
        } 

    }
}


function confAction() {
var u='/rep/download.all.employer.data.php';
var msg='Are you sure you want to download data for all employers, including history for past Job Fairs?'; 
   if(confirm(msg)) {
      document.location.href=u;
   }
}
function openWin(url,w,h,r,s,n)
{
if(n=='') {var n='genericWin';}

//n=the_name_of_new_popup_window, w=width, h=height, r=resizable, s=scrollbars

var genericWin = window.open(url, n, 'width='+w+', height='+h+', resizable='+r+', scrollbars=' + s);

genericWin.focus();
}

function validateXtra(xcount) {
   var fnameObj = 'fname'+xcount,lnameObj = 'lname'+xcount,coyContactObj = 'coyContact'+xcount,emailObj = 'email'+xcount, f=document.forms['jobfairForm'];

   if(f.elements[fnameObj].value.length>0 && f.elements[lnameObj].value.length>0 && f.elements[emailObj].value.length>0) {
      if(confirm('Should '+f.elements[fnameObj].value.toUpperCase()+' '+f.elements[lnameObj].value.toUpperCase()+' be the person who purchased this Job fair?\n\n(1) If so, click "OK", then put a checkmark in the checkbox.\n\n(2) Otherwise, click "Cancel" to use the Main Contact, then remove the checkmark in the checkbox.')) {
         f.elements[coyContactObj].checked=true;
      }
      else {
         f.elements[coyContactObj].checked=true; // this is redundant, but done on purpose to mak sure user is paying attention
     }
   }
}

