/* 
 * Global javascript methods
 *
 * Author : Chris Blown, Hinterlands
 *
 * Copyright 2003 - Hinterlands Consultancy  http://www.hinterlands.com.au
 *
 */
 
/* Global Params */

createLocation = "/cgi-bin/member.pl/login";
sendLocation   = "/default.jsp";
proofLocation  = "/proof/default.asp"; 
 
/*  
 *  In Future
 *  
 *  Checks to see if the date set is in the future 
 *
 ** Date formats are VERY important  
 */

function inFuture( id )
{
   var now=new Date();
   
   var day   = now.getDate();
   var month = now.getMonth()+1;
   var year  = now.getFullYear();
   
   var today = day+"/"+month+"/"+year;
   
   //alert(today);
   
   return ( compareDates( today, "d/M/yyyy", document.getElementById( id ).value, date_style ) );
}

/*  
 *  jtd Check Form
 *  
 *  Validates the form checking for required fields for job ticket details *  
 */

function checkForm()
{
   gadgets = new Array('bookingNumber',
                       'dPubdate');
   
   messages = new Array('Please enter a booking number, before proceeding..',
                        'Please first enter an appearance date before proceeding..');
   
   for( var i=0 ; i < gadgets.length ; i++ )
   {                  
       if ( document.getElementById(gadgets[i]).value == "" )
       {
           alert(messages[i]);
           return false;
       }
   }
   if ( inFuture('dPubdate') )
   {
      alert("Appearance date cannot be in the past.");
      return false;
   }

    document.getElementById('smsNumberText').value = document.getElementById('smsNumberText').value.replace(/\s/g, "");
    sendSMSRadio = document.forms['postJobTicket'].elements['sendSMS'];
    if(sendSMSRadio[1].checked && !(/^[0-9]+$/.test(document.getElementById('smsNumberText').value))) {	   
 	   alert("You have ticked the SMS service. Please type in mobile number for SMS service (numbers only).");
 	   return false;
    }
    if(!sendSMSRadio[1].checked && document.getElementById('smsNumberText').value != '') {
 	   alert("You have typed in the mobile number. Please tick 'yes' for SMS service.");
 	   return false;
    }
    
    return true;

}

/* Cookie Functions */

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


      /* JS Helper Functions - C.Blown May 2006 */

      var statusChangeText = "";
      var memberName = "unknown";
      var javaNum = "54363";

      function changeStatus(JobStatus,template) {
         document.getElementById("txtJobStatus").value = JobStatus;
         document.getElementById("txtTemplate").value = template;
         var time=new Date();
         var day =time.getDate();
         var month = time.getMonth() + 1;
         var year=time.getFullYear() ;
         var hours=time.getHours();
         var minutes=time.getMinutes();
         statusChangeText = "<strong>"+ memberName +"</strong> changed job status to " + JobStatus + " at " + hours + ":" + minutes + " " + day + "-" + month + "-" + year + "<br />";
         addComment();
      }

      function formSubmit() {
         document.getElementById('txtJobLog').value = document.getElementById('txtJobLog').value + statusChangeText;
         document.frmViewJob.submit();
         return true;
      }

      function validateCode() {
         if (document.getElementById('txtCode').value == javaNum) {
            formSubmit();
         } else {
            alert("You must enter the code as it appears above the text box.");
            return false;
         }
      }

      function addComment()
      {
         var commentBox = document.getElementById('commentBox');
         var commentLog = document.getElementById('commentLog');

         if ( commentBox.value != '' ) {

            var time=new Date();
            var day =time.getDate();
            var month = time.getMonth() + 1;
            var year=time.getFullYear();
            var hours=time.getHours();
            var minutes=time.getMinutes();
            var logEntry = "<strong> At "+ hours + ":" + minutes + " " + day + "-" + month + "-" + year + " " + memberName + " said : </strong><pre>"+commentBox.value+" </pre><hr/>";

            commentLog.value += logEntry;
         }
      }

	  function shrinkComments(fieldId, shrinkButtonId, enlargeButtonId)  {
		  document.getElementById(fieldId).className = 'field logScrollBox';
		  document.getElementById(shrinkButtonId).style.display = 'none';
		  document.getElementById(enlargeButtonId).style.display = 'block';
	  }
	  function enlargeComments(fieldId, shrinkButtonId, enlargeButtonId) {
		  document.getElementById(fieldId).className = 'field logScrollBoxLarge';
		  document.getElementById(shrinkButtonId).style.display = 'block';
		  document.getElementById(enlargeButtonId).style.display = 'none';
	  }













