var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
var states=['AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY'];
var xmlHttp;
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";
var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); 
var defaultDateSeparator = "/";        // common values would be "/" or "."
var defaultDateFormat = "mdy"    // valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

function validateZIP(field) 
{
var valid = "0123456789-";
var hyphencount = 0;
var returnVal = true;

if (field.length!=5 && field.length!=10) 
  {
     //alert("Please enter your 5 digit or 5 digit+4 zip code.");
     returnVal = false;
  } 

	for (var i=0; i < field.length; i++) 
		{
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
		  //alert("Invalid characters in your zip code.  Please try again.");
		  returnVal = false;
		}
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
		{
		    //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
		    returnVal = false;
		   } 
		}

return returnVal;
}

function echeck(str)
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}

 
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char; 
   if (sText.length=0) IsNumber=false; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function populatedropdown(dayfield, monthfield, yearfield)
{
	var today=new Date();
	var dayfield=document.getElementById(dayfield);
	var monthfield=document.getElementById(monthfield);
	var yearfield=document.getElementById(yearfield);
	if (today.getDate()<10)
	 {
	   dayfield.value = '0'+today.getDate();
	 } else { dayfield.value = today.getDate(); }	
	
	if (today.getMonth()<10)
	 {
	   monthfield.value = '0'+today.getMonth();
	 } else { monthfield.value = today.getMonth(); }
	 
	if (today.getFullYear()<10)
	 {
	   yearfield.value = '0'+today.getFullYear();
	 } else { yearfield.value = today.getFullYear(); }	 
}

function populatetimefileds(hourfield, minutefield) 
{
 var now = new Date();
 var hourfield=document.getElementById(hourfield);
 var minutefield=document.getElementById(minutefield); 
 var text;
 for (var i=0; i<12; i++)
  {
	if (i<10) { text = '0'+i; } else { text = i; }
  	hourfield.options[i]=new Option(text, i);
  }	 
 var j = 0;  
 for (var i=0; i<60; i+=5)
  {	  
	if (i<10) { text = '0'+i; } else { text = i; }
  	minutefield.options[j]=new Option(text, i);
	j++;
  }	 
}

function populatestates()
{
var stateFIELD = document.getElementById('statesfield');
 for (var i=0; i<states.length; i++)
 { 
 	if (states[i]=="CA") { stateFIELD.options[i]=new Option(states[i], states[i]); stateFIELD.options[i].selected = true; }
	  else { 
	         stateFIELD.options[i]=new Option(states[i], states[i]);
		   }   
 }
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	var returnVal = false;
	var bracket=3
	strPhone=trim(strPhone)
	if(strPhone.indexOf("+")>1) returnVal = false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)returnVal = false
	var brchr=strPhone.indexOf("(")
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")returnVal = false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)returnVal = false; else returnVal = true;
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	returnVal = (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
  
  if ( returnVal != true )
   {
    var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
    return re.test(strPhone);
  }		
}

function CampiagnFormValidate()
{
	if(document.getElementById('sub').value=="")
	{
		alert("Please enter subject");
		return;
	}
	if(document.getElementById('dt').value=="")
	{
		alert("Please enter date");
		return
	}
	if(document.getElementById('sem').value=="")
	{
		alert("Please select some seminars");
		return
	}
	
	document.nform.submit();
}

