
function EmailMsg(to, xID, xName, xSubject, xBody) {
  // SET MESSAGE VALUES
  //var to = "person@company.com";
  //var cc = "another_person@company.com";
  //var bcc = "yet_another_person@company.com";
  var x = window.location.hostname;
  var body = 
      "Dear " + xName +",\n\n"+
      "http://"+x+"/ei_interview_submit.asp?xID=" + xID

  // BUILD MAIL MESSAGE COMPONENTS 
  var doc = "mailto:" + to + 
      //"?cc=" + cc + 
      //"&bcc=" + bcc + 
      "&subject=" + escape('Exit Interview') + 
      "&body=" + escape(body); 

  // POP UP EMAIL MESSAGE WINDOW
  window.location = doc;
}

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}


function MyMoveItem(fromObj, toObj) // moves Items from one select list to another
{
   for (var selIndex = fromObj.length - 1; selIndex >= 0; selIndex--)
   {
      // Is this option selected?
      if (fromObj.options[selIndex].selected)
      {
         // Get the text and value for this option.
         var newText  = fromObj.options[selIndex].text;
         var newValue = fromObj.options[selIndex].value;
 
         // Create a new option, and add to the other select box.
         var newOption = new Option(newText, newValue)
         toObj[toObj.length] = newOption;

         // Delete the option in the first select box.
         fromObj[selIndex] = null;
      }
   }
}

function makeStringFromSelect(selectCtrl, valSeparator) {
 // transforms the select list items into selected items for a hidden field - used with MyMoveItem
// assign value to a hidden field
//valSeparator = separator value
	var i;
	var j = 0;
	var outlist = "";

	for (i = 0; i < selectCtrl.options.length; i++) {
		if (j > 0) {
			outlist = outlist + valSeparator;
		}
		outlist = outlist + selectCtrl.options[i].value;
		j++;
	}
	return outlist;
}


function ClearForm(f) // clears form values =
{ 
   l=f.length
   var i = 0
   var n =""
   do {
	   //''if (f.elements[i].name !=='btnSubmit'){
	   //if (f.elements[i].type!=="button" || f.elements[i].type!=="submit") { 
	   if ((f.elements[i].type !='button') && (f.elements[i].type !='submit') && (f.elements[i].type !='hidden')){
	   f.elements[i].value = '';
	   f.elements[i].style.background='#EEEEEE';}
	   i=i+1; 
   }
   while (i <l);
   
} 
function checkrequired(which){ // validates ALL required fields in the form, provided default value is ""
//the name of field has to start with "r_", submitted value cannot be zero length
//turns background yellow if empty
//field id is used for the error message
//usage: form onSubmit="return checkrequired(this)"
	var pass=true
	if (document.images){
		var error = ""
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.name.substring(0,2)=="r_"){
				
			if (tempobj.value.length == 0){
				which.elements[i].style.background = '#FFFFCC'; 
				error += which.elements[i].id + "\n";
				pass=false
				}
			}
		}
	}
	if (!pass){
		alert("The following required fields are not complete:\n" +error);
		return false
		}
	else
	return true
}

function checkrequired2(which){ // validates ALL required fields in the form, provided default value is ""
//the name of field has to start with "r_", submitted value cannot be zero length
//turns background yellow if empty
//field id is used for the error message
//usage: form onSubmit="return checkrequired(this)"
	var pass=true
	if (document.images){
		var error = ""
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.name.substring(0,2)=="r_"){
			if (tempobj.value==false){
				which.elements[i].style.background = '#FFFFCC'; 
				error += which.elements[i].id + "\n";
				pass=false
				}
			}
		}
	}
	if (!pass){
		alert("The following required fields are not complete:\n" +error);
		return false
		}
	else
	return true
}


function validateEmpty(fld) { // function that validates an empty field, turns background yellow if empty (should we use the new one "checkrequired(which)"
    var error = "";
	if (fld.value.length == 0) {
        fld.style.background = '#FFFFCC'; 
		TheLabel = fld.id;
        error = TheLabel + "\n" 
	} else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateRadio(fld) { // validates radio field
	var error = "";
	var TheLabel = "";
	myOption = -1;
	for (i=fld.length-1; i > -1; i--) {
		if (fld[i].checked) {
			myOption = i; i = -1;
			}
		}
	if (myOption == -1) {
			for (i=0;i<fld.length;i++){
				fld[i].style.background = '#FFFFCC';
				TheLabel = fld[i].id
				}
			error = TheLabel + "\n" 
			
	} else {
        for (i=0;i<fld.length;i++){
				fld[i].style.background = 'White';
				}
		}
	return error;
}

function validateNumeric(field) { // validation for numeric field validation, use with onBlur="validateNumeric(this)"
var valid = "0123456789"
var pass = "yes";
var temp;
if (field.value.length!=0) {
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") pass = "no";
		}
	}
if (pass == "no") {
	alert("Invalid entry.  Only numbers are accepted.");
	field.style.background = '#FFFFCC'; 
	field.value = '';
	field.focus();
	field.select();
	return false;
	}

}

function validateMoney(field) { // validation for numeric field validation, use with onBlur="validateNumeric(this)"
var valid = "0123456789$."
var pass = "yes";
var temp;
if (field.value.length!=0) {
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") pass = "no";
		}
	}
if (pass == "no") {
	alert("Invalid entry.  Only money values are accepted.");
	field.style.background = '#FFFFCC'; 
	field.value = '';
	field.focus();
	field.select();
	return false;
	}

}


