// NOTE: This function sis used to record the "last" mouse click so the logic in
//              sched.php  can know id and "when" the user's activity has stopped

function validateEvalReferral(){
	if( document.getElementById("referralSource") ){
			if( document.getElementById("referralSource").value =="Referred by a friend" ){

						if(document.getElementById("referral_name")){
								var friend = document.getElementById("referral_name").value;
								if( friend == " " || friend == " " || friend == null || friend.indexOf("friend") != -1     ){
										alert( "Please finish the referral information before pressing the button" );
										return false;
									}else{
										return true;
									}//if - else
						}else{
									alert( "Please finish the referral information before pressing the button" );
									return false;
								}
				}//  if( document.getElementById("referralSource").value =="Referred by a friend" )
				
			//---START: TV PROGRAM REFERRALS -------
				
		if( document.getElementById("referralSource").value == "TV Ad" ){

					if(document.getElementById("tv-program")){
						    var index =  document.getElementById("tv-program").selectedIndex;
							var tvProg = document.getElementById("tv-program").options[index];
								if( tvProg == "" || tvProg == " " || tvProg == null || tvProg.indexOf("program") != -1     ){
										alert( "Please finish the referral information before pressing the button" );
										return false;
									}else{
										return true;
									}//if - else
					}else{
									alert( "Please finish the referral information before pressing the button" );
									return false;
							}
							
				}//  if( document.getElementById("referralSource").value =="Referred by a friend" )
				
			//---END: TV PROGRAM REFERRALS -------	
	 }//if( document.getElementById("referralSource") )
else{
		alert( "Please finish the referral information before pressing the button" );
		return false;
		}
return false;
}//validateEvalReferral()

function openReferralBox(){
var index = document.getElementById("referralSource").selectedIndex;
var input = document.getElementById("referralSource").options[index];
//alert( "selected ="+input.value );
	if( input.value == "Referred by a friend" ){
	      
			document.getElementById("referral_info").style.display="block";
	}

}

function lastMouseClick(){
	if(document.getElementById("leadTableRow") ){
	
	var id = document.getElementById("leadTableRow").value;
		
	}
	if(id !=null){
			var now    = new Date();
			var hour   = now.getHours();
	  		var minute = now.getMinutes();
			var processFile	= "record_last_click.php" ;// <------ Process File
			var postValues		= "id="+id+"&time="+hour+minute; 
			var div_id				=  "test";
			
			pkl_AjaxCall_POST(processFile, postValues, div_id);
			
//alert("ROW="+id+"  time = "+time );
			
	}// if(id !=null)
}//  function lastMouseClick(id)

function getClockTime(){
	  // var now    = new Date();
	  // var hour   = now.getHours();
	  // var minute = now.getMinutes();
	   //var second = now.getSeconds();
	   //var timeString = hour +':' + minute +';
	  // return timeString;
} // function getClockTime()


function getCampusReferrals(){
var selectCampus 	= document.getElementById('campus') ;
var index     				= selectCampus.options.selectedIndex ;
var campus 				= selectCampus.options[index].text ;
var postValues			= "campus="+campus ; 
var processFile		= "get_campus_referrals.php" ;// <------ Process File
var div_id					=  "campusReferrals";
			
pkl_AjaxCall_POST(processFile, postValues, div_id);		

//alert("CAMPUS="+campus );
			
}//  getCampusReferrals()

function getReferral_info(){
var referralSource 	= document.getElementById('referralSource') ;
var index     				= referralSource.options.selectedIndex ;
var referral				= referralSource.options[index].text ;
var campus 	= document.getElementById('campus') ;
var index     				= campus.options.selectedIndex ;
var campus				= campus.options[index].text ;
if( referral == 'Referred by a friend') { 
referral = "referredbyafriend"; 
}
if( referral == 'TV Ad') { 
referral = "tv_ad"; 
}
if( referral == 'Please Select One.') { 
			referralSource.style.backgroundColor = "#990000";
}else{
			referralSource.style.backgroundColor = "#fff";
}

var postValues			= "referral="+referral+"&campus="+campus ; 
var processFile		= "process_referral_info.php" ;// <------ Process File
var div_id					=  "referral_info";
			
pkl_AjaxCall_POST(processFile, postValues, div_id);		

//alert("CAMPUS="+campus );
			
}//  function getReferral_info()


//+++++++++++++++++++++++++++++++++++++++++++++
//      ZEMELRECK FUNCTION
//+++++++++++++++++++++++++++++++++++++++++++++
 
function pkl_AjaxCall_POST(processFile, postValues, div_id){
 	var XMLHttpRequestObject = false;
  	if (window.XMLHttpRequest) {
				XMLHttpRequestObject = new XMLHttpRequest();
  			} else if (window.ActiveXObject) {
				XMLHttpRequestObject = new 
				ActiveXObject("Microsoft.XMLHTTP");
  			}//if-else
  	if(XMLHttpRequestObject) {
			XMLHttpRequestObject.open("POST", processFile); 
    		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
			XMLHttpRequestObject.onreadystatechange = function() { 
			// AJAX loading message and image
			document.getElementById(div_id).innerHTML = "<img src='ajax-loader.gif' /><br />Please wait..." ;

	  							if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { 
	  									if(document.getElementById(div_id)){
		  										document.getElementById(div_id).innerHTML = XMLHttpRequestObject.responseText;
		  									}
		  							
	  							} //if
						} //function
			XMLHttpRequestObject.send(postValues); 
  		}// if(XMLHttpRequestObject)
  }
  //function pkl_AjaxCall(processFile, div )

function twoRadioToggleLogic(id_in, otherRadio ){
//  id_in is the ID of the current radio button
// otherRadio is the ID of the other "opposing" radio button
//  if  one is on then other is off
var  a  = document.getElementById(id_in);
var  b  = document.getElementById(otherRadio);
if(a.checked==true ){ b.checked = false ; }
}