function ReserveFormValidate()
{
  var firstname = document.getElementById('firstname');
  var lastname = document.getElementById('lastname');
  var ftype = document.getElementById('formtype');
  if(chkObject(false,'creditcardno'))
  {
	  if (document.getElementById('creditcardno').value=='')
	  {
		  alert("Please enter credit card number.");
		  return;
	  }
  }
  
  if(chkObject(false,'month'))
  {
	  if(document.getElementById("month").selectedIndex=='0')
	  {
		  alert("Please select month");
		  return;
	  }
  }
  
  if(chkObject(false,'year'))
  {
	  if(document.getElementById("year").selectedIndex=='0')
	  {
		  alert("Please select year");
		  return;
	  }
  }

  if(chkObject(false,'cvv'))
  {
	  if (document.getElementById('cvv').value=='')
	  {
		  alert("Please enter cvv number from the back of the card.");
		  return;
	  }
  }
  
  if(chkObject(false,'baddress'))
  {
	  if (document.getElementById('baddress').value=='')
	  {
		  alert("Please enter billing address.");
		  return;
	  }
  }
  
  if(chkObject(false,'nameoncard'))
  {
	  if (document.getElementById('nameoncard').value=='')
	  {
		  alert("Please enter Name on Card.");
		  return;
	  }
  }
  
  if(chkObject(false,'toc'))
  {
	  if (document.getElementById('toc').value=='')
	  {
		  alert("Please enter Type of Card.");
		  return;
	  }
  }
  
//  var reservBox = document.getElementById('MadeReservation');
//  var AddToWaitListBox = document.getElementById('WaitListChck');
//  var DidntMReservBox = document.getElementById('DidNotMakeReservation');
//  var DoNotContactBox = document.getElementById('DoNotContact');
  if(document.getElementById("State").selectedIndex=='0') { alert('Please select some state'); return;}
  if ( (firstname.value!='') && (lastname.value!=''))
    {
	  if (document.getElementById('Company').value=='') { alert('Company field is empty !'); }
	  else	
	  if (document.getElementById('Email').value=='' && document.getElementById('emailverif').value=='1') { alert('Email field is empty !'); }
	  else
	  if (document.getElementById('Address1').value=='') { alert('Address field is empty !'); }
	  else
	  if (document.getElementById('City').value=='') { alert('City field is empty !'); } 	  
	  else
	  if ((document.getElementById('PostalCode').value=='') || (!validateZIP(document.getElementById('PostalCode').value) )) { alert('Zip Code field is empty or incorrect !'); }
	  else    
	  if ( (!echeck(document.getElementById('Email').value))&&(document.getElementById('Email').value!='') ) { alert('Email field is invalid !'); }
	  else	  
	  if ( ( checkInternationalPhone( document.getElementById('PhonePrimary').value )==false )  
	       && (document.getElementById('PhonePrimary').value.toLowerCase()!='none')
		 ) 
	  { alert('Primary Phone field is incorrect or empty !'); }
	  else
	  if (    ( checkInternationalPhone( document.getElementById('PhoneCell').value )==false ) 
	       && (document.getElementById('PhoneCell').value.toLowerCase()!='none') 
		   && (document.getElementById('PhoneCell').value.toLowerCase()!='')
		   )
	  { alert('Cell Phone field is incorrect or empty !'); }
	  else  {
              	document.addReserve.submit();
	        }
    } else { alert('First Name or Last Name fields are empty !'); }	
}

function chkObject(inParent,theVal) {
if(inParent){
if (window.opener.document.getElementById(theVal) != null) {
return true;
} else {
return false;
}
}else{
if (document.getElementById(theVal) != null) {
return true;
} else {
return false;
}
}
}

function ReserveFormValidate1()
{
  var firstname = document.getElementById('firstname');
  var lastname = document.getElementById('lastname');
  var ftype = document.getElementById('formtype');
  ftype.value = '1';
  if ( (firstname.value!='') && (lastname.value!=''))
    { document.addReserve.submit(); } else { alert('Please fill the reservation fields !'); }
}

function ChangeElementValue(elemID, val)
{
  //alert(val);
  $("#"+elemID).attr('value',val);
  var el = document.getElementById(elemID);
}

function EventConfDialog()
{
  var ret = false; 
  	 
  $('#ConfEventName').val($('#Ename').val());	
  
  $('#addeventDialogConf').jqm({modal: true, overlay: 20}); 	 
   
  $("#addeventDialogConf").jqmShow();
  
  $('#CancelAddDialog').click( function() { ret = false; $('#SubmitButton').attr('disabled', false); });  
  $('#OkAddDialog').click( function() 
      {       	 
		 document.AddEvent.submit(); 
	  });    								 	
}

function ValidateEventForm()
{  
	var returnVal = false; 
	var Ename = $("#Ename").val();
	var Spname = $("#Spname").val();
	var Address = $("#Address").val();
	var maxattend = $("#maxattend").val();
	var MaxPerParty = $("#MaxPerParty").val();
	var seats = $("#seats").val();
	var maxpieces = $("#maxpieces").val();
	var zip = $("#zip").val();   
		
	if ( Ename=='' ) { alert("Event Name field is empty !"); } else
	{
		if ( (Spname=='')) { alert("Partner Name field is empty !"); } else 
	    {
			if (Address=='') { alert("Address field is empty !"); } else
			{   
		      if ( !validateZIP(zip) ) { alert('Zip Code field is empty or incorrect !'); }		
		      else
		      {
			  if ( (isDate($('#date').val(), 'mm/dd/yy')==false) && (isDate($('#date').val(), 'mm/dd/yyyy')==false) ) 
			      { 
				     alert('Invalid Seminar Date !'); 
				  } else
			  	if (maxattend=='') { alert("Max Attendees field is empty ! "); } else 
					{ if (!IsNumeric(maxattend)) { alert("Incorrect data in Max Attendees field ! "); } else
					
						if (MaxPerParty=='') { alert("Max Per Party field is empty !"); } else
						{ if (!IsNumeric(MaxPerParty)) { alert("Incorrect data in Max Per Party field ! "); } else
						
							if (seats=='') { alert("Seats field is empty !"); } else 
							{ if (!IsNumeric(seats)) { alert("Incorrect data in Seats field ! "); } else
							
							  if (maxpieces=='') { alert("Mail Pieces field is empty !"); } else 
							    { 
								  if (!IsNumeric(maxpieces)) { alert("Incorrect data in Mail Pieces field ! "); } else
							        if ( (isDate($('#mdate').val(), 'mm/dd/yy')==false) && (isDate($('#mdate').val(), 'mm/dd/yyyy')==false) )
									 { alert('Invalid Mailing Date !'); } else returnVal = true;
								} 
							}
						}
					}
			   }
			}
		}
	}
	if (returnVal)	
	{ 
	    if($('#formCommand').val()!='edit')
		{
		$.get('ajax.php?cmd=CheckEventName&e='+$('#Ename').val(), 
			  function(data)
			    { 	
				  if(data=='1') 
				   {
				      returnVal = false; 
					  $('#Ename').attr('size','18');
					  $('#duplictEvent').remove();
		     		  $('#Ename').after("<span id='duplictEvent' style='font-size: 10px; color: red'>This Event has been already added !</span>");				   	 
					  $('#SubmitButton').attr('disabled', false);
					  return returnVal;
				    };
				  if(data=='0') {
				  	             //if (returnVal) returnVal = EventConfDialog();
	                             return returnVal;
				            };
				});
		} return returnVal;
		
	}
}