function checkdate(input){
//var returnval=false
if (input.value.length!=0){
	var monthfield=input.value.split("/")[0]
	var dayfield=input.value.split("/")[1]
	var yearfield=input.value.split("/")[2]
	var dayobj = new Date(yearfield, monthfield-1, dayfield)
	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getYear()!=yearfield)){
		alert("Invalid Day, Month, or Year range detected. Please correct and submit again.\n Date should be in m/d/yy format.") ;
		input.style.background = '#FFFFCC';
		input.focus();
		input.select();
		return false}
	else
		{input.style.background = '#EEEEEE';}
}
else
return true
}


function trim(s) /// trims whitespac from a field entry
{
  return s.replace(/^\s+|\s+$/, '');
} 

function cInt(s) { //converts money to integer
	s = s.replace("$", '')
	s.replace(",", '')
	return parseFloat(s)
}
///***** added by ks for external site validation process
var ext_val_msg;

function ext_txt_required(iname, imsg) {
	var input = document.getElementById(iname);
	if (input.value.length!=0) {
			input.style.background = '#EEEEEE';
	}
	else {
	   		input.style.background = '#FFFFCC';
			ext_val_msg += imsg;
	}
}

function ext_sel_required(iname, imsg) {
	var input = document.getElementById(iname);
	if (input.selectedIndex!=0) {
			input.style.background = '#EEEEEE';
	}
	else {
	   		input.style.background = '#FFFFCC';
			ext_val_msg += imsg;
	}
}

function ext_pass_required(iname, iname2) {
	var input = document.getElementById(iname);
	var input2= document.getElementById(iname2);
	if ((input.value.length!=0 && input2.value.length!=0) && (input.value==input2.value)) {
	
			input.style.background = '#EEEEEE';
			input2.style.background = '#EEEEEE';
	}
	else {
	   		input.style.background = '#FFFFCC';
	   		input2.style.background = '#FFFFCC';
	   		if (input.value.length==0 && input2.value.length==0) {
				ext_val_msg += "You must enter a valid password\n";
			} else {
				ext_val_msg += "The passwords you have entered do not match\n";
			}
	}
}

function ext_chk_email_required(iname, imsg) { 
	var fld=document.getElementById(iname);
    var tfld = trim(fld.value); // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;   
    if (!emailFilter.test(tfld) || fld.value.match(illegalChars) || fld.value.length==0)
        {
	   		fld.style.background = '#FFFFCC';
			ext_val_msg += imsg;	
   		 } else {
   		 	fld.style.background = '#EEEEEE';
   	}
}
	
function enumpage() {
 var f=document.forms;
 var e, aline
 var w= window.open("","enumwin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=500");
	 aline = '<html><head><link href="/newsendss/sendss.css" rel="stylesheet" type="text/css"></head>';
	 aline += '<body>';
	 for (i=0; i < f.length; i++) {
	    e = f[i].elements
	    aline += '<b>'+f[i].name + '  - ' + i + '</b> - ' + f[i].action + ' <br><table border=0 cellpadding=2 cellspacing=2>';
	 	for (j=0; j < e.length; j++) {
	 		aline += '<TR><td>';
 			aline += e[j].value.replace('"','\'') + '</td>';
	 		aline += '<td>' + e[j].type + '</td>';
	 	aline += '<td>'+f[i].name+'_' + e[j].name+'</td></tr>';
	 	}
	 aline += '</table><br><br>';
	 }
 aline += '</body></html>';
 w.document.write (aline);

}
///***** 

function validExt(theFile) { // validate extension - allow RTF, DOC, TXT only
	var sFile = theFile.value.toLowerCase();
	if (sFile.length>0){
		var ext = sFile.substring(sFile.lastIndexOf('.'),sFile.length);
		//alert(ext)
		if ((ext== '.doc') || (ext == '.txt') || (ext == '.rtf')) { 
			//document.frmUpload.submit();
			return true
			}
		else {
			alert("Invalid file type. Please select MS Word document or plain text file to upload");
			theFile.focus;
			theFile.select();
			theFile.value = '';
			return false
			}
	}
} 

function validExtPDF(theFile) { // validate extension - allow RTF, DOC, TXT only
	var sFile = theFile.value.toLowerCase();
	if (sFile.length>0){
		var ext = sFile.substring(sFile.lastIndexOf('.'),sFile.length);
		//alert(ext)
		if ((ext== '.pdf')) { 
			//document.frmUpload.submit();
			return true
			}
		else {
			alert("Invalid file type. Please select PDF file to upload");
			theFile.focus;
			theFile.select();
			theFile.value = '';
			return false
			}
	}
} 


function validateEmail(fld) { // validates a form field for correct e-mail address - use with onBlur="validateEmail(this)"
var tfld = trim(fld.value); // value of field with whitespace trimmed off
if (tfld.length!=0) 
	{
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;  
	if ((!emailFilter.test(tfld)) || (fld.value.match(illegalChars)))
			{
			alert("Please enter a valid email address.");
			fld.focus();
			fld.select();	
			return false;
			 } 
		else
			return true;
	}
}
	
function chklength(fld, num) // validates field length
{
  if (fld.value.length > num)
  {
    alert("This field must not exceed the maximum number of characters allowed.");
  }
}

function showhide(what,obj) {  // shows/hides form element depending on the checkbox status
    if(what.checked) {
        obj1 = document.getElementById(obj);
        obj1.style.visibility = 'visible';
        
    } else {
        obj1 = document.getElementById(obj);
        obj1.style.visibility = 'hidden';
    
    }
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