function ValidateAddWalkIn()
{                 //$('#').val();
  var firstname = $('#txtFirstName').val();
  var lastname = $('#txtLastName').val();
  var address1 = $('#Address1').val();
  var address2 = $('#Address2').val();
  var city = $('#txtCity').val();
  var state = $('#State').val();
  var zip = $('#PostalCode').val();
  var p1 = $('#PhonePrimary').val();
  var p2 = $('#PhoneCell').val();
  var p3 = $('#PhoneSecondary').val();
  var p4 = $('#PhoneFax').val();
  var email = $('#Email').val();
  var returnVal = false;
  
  if (firstname=='') { alert('First Name field is empty !'); }
  else
  if (lastname=='') { alert('Last Name field is empty !'); }
  else
  if (address1=='') { alert('Address1 field is empty !'); } 
  else
  if (address2=='') { alert('Address2 field is empty !'); }
  else
  if (city=='') { alert('City field is empty !'); }
  else
  if (state=='0') { alert('State field is empty !'); }   
  else
  if (!validateZIP(zip)) { alert('Zip field is empty or incorrect !'); } 
  else
  if ((!checkInternationalPhone(p1)) && (p1.toLowerCase()!='none')) { alert('Primary Phone field is empty or incorrect !'); }  
  else
  if ((!checkInternationalPhone(p2)) && (p2.toLowerCase()!='none')) { alert('Cell Phone field is empty or incorrect !'); }
  else
  if ((!checkInternationalPhone(p3)) && (p3.toLowerCase()!='none')) { alert('Secondary Phone field is empty or incorrect !'); }
  else
  if ((!checkInternationalPhone(p4)) && (p4.toLowerCase()!='none')) { alert('Fax Number field is empty or incorrect !'); }
  else
  if (!echeck(email)) { alert('Invalid Email ! '); }
  else returnVal = true;
  
  return returnVal;
}

// Add Event functions
function SelectedRow(elem)
{
  $(elem).attr('bgcolor','#3FA391');
}
function UnelectedRow(elem)
{
  $(elem).attr('bgcolor','');
}

function ValidatePassword()
{
  var pass1 = document.getElementById('idPassword');
  var pass2 = document.getElementById('idPassword2');
  if (pass1.value!='') 
   {
     if (pass1.value==pass2.value) document.updPass.submit(); else alert('Confirmed password doesn\'t match !');   
   }
}

function MsgOkCancel()
{
	var fRet;
	fRet = confirm('Are you sure ?');
	return fRet;
} 

function GoHome()
{
  window.location="index.php";
}
function UpdateTab(idu)
{	
   var eimg = document.getElementById(idu);	 
   $.get("ajax.php?src="+eimg.src+"&id="+eimg.id+'&cmd=attend', 
                      function(data) { 					  
					                    eimg.src = data;  
								     });		
}
function UpdateTab_DNMail(idu)
{	
   var eimg = document.getElementById(idu);	 
   $.get("ajax.php?src="+eimg.src+"&id="+eimg.id+"&cmd=dnmail", function(data) { eimg.src = data; });		
}
function WaitListUpdate(id, resp)
{
  var btn = document.getElementById(id);
  if (btn.value=='Add to Wait List') 
    {
       $.get("ajax.php?cmd=addtowaitlist&resp="+resp, function(data) { btn.value = data; });
       $('#formtype').attr('value','1');
    }
  if (btn.value=='Remove From Wait List') 
    {
       $.get("ajax.php?cmd=removefromwaitlist&resp="+resp, function(data) { btn.value = data; });
       $('#formtype').attr('value','0');
    }	 
}
function StatusUpdate(id, resp)
{
  var btn = document.getElementById(id);
  if (btn.value=='Cancel Reservation') 
    {
       $.get("ajax.php?cmd=cancelreserv&resp="+resp, function(data) { btn.value = data; });
    }
  if (btn.value=='Un-Cancel Reservation') 
    {
       $.get("ajax.php?cmd=uncancelreserv&resp="+resp, function(data) { btn.value = data; });
    }	 
}
function ConvertToPrimary(resp)
{
   $.get("ajax.php?cmd=converttoprimary&resp="+resp, function(data)	{ window.location.reload( false );});
}

function UpdateDeal(id, col, idul, sid)
{
   var eid = '#'+id;
   var val = $("#"+sid).val();
   var query = "ajax.php?cmd=update_deal&col="+col+"&val="+val+"&id="+idul;
   $.get(query, function(data) { 
                                 $(eid).attr("background", data);
                                 if (data!="") $("#"+sid).attr("value",'0'); else $("#"+sid).attr("value","1");	   
							   });
   return true;    	
}

function NewDealValidate()
{ 
 if ( $("#DealName1").val()!='') document.NewDealForm.submit(); else alert('Empty Field !')
}

function Fct(p, mDiv, sDiv)
   {
     var pw = $("#"+mDiv).width()-2;
	 var nw = (pw*p) / 100;
	 $("#"+sDiv).css("width",nw);
	 return true;
   }

function DelUser(id)
{  
	$('#dialog').jqmShow(); 
    $('#LastConfirmButton1').click( function() { $.get("ajax.php?cmd=deluser&id="+id, function(data) { window.location.reload( false );	}); }  );
//if (MsgOkCancel()==true)
//      $.get("ajax.php?cmd=deluser&id="+id, function(data) { 
//	  	                                                     window.location.reload( false );
//														   });	
}

function DeleteBlock(id)
{
	$('#dialog').jqmShow(); 
	$('#LastConfirmButton1').click( function() { 
									                 window.location.href='index.php?cmd=delete_block&b='+id; 
									           }  );
}

function DeleteEvent(id)
{
	$('#dialog').jqmShow();
	$('#LastConfirmButton1').click( function() {
									                 window.location.href='index.php?cmd=delete_event&event='+id;
									           }  );
}

function DeleteResponder(respid, evid)
{
	$('#dialog').jqmShow(); 
	$('#LastConfirmButton1').click( function() { 
									                 window.location.href='index.php?cmd=delresp&id='+respid+'&event='+evid;
									           }  );	
}

function DeleteDeal(id)
{
	$('#dialog').jqmShow(); 
	$('#LastConfirmButton1').click( function() { 
									                 window.location.href='index.php?cmd=deldeal&id='+id;
									           }  );	
}

function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep)
{
  var targetDateField = document.getElementsByName(dateFieldName).item(0);
   // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
 
  // if a date separator character was given, update the dateSeparator variable
  //if (dtSep)
  //  dateSeparator = dtSep;
  //else
    dateSeparator = '/'; //defaultDateSeparator;
 
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
  dateFormat = 'MDY'  //defaultDateFormat;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
 
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }
 
  drawDatePicker(targetDateField, x, y);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y)
{
  var dt = getFieldDate(targetDateField.value);

  if (!document.getElementById(datePickerDivID)) {
  var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
 
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;  
  // draw the datepicker table
  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateFieldName, year, month, day)
{
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
 
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
 
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleTD'>";
  var TD_buttons = "<td class='dpButtonTD'>";
  var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";
 
  // start generating the code for the calendar table
  var html = TABLE;
 
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
  html += xTR;
 
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
 
  // now we'll start populating the table with days of the month
  html += TR;
 
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;
 
  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
    
    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
 
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
 
  // add a button to allow the user to easily return to today, or close the calendar
  var today = new Date();
  var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
  html += TR_todaybutton + TD_todaybutton;
  html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> ";
  html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
  html += xTD + xTR;
 
  // and finally, close the table
  html += xTABLE;
 
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth () + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
 
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
}


/**
Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
 
  dateFormat = "mdy";
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal = new Date(getDateFromFormat(dateString,'MM/dd/yy'));
  return dateVal;
}

/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
 
  return dArray;
}

function updateDateField(dateFieldName, dateString)
{
  var dateVal = new Date(getDateFromFormat(dateString,'MM/dd/yyyy'));
  	 
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
  if (dateString)
    targetDateField.value = formatDate(dateVal, 'MM/dd/yy');
 
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  targetDateField.focus();
 
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);
}

function adjustiFrame(pickerDiv, iFrameDiv)
{
  // we know that Opera doesn't like something about this, so if we
  // think we're using Opera, don't even try
  var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  if (is_opera) return;
  
  // put a try/catch block around the whole thing, just in case
  try {
    if (!document.getElementById(iFrameDivID)) {
      // don't use innerHTML to update the body, because it can cause global variables
      // that are currently pointing to objects on the page to have bad references
      //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
      var newNode = document.createElement("iFrame");
      newNode.setAttribute("id", iFrameDivID);
      newNode.setAttribute("src", "javascript:false;");
      newNode.setAttribute("scrolling", "no");
      newNode.setAttribute ("frameborder", "0");
      document.body.appendChild(newNode);
    }
    
    if (!pickerDiv)
      pickerDiv = document.getElementById(datePickerDivID);
    if (!iFrameDiv)
      iFrameDiv = document.getElementById(iFrameDivID);
    
    try {
      iFrameDiv.style.position = "absolute";
      iFrameDiv.style.width = pickerDiv.offsetWidth;
      iFrameDiv.style.height = pickerDiv.offsetHeight ;
      iFrameDiv.style.top = pickerDiv.style.top;
      iFrameDiv.style.left = pickerDiv.style.left;
      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
      iFrameDiv.style.visibility = pickerDiv.style.visibility ;
      iFrameDiv.style.display = pickerDiv.style.display;
    } catch(e) {
    }
 
  } catch (ee) {
  }
 
}

function SentMailUpdate(id, elementID)
{
  var el = document.getElementById(elementID);
  var val = $("#"+elementID).attr('src');
  if (val=='images/mail_sent.png') 
    {	 
       $.get("ajax.php?cmd=sentmail&resp="+id+"&val=0", function(data) { el.src = data; });
    }
      else 
    {
       $.get("ajax.php?cmd=sentmail&resp="+id+"&val=1", function(data) { el.src = data; });
    }	
}
// == some math functions 
function roundToPrecision(inputNum, desiredPrecision){
 var precisionGuide = Math.pow(10, desiredPrecision);
 return( Math.round(inputNum * precisionGuide) / precisionGuide );
}
//converts the input number into a string and adds zeroes
//until the desired precision is reached and then
//returns the new string
function addZeroesToPrecision(inputNum, desiredPrecision){
 var numString = inputNum + "";
 var afterDecimalString = numString.substring(numString.search(/\./) + 1);
 while (afterDecimalString.length < desiredPrecision) {
   afterDecimalString += "0";
   numString += "0";
 }
 return(numString);
}

function ECalc()
{
  var reservations = $("#signedresponders").attr('value');
  var seats = $("#seats").attr('value');
  var fillrate = roundToPrecision((reservations*100)/seats, 2); 
  var mailingcost = $("#mailingcost").attr('value');  
  var cpl = mailingcost / reservations;
  fillrate = addZeroesToPrecision(fillrate, 2);
  cpl = roundToPrecision(cpl, 2); 
  cpl = addZeroesToPrecision(cpl, 2);
  if (cpl=='NaN') cpl = '0';
  if (fillrate=='NaN') fillrate = '0';  
  if (cpl=='Infinity') cpl = '0';
  if (fillrate=='Infinity') fillrate = '0'; 
      
  $("#costperlead").attr('value', cpl);  
  $("#fillrate").attr('value', fillrate);  
}

function ValidateAddBlockForm()
{
  var returnVal = false;
  if (document.getElementById('BlockName').value != '' )  returnVal = true; else { alert('Empty field not allowed !'); }
  return returnVal;
}


function ValidateAddOperator()
{
	var returnVal = false;
	var pass = $('#pass').val();
	if ($('#firstname').val()=='') { alert('First Name field is empty !'); }
	else
	if ($('#lastname').val()=='') { alert('Last Name field is empty !'); }
	else 	 
	if ( echeck($('#email').val())==false ) { alert('Invalid Email address !'); }
	else 
	if ( ($('#pass').val() == $('#pass1').val())&&( pass.length > 0 ) )
	 {
	    if ($('#pass').val()='') alert('Password field is empty !'); 
		 else 
		   { 
		     returnVal = true;	
		   } 	
	 } else { alert('Password fields does not match or empty !'); }
	return returnVal;
}

function ValidateNameTags()
{
	var returnVal = true; 
	
	if (!IsNumeric($('#leftMargin').val())) { alert('Left Margin field is incorrect !'); returnVal = false;  } 
	else
	if (!IsNumeric($('#rightMargin').val())) { alert('Right Margin field is incorrect !'); returnVal = false;  }    
	else 
	if (!IsNumeric($('#topMargin').val())) { alert('Top Margin field is incorrect !'); returnVal = false;  }
	else 
	if (!IsNumeric($('#bwidth').val())) { alert('Width field is incorrect !'); returnVal = false;  }	
	else 
	if (!IsNumeric($('#bheight').val())) { alert('Height field is incorrect !'); returnVal = false;  }	
	else 
	if (!IsNumeric($('#nfontsize').val())) { alert('Name Size field is incorrect !'); returnVal = false;  }		
	else 
	if (!IsNumeric($('#tfontsize').val())) { alert('Title Size field is incorrect !'); returnVal = false;  }	
    else 
      returnVal = true;
	
	return returnVal;
}


function MoveToArchive()
{
	$('#A1AlertText').text('Are you sure that you want to archive this item ?');
	$('#A1dialog').jqm({modal: true, trigger: 'a.showDialog'});  
	$('#Adialog1').jqm({modal: true, trigger: 'a.showDialog'});	
	$('#A1dialog').jqmShow(); 
    
	$('#ALastConfirmButton1').click( function() {
									                $.get('ajax.php?cmd=move_file&f='+$('#files').val(), 
					           							function(data){ 
							   	                				           window.location = "index.php?page=import&p=filem&cmd=view&m=1"; 
											  			              });
									           }  );

}

function MoveToImports()
{
	$('#A1AlertText').text('Are you sure that you want to restore this item ?');
	$('#A1dialog').jqm({modal: true, trigger: 'a.showDialog'});  
	$('#Adialog1').jqm({modal: true, trigger: 'a.showDialog'});	
	$('#A1dialog').jqmShow(); 
    
	$('#ALastConfirmButton1').click( function() {
									                $.get('ajax.php?cmd=move_filetoimports&f='+$('#archivedfiles').val(), 
					           							function(data){ 
							   	                				           window.location = "index.php?page=import&p=filem&cmd=view&m=1";
											  			              });
									           }  );
}

function DeleteArch(fname)
{
	$('#dialog').jqm({modal: true, trigger: 'a.showDialog'});  
	$('#dialog1').jqm({modal: true, trigger: 'a.showDialog'});	
	
    $('#dialog').jqmShow();
	$('#LastConfirmButton1').click( function() {	
	                       $.get("ajax.php?cmd=delete_archivefile&f="+fname, function(data) { window.location.reload( false );  });	
	                                            });
}

function AddToArchive(id)
{
    $('#AlertText').text('Are you sure that you want to archive this item ?');
    $('#dialog').jqmShow();
	$('#LastConfirmButton1').click( function() {
									                  window.location = "index.php?cmd=add_arch&event="+id;
									                  
 								               });
    //$('#AlertText').text('Are you sure that you want to delete this item ?');
}

function GetPersonDetails(typ)
{
	if (typ==1) 
  	  {
			$.get('ajax.php?cmd=getpdetails&f='+$('#firstname').val()+'&l='+$('#lastname').val(), 
			function(data){ 
				            
					        if (data=='') {  $('#GetInfoLablel').text('Name not found.'); }
					          else  
					           { 	
							   	 infos = data.split(" , ");
								 $('#Address1').attr('value', infos[5]);
								 $('#City').attr('value', infos[6]);
								 $("#State").selectOptions(infos[7]);							   							 
								 $('#PostalCode').attr('value', infos[8]);
								 $('#GetInfoLablel1').text('');
							   }
			              });
	  }			  
	if (typ==2) 
  	  {
			$.get('ajax.php?cmd=getAdetails&f='+$('#Address1').val(), 
			function(data){ 				            
					        if (data=='') { $('#GetInfoLablel1').text('Name not found.'); }
					          else  
					           { 					           	 
							   	 infos = data.split(" , ");
							   	 alert(infos);
							   	 $('#firstname').attr('value', infos[2]);
							   	 $('#lastname').attr('value', infos[4]);
								 $('#City').attr('value', infos[6]);
								 $("#State").selectOptions(infos[7]);							   							 
								 $('#PostalCode').attr('value', infos[8]);
								 $('#GetInfoLablel1').text('');
							   }
			              });  	  	
	  }		  				    	
}

function EventNameVerification()
{   
	$.get('ajax.php?cmd=CheckEventName&e='+$('#Ename').val(), 
		function(data){  
			             if (data == '1') 
						   { 
						   	 $('#Ename').attr('size','18');
							 $('#Ename').after("<span id='duplictEvent' style='font-size: 10px; color: red'>This Event has been already added !</span>");				   	 
						   }						   
						      else 
						   { 
						   	 $('#duplictEvent').text('');
						   	 $('#duplictEvent').remove();
							 $('#Ename').attr('size','50');
						   } 
		              }); 	
}


function RecoveryMailValidate()
{
  var returnVal = false;
  if ( echeck($('#email').val())==false ) { returnVal = false; alert('Invalid email address !'); } else returnVal = true;
  return returnVal;
}

function ChangeStatus(id, val)
{
	$.get('ajax.php?cmd=status&ev='+id+'&val='+val, 
		function(data){ 
			             if (data!='')
						   {  					   	  
						   	  $("#status"+id).attr('src',data);
						   	  if (val==1) 
								  {
								  	$("#status"+id).attr('onclick','ChangeStatus('+id+', 0)');									
									$("#tr"+id).children().css('background-color','red');
									//$("#td"+id).children(":nth-child(1)").css('background-color','');
								  	$("#status"+id).attr('title','Activate Event');
								  }
								  else 
								  {
								  	$("#status"+id).attr('onclick','ChangeStatus('+id+', 1)');
								  	$("#tr"+id).children().css('background-color','');								  	
								  	$("#status"+id).attr('title','Cancel Event');
								  }					   	  
						   }    	
		              }); 	
}

var n;
var p;
var p1;

function ValidatePhone(element)
{
p=p1.value
if(p.length==3){
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	element.value="";
	element.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		element.value="";
		element.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	element.value="";
	pp="("+p13+")"+p14+p15;
	element.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);

	pp=p19+p17+"-"+p18;
	element.value="";
	element.value=pp;
	}
}
 setTimeout(ValidatePhone,100)
}

function testphone(obj1)
	{
		p=obj1.value
		p=p.replace("(","")
		p=p.replace(")","")
		p=p.replace("-","")
		p=p.replace("-","")
		if (isNaN(p)==true){
		alert("Check phone");
		return false;
	}
}
function getIt(m)
{
	n=m.name;
	p1=m
	ValidatePhone(m)
}

function ResetAddFormFields()
{					
	var today = new Date();  
	$('#BlockName').val('');
	$('#BlockCity').val('');
	$('#BlockVenue').val('');
	$('#BlockDate').val(formatDate(today,'M/dd/yy'));
	$('#BlockNotes').val('');
	$('#BlockWait').hide();   
	$('#BlockWait').text('Please wait...');
	$('#BlockWait').css('color','black');
}

function AddBlockForm()
{
	$('#BlockTable').show();  
	$('#addBlock').jqmShow(); 
	$('#aBCancelBtn').click( function() { 
									         //window.location.href='index.php?cmd=delete_block&b='+id; 
									     } 
								   );
	$('#addBlockBtn').click( function() { 
									          
									     } 
								   );								   
}
function OpenEditBlockForm(id)
{
	$('#BlockTable').hide();
    $('#BlockWait').text('Please wait...');
    $('#BlockWait').css('color','black');
	$('#BlockWait').show();  	
	$('#addBlock').jqmShow();
	
	
	$.get('ajax.php?cmd=getBlockInfo&id='+id, 
		function(data){ 
			             if (data!='')
						   {  					   	  
							 if (data=='error') 
							     { 
							        $('#BlockWait').text('An error occurred, please try again !');
							        $('#BlockWait').css('color','red');																     	
							     }
							  else
							  {
							  	$('#BlockTable').remove();
							  	$('#addBlock').append(data);
							  	$('#aBCancelBtn').click( function() { 
							  		                                  ResetAddFormFields();
							  		                                  $('#addBlockBtn').attr("onclick", "$('addBlockBtn').addClass('jqmClose');"+
																		                                "$('#BlockTable').hide(); $('#BlockWait').show();"+     
											                                                            "AjaxAddBlock('addBlock');" );											                                                            
                                         							  $('#addBlock').jqmHide();	  		
                                                                      $('#addBlockBtn').attr('value','Add'); 																			  
									                                });
							  	$('#addBlock').jqm( { modal: true, onHide: function(h) { h.o.remove(); h.w.fadeOut(688);   } } );
							  	$('#BlockWait').hide();	
                                						
							  }   							     							   	  
						   }    	
		              }); 
}

function EditUser(id)
{
  $('#EditUserForm').jqmShow();
  $.get('ajax.php?cmd=getuserdetails&id='+id, 
		function(data){
		                 $('#EditUserFormAjax').remove();
                         $('#EditUserForm').append(data);
						 $('#EditUserBtn').click( function() { 
						           $('#EditUserForm').jqmHide(); 	
								   $(this).remove();								   
								});
						});                
}

function ChangeEventBlock(id)
{
	$('#BlockTable').hide();	
	$('#ChangeBlockDialogForm').jqmShow(); 
	$('#OkChangeDialog').click( function() 
	                                    { 
									       $.post('ajax.php', 
										                     { 
										                       cmd : "changeEventBlock", 
										                       eventId : id, 
															   block: $('#blocksCombo1').val() },  
										   function(data){ 
                                                             window.location.href='index.php?page=blocks&cmd=viewblocks&gr=blocks'; 
											              }); 
									    } 
								   );
}

function AjaxAddBlock(funct, id)
{	
	//  funct 
	//  -- addBlock - Add a new Block
	//  -- editBlock - Eddit a block    
	$.post('ajax.php', { cmd : funct,
	                     bId : id,   
	                     name : $('#BlockName').val(),
						 city : $('#BlockCity').val(),
						 venue : $('#BlockVenue').val(),
						 BlockDate : $('#BlockDate').val(),
						 notes : $('#BlockNotes').val() },  
		function(data){ 
			            if (data=='') 
						    { 
							   ResetAddFormFields();							   	 
						       $('#addBlock').jqmHide();							   
						       window.location.href='index.php?page=blocks&cmd=viewblocks&gr=blocks';
							}  
							  else
							{
							  $('#BlockWait').text('An error occurred, please try again !');
							  $('#BlockWait').css('color','red');
							  $('#BlockTable').show();
							  $('#addBlock').jqmShow();  	
							}    	
		              }); 	
}

function ShowBlockSearchForm()
{
  $('#SearchByWeek').val('');	
  $('#SearchBlockForms').jqmShow();	
}

function ClearSearchBlockForm()
{
   $('#SearchByName').val('');	
   $('#SearchByCity').val('');
   $('#SearchByVenue').val('');
   $('#SearchByWeek').val('');
   $('#SearchByNotes').val('');
}

function URLEncode(clearString) 
  {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9_.]*)/;
	  while (x < clearString.length) {
	    var match = regex.exec(clearString.substr(x));
	    if (match != null && match.length > 1 && match[1] != '') {
	    	output += match[1];
	      x += match[1].length;
	    } else {
	      if (clearString[x] == ' ')
	        output += '+';
	      else {
	        var charCode = clearString.charCodeAt(x);
	        var hexVal = charCode.toString(16);
	        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
	      }
	      x++;
	    }
	  }
	  return output;
 }
 
function SearchBlock()
{
  var query = ""; 
  var datString;
  datString = $('#SearchByWeek').val();
  var searchVal = $('#SearchByName').val();

  if ($('#SearchByName').val()!='') query = "name like $%"+searchVal+"%$";
  
  if ($('#SearchByCity').val()!='') 
    {  
	   if (query=='') query = "city like \'%"+$('#SearchByCity').val()+"%\'";
	                  else query = query + " or city like \'%"+escape($('#SearchByCity').val())+"%\'";
	} 
  if ($('#SearchByVenue').val()!='') 
    {
      if (query=='') query = "venue like \'%"+$('#SearchByVenue').val()+"%\'"; 
	    query = query + " or venue like \'%"+$('#SearchByVenue').val()+"%\'";
    }		  
 
  if ($('#SearchByNotes').val()!='') 
    { 
      if (query=='') query = "notes like \'%"+$('#SearchByNotes').val()+"%\'";
    	else query = query + " or notes like \'%"+$('#SearchByNotes').val()+"%\'";
	}	   
	
  window.location.href='index.php?page=blocks&cmd=viewblocks&search=1&searchby='+URLEncode(query);
}

function GetActivity(id)
{  	 
  $('#ActivityForm').jqmShow();
  $('#ClearActivityBtn').click(function(){  ClearActivity(id); } );
  $.get('ajax.php?cmd=getUserActivity&id='+id, 
		function(data){ 
			            $('#ActivityTable').remove(); 
			            $('#NoActivity').remove();			            
                        $('#ActivityForm').prepend(data);  	
                        $('#OkActivityDialog').click( function() 
	                                                  { 
	                                                  	
													  } 
												   );
		              });	
}

function EventsTableOver(id)
{  
  $('#tr'+id).css('background-color','#CCFFCC');	
  $('#td'+id).css('background-color','#CCFFCC');
}

function EventsTableOut(id)
{  
  $('#tr'+id).css('background-color','');	
  $('#td'+id).css('background-color','#B9D0CC');	
}

function DeleteBlock(id)
{
	$('#dialog').jqmShow();
	$('#LastConfirmButton1').click( function() {
												 window.location.href='index.php?cmd=delete_block&block='+id;
									           }  );
}

function SearchDialogShow()
{	    
  $('#SearchDialogBox').jqmShow();	
}

function SearchButtonOnClick()
{	
  var term = $('#SearchTerm').val();
  $('#SearchDialogResult').jqmShow();	
  $.get('ajax.php?cmd=search&term='+term, 
									      function(data){ 
									      	              $('#SearchDialogResult').prepend(data);
										                });	 	
}
function ClearActivity(user)
{	
  
  $.get('ajax.php?cmd=clearactivity&user='+user, 
									      function(data){  
									                       $('#ClearActivityBtn').unbind(); 								                       
									      	               $('#ActivityForm').jqmHide(); 
									      	               $('#ActivityTable').remove();
										                });	 	
}

function ChangeRights(user, right, val)
{
  $.get('ajax.php?cmd=rights&user='+user+'&right='+right+'&val='+val, 
									      function(data){ 
									      	               
										                });	  	
}

function PreviewDB()
{ 
  var fl = $('#backuplist :selected').val();
  if (fl!='') { window.location.href = 'http://noel-murphy-financial.com/index.php?cmd=backup_prev&fl='+fl; }
}
