//-------------XML HTTP REQUEST----------------------------

var req;
var oldData;
var doesNotSupport = true;
var messagediv;
function do_task(val,url,thediv)
{
   //url = " ";
     messagediv=thediv;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest;
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (req) {
       req.open("POST",url, true);
       req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');


        req.send(val);
        req.onreadystatechange = processReqChange;
        //alert(req.readyState);
        if (req.readyState == 4){
        if (req.status == 200){
             //alert(req.responseText);
             document.getElementById(thediv).innerHTML=req.responseText;
           }
        }
    } else {
       alert("Please use latest version of the current browser to function properly");
       doesNotSupport = false;
    }
}
function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
             //alert(req.responseText);
             document.getElementById(messagediv).innerHTML=req.responseText;
           }
        }
    }


function collectdata(frm,thediv,postvalues)
{
    //var postvalues='sendmail=1&subject='+frm.subject.value+'&content='+frm.content.value+'&toaddress='+frm.toaddress.value;
    //alert(postvalues);
    url="do_task.php";
    do_task(postvalues,url,thediv);
}

//-----------------------------------------



url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

var ajax_get_error = false;

function createCookie(name,value,days)
{
  //alert(name);
 if (days)
 {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 }
 else var expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}

function ajax_do (url) {
  
	// Does URL begin with http? 	
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
    
	//return true;
}

function ajax_get (url, el) {
	// Has element been passed as object or id-string?
	if (typeof(el) == 'string') {
		el = document.getElementById(el);
	}

	// Valid el?
	if (el == null) { return false; }

	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}

	// Create getfile URL
	getfile_url = base_url + 'getfile.php?url=' + escape(url) + '&el=' + escape(el.id);

	// Do Ajax
	ajax_do (getfile_url);

	return true;
}






/**
This is a JavaScript library that will allow you to easily add some basic DHTML
drop-down datepicker functionality to your forms and pages. This script is not as
full-featured as others you may find on the Internet, but it's free, it's easy to
understand, and it's easy to change.

You'll also want to include a stylesheet that makes the datepicker elements
look nice. Example styles have been included directly in this HTML page for ease
of reference.

I've tested this lightly with Internet Explorer 6 and Mozilla Firefox. I have no idea
how compatible it is with other browsers. You are free to use this in any way you'd
like, with no charge or obligation.

version 1.4
December 20, 2004
Julian Robichaux -- http://www.nsftools.com

HISTORY
--  version 1.0 (Sept. 4, 2004):
Initial release.

--  version 1.1 (Sept. 5, 2004):
Added capability to define the date format to be used, either globally (using the
defaultDateSeparator and defaultDateFormat variables) or when the displayDatePicker
function is called.

--  version 1.2 (Sept. 7, 2004):
Fixed problem where datepicker x-y coordinates weren't right inside of a table.
Fixed problem where datepicker wouldn't display over selection lists on a page.
Added a call to the datePickerClosed function (if one exists) after the datepicker
is closed, to allow the developer to add their own custom validation after a date
has been chosen. For this to work, you must have a function called datePickerClosed
somewhere on the page, that accepts a field object as a parameter. See the
example in the comments of the updateDateField function for more details.

--  version 1.3 (Sept. 9, 2004)
Fixed problem where adding the <div> and <iFrame> used for displaying the datepicker
was causing problems on IE 6 with global variables that had handles to objects on
the page (I fixed the problem by adding the elements using document.createElement()
and document.body.appendChild() instead of document.body.innerHTML += ...).

--  version 1.4 (Dec. 20, 2004)
Added "targetDateField.focus();" to the updateDateField function (as suggested
by Alan Lepofsky) to avoid a situation where the cursor focus is at the top of the
form after a date has been picked. Added "padding: 0px;" to the dpButton CSS
style, to keep the table from being so wide when displayed in Firefox.
*/

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');

// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
// and defaultDateFormat variables either here or on your HTML page.
var defaultDateSeparator = "/";		// common values would be "/" or "."
var defaultDateFormat = "mdy"	// valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/**
This is the main function you'll call from the onClick event of a button.
Normally, you'll have something like this on your HTML page:

Start Date: <input name="StartDate">
<input type=button value="select" onclick="displayDatePicker('StartDate');">

That will cause the datepicker to be displayed beneath the StartDate field and
any date that is chosen will update the value of that field. If you'd rather have the
datepicker display beneath the button that was clicked, you can code the button
like this:

<input type=button value="select" onclick="displayDatePicker('StartDate', this);">

So, pretty much, the first argument (dateFieldName) is a string representing the
name of the field that will be modified if the user picks a date, and the second
argument (displayBelowThisObject) is optional and represents an actual node
on the HTML document that the datepicker should be displayed below.

In version 1.1 of this code, the dtFormat and dtSep variables were added, allowing
you to use a specific date format or date separator for a given call to this function.
Normally, you'll just want to set these defaults globally with the defaultDateSeparator
and defaultDateFormat variables, but it doesn't hurt anything to add them as optional
parameters here. An example of use is:

<input type=button value="select" onclick="displayDatePicker('StartDate', false, 'dmy', '.');">

This would display the datepicker beneath the StartDate field (because the
displayBelowThisObject parameter was false), and update the StartDate field with
the chosen value of the datepicker using a date format of dd.mm.yyyy
*/
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 = 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);

  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // 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 += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    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.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'";	// 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'";	// 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);

  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;
  var dArray;
  var d, m, y;

  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else {
      dateVal = new Date(dateString);
    }
  } catch(e) {
    dateVal = new Date();
  }

  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;
}

/**
Update the field with the given dateFieldName with the dateString that has been passed,
and hide the datepicker. If no dateString is passed, just close the datepicker without
changing the field value.

Also, if the page developer has defined a function called datePickerClosed anywhere on
the page or in an imported library, we will attempt to run that function with the updated
field as a parameter. This can be used for such things as date validation, setting default
values for related fields, etc. For example, you might have a function like this to validate
a start date field:

function datePickerClosed(dateField)
{
  var dateObj = getFieldDate(dateField.value);
  var today = new Date();   today = new Date(today.getFullYear(), today.getMonth(), today.getDate());

  if (dateField.name == "StartDate") {
    if (dateObj < today) {
      // if the date is before today, alert the user and display the datepicker again
      alert("Please enter a date that is today or later");
      dateField.value = "";
      document.getElementById(datePickerDivID).style.visibility = "visible";
      adjustiFrame();
    } else {
      // if the date is okay, set the EndDate field to 7 days after the StartDate
      dateObj.setTime(dateObj.getTime() + (7 * 24 * 60 * 60 * 1000));
      var endDateField = document.getElementsByName("EndDate").item(0);
      endDateField.value = getDateString(dateObj);
    }
  }
}

*/
function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementsByName(dateFieldName).item(0);
  if (dateString)
    targetDateField.value = dateString;
  document.getElementById(datePickerDivID).style.visibility = "hidden";
  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);
}


/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDiv, iFrameDiv)
{
  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;
  } catch(e) {
  }
}


//----------------------------------------------------------------------------------------------------

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

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 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++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	//var strYear=dtStr.substring(pos2+1)
	
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : yyyy-mm-dd")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}



function greatDate(date1,date2){
 // alert(date1);
 // alert(date2);
	var daysInMonth = DaysArray(12)
	var pos1=date1.indexOf(dtCh)
	var pos2=date1.indexOf(dtCh,pos1+1)

	var strMonth1=date1.substring(0,pos1)
	var strDay1=date1.substring(pos1+1,pos2)
	var strYear1=date1.substring(pos2+1)
	
	
	strYr1=strYear1;
	if (strDay1.charAt(0)=="0" && strDay1.length>1) strDay1=strDay1.substring(1)
	if (strMonth1.charAt(0)=="0" && strMonth1.length>1) strMonth1=strMonth1.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr1.charAt(0)=="0" && strYr1.length>1) strYr1=strYr1.substring(1)
	}
	
	month1=parseInt(strMonth1)
	day1=parseInt(strDay1)
	year1=parseInt(strYr1)
	
	var pos1=date2.indexOf(dtCh)
	var pos2=date2.indexOf(dtCh,pos1+1)

	var strMonth2=date2.substring(0,pos1)
	var strDay2=date2.substring(pos1+1,pos2)
	var strYear2=date2.substring(pos2+1)

    strYr2=strYear2;
	if (strDay2.charAt(0)=="0" && strDay2.length>1) strDay2=strDay2.substring(1)
	if (strMonth2.charAt(0)=="0" && strMonth2.length>1) strMonth2=strMonth2.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr2.charAt(0)=="0" && strYr2.length>1) strYr2=strYr2.substring(1)
	}

	month2=parseInt(strMonth2)
	day2=parseInt(strDay2)
	year2=parseInt(strYr2)
	
	if(year1<=year2)
	{
      if(year1==year2)
      {
        if(month1<=month2)
        {
          if(month1==month2)
          {
              if(day1<=day2)
              {
                return true;
              }
              else
              {
                return false;
              }
          }
          else
          return true

        }
        else
        {
          return false;
        }
     }
     else
     {
       return true;
     }

    }
    else
    {
      return false;
    }
}


//---------------------------------------------------------------------------------------





function showhide(v)
{
  var s=document.getElementById(v);
  //alert(s.style.display);
  if(s.style.display=="none")
  {
    s.style.display="inline";
    return true;
  }
  else
  {
    s.style.display="none";
    return true;
  }
  return false;

}
function checkDomain(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);

if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your domain extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)
		  	 {
		 	  	 alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your domain name should not have special characters");
			 return false;
		  }
		}
	}
}
else
{
 alert("Your Domain name is too short/long");
 return false;
}

return true;
}



function focusCursor()
{
    for (var i = 0; i < document.forms.length; ++i)
    {
        var f = document.forms[i];
        for (var j = 0; j < f.elements.length; ++j)
        {
            if (f.elements[j].type == 'text' ||
                f.elements[j].type == 'textarea')
            {
                f.elements[j].focus();
                return;
            }
        }
    }
}

function url_validate(url)
{
  var re_http = /^([http:])+\/\/(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
  if (!re_http.test(url))
  {
 	alert("The Hyperlink is incorrectly entered \nPlease ensure that it is a valid URL.\n The url should start with http:// \n An example is 'http://www.yoursite.com'");
		return false;
    }
    else
    return true;

}

function showhide(v)
{
  var s=document.getElementById(v);
  //alert(s.style.display);
  if(s.style.display=="none")
  {
    s.style.display="inline";
    return true;
  }
  else
  {
    s.style.display="none";
    return true;
  }
  return false;

}


function echeck(str,err)
{

		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 "+err)
		   return false
		}

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

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid "+err)
		    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 SelectColor() {
    var retString = ""
    retString += showModalDialog("scripts/selcolor.html", "", "dialogWidth:370px;dialogHeight:240px;help:no;scroll:no;status:no");
    if (retString != "undefined") {
	return retString
    }
    else {
	return ""
    }
    }


function check_login(frm)
{
  if(frm.f_username.value=="")
  {
    alert("Please enter username");
    frm.f_username.focus();
    return false;
  }
  if(frm.f_password.value=="")
  {
    alert("Please enter password");
    frm.f_password.focus();
    return false;
  }
  /*if(frm.f_code.value=="")
  {
    alert("Please enter login code");
    frm.f_code.focus();
    return false;
  }*/
  /*else
  {
        if(frm.f_code.value!=frm.f_sec.value)
        {
            alert("Incorrect Login code");
            frm.f_code.focus();
            return false;
        }
  }*/
  return true;
}

function add_domain(frm)
{
  if(frm.f_server.value=="")
  {
    alert("Please enter ftp server name");
    frm.f_server.focus();
    return false;
  }
  /*else
  {
    if(checkDomain(frm.f_server.value)==false)
    {
      frm.f_server.focus();
        return false;
    }
  }*/
  if(frm.f_username.value=="")
  {
    alert("Please enter FTP username");
    frm.f_username.focus();
    return false;
  }
  if(frm.f_password.value=="")
  {
    alert("Please enter FTP password");
    frm.f_password.focus();
    return false;
  }
  if(frm.f_basepath.value=="")
  {
    alert("Please enter FTP basepath");
    frm.f_basepath.focus();
    return false;
  }
  
  return true;
}


function users_add(frm)
{
    
    if(frm.f_name.value=="")
    {
      alert("Please enter the name");
      frm.f_name.focus();
      return false;
    }
    if(frm.f_username.value=="")
    {
      alert("Please enter the user name");
      frm.f_username.focus();
      return false;
    }
    if(frm.f_email.value=="")
    {
      alert("Please enter the email");
      frm.f_email.focus();
      return false;
    }
    else
    {
        if(echeck(frm.f_email.value)==false)
        {
          alert("Please enter a valid email");
          frm.f_email.focus();
          return false;
        }
    }
    if(frm.f_password.value=="")
    {
      alert("Password cannot be set to NULL or empty");
      frm.f_password.focus();
      return false;
    }
    else if(frm.f_cpassword.value=="")
    {
      alert("Confirm Password cannot be set to NULL or empty");
      frm.f_cpassword.focus();
      return false;
    }
    else if(frm.f_password.value!=frm.f_cpassword.value)
    {
      alert("Password mismatch");
      frm.f_password.focus();
      return false;
    }
    return true;
}


function banwords_add(frm)
{
    
    if(frm.f_name.value=="")
    {
      alert("Please enter the banword");
      frm.f_name.focus();
      return false;
    }
    return true;
}

function profile(frm)
{
    
    if(frm.f_name.value=="")
    {
      alert("Please enter the name");
      frm.f_name.focus();
      return false;
    }
    if(frm.f_email.value=="")
    {
      alert("Please enter the email");
      frm.f_email.focus();
      return false;
    }
    else
    {
        if(echeck(frm.f_email.value)==false)
        {
          alert("Please enter a valid email");
          frm.f_email.focus();
          return false;
        }
    }
    return true;
}

function users_edit(frm)
{
    
    if(frm.f_name.value=="")
    {
      alert("Please enter the first name");
      frm.f_name.focus();
      return false;
    }
    if(frm.f_lname.value=="")
    {
      alert("Please enter the last name");
      frm.f_lname.focus();
      return false;
    }
    if(frm.f_email.value=="")
    {
      alert("Please enter the email");
      frm.f_email.focus();
      return false;
    }
    else
    {
        if(echeck(frm.f_email.value)==false)
        {
          alert("Please enter a valid email");
          frm.f_email.focus();
          return false;
        }
    }
    return true;
}

function products_add(frm)
{
    if(frm.f_pname.value=="")
    {
      alert("Please enter the product name");
      frm.f_pname.focus();
      return false;
    }
    if(frm.f_pid.value=="")
    {
      alert("Please enter the product id");
      frm.f_pid.focus();
      return false;
    }
    if(frm.f_pqty.value=="" || frm.f_pqty.value==0)
    {
      alert("Quantity cannot be NULL or Zero");
      frm.f_pqty.focus();
      return false;
    }
    if(frm.f_pweight.value=="")
    {
      alert("Please enter the product weight");
      frm.f_pweight.focus();
      return false;
    }
    if(frm.f_pcost.value=="")
    {
      alert("Please enter the product cost");
      frm.f_pcost.focus();
      return false;
    }
    if(frm.f_pdcost.value=="")
    {
      alert("Please enter the product deleviry cost");
      frm.f_pdcost.focus();
      return false;
    }
    if(frm.f_pzone.value==0)
    {
      alert("Please create some zones from the Zones section");
      frm.f_pzone.focus();
      return false;
    }
    if(frm.f_picost.value=="")
    {
      alert("Please enter the insureance cost");
      frm.f_picost.focus();
      return false;
    }
    if(frm.f_pdesc.value=="")
    {
      alert("Please enter the product description");
      frm.f_pdesc.focus();
      return false;
    }
    return true;
}


function couriers_add(frm)
{
    if(frm.f_cname.value=="")
    {
      alert("Please enter the courier service name");
      frm.f_cname.focus();
      return false;
    }
    if(frm.f_cperson.value=="")
    {
      alert("Please enter the contact person name");
      frm.f_cperson.focus();
      return false;
    }
    if(frm.f_cno.value=="")
    {
      alert("Please enter the contact No.");
      frm.f_cno.focus();
      return false;
    }
    if(frm.f_cwebsite.value!="")
    {
      if(url_validate(frm.f_cwebsite.value)==false)
        {
            frm.f_cwebsite.focus();
            return false;
        }
    }
    if(frm.f_cemail.value=="")
    {
      alert("Please enter the contact Email.");
      frm.f_cemail.focus();
      return false;
    }
    else
    {
        if(echeck(frm.f_cemail.value)==false)
        {
          alert("Please enter a valid contact Email.");
          frm.f_cemail.focus();
          return false;
        }
    }
    if(frm.f_caddress.value=="")
    {
      alert("Please enter the contact address");
      frm.f_caddress.focus();
      return false;
    }
    if(frm.f_cdesc.value=="")
    {
      alert("Please describe the courier agency");
      frm.f_cdesc.focus();
      return false;
    }
    return true;
}

function zone_add(frm)
{
    if(frm.f_zname.value=="")
    {
      alert("Please enter a zone name");
      frm.f_zname.focus();
      return false;
    }
    if(frm.f_zdesc.value=="")
    {
      alert("Please describe the zone");
      frm.f_zdesc.focus();
      return false;
    }
    /*if(frm.f_zcourier.value==0)
    {
      alert("Please add some courier(s) from the courier section");
      frm.f_zcourier.focus();
      return false;
    }*/
    if(frm.f_dprice.value==0)
    {
      alert("Please mention the delivery price");
      frm.f_dprice.focus();
      return false;
    }
    if(frm.f_etime.value==0)
    {
      alert("Please mention the estimated delivery time");
      frm.f_etime.focus();
      return false;
    }
    return true;
}
function add_tpl(frm)
{
  if(frm.f_tplname.value=="")
  {
    alert("Please enter the template name");
    frm.f_tplname.focus();
    return false;
  }
  
  if(frm.f_contents.value=="" && frm.f_file.value=="")
  {
    alert("Please enter enter the template contents  or \\n select a template file");
    frm.f_contents.focus();
    return false;
  }
  

  return true;
}

function add_title(frm)
{
  if(frm.f_import.value=="")
  {
    alert("Please select a file to import");
    frm.f_import.focus();
    return false;
  }
  return true;
}


function add_market(frm)
{
  if(frm.f_market.value=="")
  {
    alert("Please enter the market name");
    frm.f_market.focus();
    return false;
  }

  if(frm.f_prikeywords.value=="")
  {
    alert("Please enter primary keywords");
    frm.f_prikeywords.focus();
    return false;
  }
  if(frm.f_seckeywords.value=="")
  {
    alert("Please enter secondary keywords");
    frm.f_seckeywords.focus();
    return false;
  }
  if(frm.f_marketurls.value=="")
  {
    alert("Please enter market url's");
    frm.f_marketurls.focus();
    return false;
  }
  if(frm.f_exclusionurls.value=="")
  {
    alert("Please enter exclusion url's");
    frm.f_exclusionurls.focus();
    return false;
  }
  if(frm.f_notes.value=="")
  {
    alert("Please enter notes");
    frm.f_notes.focus();
    return false;
  }
  return true;
}

function add_robot(frm)
{
  if(frm.f_tplname.value=="")
  {
    alert("Please enter the robot file description");
    frm.f_tplname.focus();
    return false;
  }

  if(frm.f_contents.value=="")
  {
    alert("Please enter enter the file contents");
    frm.f_contents.focus();
    return false;
  }


  return true;
}


function add_404(frm)
{
  if(frm.f_tplname.value=="")
  {
    alert("Please enter the 404 template description");
    frm.f_tplname.focus();
    return false;
  }

  if(frm.f_contents.value=="" && frm.f_file.value=="")
  {
    alert("Please enter enter the template contents  or \\n select a template file");
    frm.f_contents.focus();
    return false;
  }


  return true;
}


function del_del(id,a,txt,url)
{

  var k="";
  if(a==1)
  k="Active ";
  if(a==0)
  k="Inactive ";

  if(confirm("Are you sure you want to delete this "+k+txt))
  {
    window.location.href=url+"?"+id;
  }
  else
  {
    return false;
  }
}

function account_check(frm)
{
  if(frm.f_username.value=="")
  {
    alert("Please enter username");
    frm.f_username.focus();
    return false;
  }
  else
  {
    if(frm.f_username.value.length<4)
    {
        alert("username should have a minimum of 4 characters");
        frm.f_username.focus();
        return false;
    }
  }
  if(frm.f_password.value=="")
  {
    alert("Please enter password");
    frm.f_password.focus();
    return false;
  }
  else
  {
    if(frm.f_password.value.length<4)
    {
        alert("Password should have a minimum of 4 characters");
        frm.f_password.focus();
        return false;
    }
  }
  if(frm.f_email.value=="")
  {
    alert("Please enter Email");
    frm.f_email.focus();
    return false;
  }
  else
  {
        if(echeck(frm.f_email.value)==false)
        {
            alert("Please enter valid Email address");
            frm.f_email.focus();
            return false;
        }
  }
  
  if(frm.f_resultperpage.value=="" || frm.f_resultperpage.value==0)
  {
    alert("Please enter a value greater than zero");
    frm.f_resultperpage.focus();
    return false;
  }
  
  return true;
}


function profile_check(frm) {
  if(frm.f_name.value=="")
  {
    alert("Please enter name");
    frm.f_name.focus();
    return false;
  }

  if(frm.f_password.value=="")
  {
    alert("Please enter password");
    frm.f_password.focus();
    return false;
  }
  else
  {
    if(frm.f_password.value.length<4)
    {
        alert("Password should have a minimum of 4 characters");
        frm.f_password.focus();
        return false;
    }
  }
  if(frm.f_email.value=="")
  {
    alert("Please enter Email");
    frm.f_email.focus();
    return false;
  }
  else
  {
        if(echeck(frm.f_email.value)==false)
        {
            alert("Please enter valid Email address");
            frm.f_email.focus();
            return false;
        }
  }
  return true;
}


function search_check(frm)
{
  k=0;
  //alert(frm.length);
  for (i=0;i<frm.length;i++)
    {
      if(frm.elements[i].type=="text")
      {
    	if (frm.elements[i].value!="")
    	{
    		k=1;
    	}
      }
    }

  
    if(k==0)
    {
        alert("Please enter any search condition");
        frm.elements[0].focus();
        return false;
    }


  return true;
}

function add_feed(frm)
{
    if(frm.f_feed.value=="")
    {
        alert("Please enter the feed url");
        frm.elements[0].focus();
        return false;
    }
  return true;
}

function insert_tokens(text) {
        var txtarea = document.tpl.f_contents;
        text = '{' + text + '}';
        //if (txtarea.createTextRange && txtarea.caretPos) {
                var caretPos = txtarea.caretPos;
                alert (caretPos);
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
                txtarea.focus();
       // } else {
         //       txtarea.value  += text;
          //      txtarea.focus();
       // }
}


function insert_token(text){
  var objMailForm = document.forms['tpl']
  var objEl = objMailForm.elements['f_contents']
  if (objEl.createTextRange && objEl.caretPos){
   var caretPos = objEl.caretPos;
   caretPos.text =
   caretPos.text.charAt(caretPos.text.length - 1) == '{' ? text + '}' :text;
  }
  else{
   objEl.value += text + " ";
  }
}


function list_check(k,frm,cont,url)
{
  frm=document.getElementById(frm);
  var ck=0;
  var got=0;
  if(k==1) {
    frm.act.value="delete";
    act="delete";
  }
  if(k==2) {
    frm.act.value="activate";
    act="Unlock";
  }
  if(k==3) {
    frm.act.value="deactivate";
    act="Lock";
  }
  if(k==4) {
    frm.act.value="undispatch";
    act="Undispatch";
  }
  if(k==5) {
    frm.act.value="close";
    act="close";
  }
  if(k==6) {
    frm.act.value="email";
    act="email";
  }
  if(k==7) {
    frm.act.value="edit";
    act="modify";
  }
  if(k==8) {
    frm.act.value="default";
    act="set as default";
  }
  checknum=0;
  for(i=0;i<frm.del.length;i++) {
    if(frm.del[i].checked) {
      got=1;
      checknum++;
      frm.del[i].name="del[]";
    }
  }
  if(got==1) {
    if((k==7 || k==8) && checknum!=1) {
      alert("Please select only one record to "+act);
    } else {
      //return true;
      if(confirm("Are you sure you want to "+act+" the selected "+cont)) {
        if(k==6) {
          for(i=0;i<frm.del.length;i++) {
            if(frm.del[i].checked) {
              e=frm.del[i].value;
              em='email'+e;
              f=document.getElementById(em).value;
              frm.del[i].value=f;
              frm.del[i].name="emailto[]";
            }
          }
        } else {
          for(i=0;i<frm.del.length;i++) {
            if(frm.del[i].checked) {
              editid=frm.del[i].value;
              frm.del[i].name="del[]";
            }
          }
        }
        if(k==6) {
          frm.action="send_email.php";
        }
        if(k==7) {
          url=url+"?editid="+editid;
          window.location.href=url;
        } else {
          frm.submit();
        }
      }
    }
  } else {
    if(frm.del.checked) {
      ck=1;
      if(confirm("Are you sure you want to "+act+" the selected "+cont)) {
      if(k==6) {
        e=frm.del.value;
        em='email'+e;
        f=document.getElementById(em).value;
        frm.del.value=f;
        frm.del.name="emailto[]";
      } else {
        editid=frm.del.value;
        frm.del.name="del[]";
      }
      if(k==6) {
        frm.action="send_email.php";
      }
      if(k==7) {
        url=url+"?editid="+editid;
        window.location.href=url;
      } else {
        frm.submit();
      }
      }
    }
  }
  if(got==0 && ck==0) {
    alert("No "+cont+" are selected");
  }
}

function selectallcheck(frm,ctl,act)
{
   f=0;
   if(act==1) {
     for(i=0;i<ctl.length;i++) {
       f=1;
       va='row'+ctl[i].value;
       document.getElementById(va).className='inactive';
       ctl[i].checked=true;
     }
   }
   if(act==0) {
     for(i=0;i<ctl.length;i++) {
       f=1;
       va='row'+ctl[i].value;
       document.getElementById(va).className='rcolor';
       ctl[i].checked=false;
     }
   }
   if(f==0) {
     if(act==1) {
       va='row'+ctl.value;
       document.getElementById(va).className='inactive';
       ctl.checked=true;
     }
     if(act==0) {
       va='row'+ctl.value;
       document.getElementById(va).className='rcolor';
       ctl.checked=false;
     }
   }
}

function deldel(a,txt,url)
{

  var k="";
  if(a==1)
  k="Active ";
  if(a==0)
  k="Inactive ";

  if(confirm(txt))
  {
    window.location.href=url;
  }
  else
  {
    return false;
  }
}

function editpassword(ctl)
{
  if(ctl.value=="")
  {
    alert("Password cannot be left blank");
    ctl.focus();
    return false;
  }
  else
  {
    if(confirm("Do you want to continue ?"))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
}

function rowmouseout(rid,chkid)
{
  if(document.getElementById(chkid))
  {
  if(document.getElementById(chkid).checked==false)
  rid.className='rcolor';
  }
  else
  {
    rid.className='rcolor';
  }
}

function menumouseover(tdid)
{
  //tdid=document.getElementById(tdid);
  tdid.className='menuover';
  //alert(tdid.classname);
}
function menumouseout(tdid)
{
  //tdid=document.getElementById(tdid);
  tdid.className='menumain';
}

function rowmouseover(rid)
{
  rid.className='inactive'
}

function rowonclick(rid,chkid)
{
  
  if(document.getElementById(chkid).checked==true)
  {
    document.getElementById(chkid).checked=false;
    document.getElementById(rid).className='rcolor'
  }
  else
  {
    document.getElementById(chkid).checked=true;
    document.getElementById(rid).className='inactive'
  }
}

function checkclick()
{
	var rightclick;
	var e = window.event;
	alert (e.button);
	if (e.which)
    rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	alert('Rightclick: ' + rightclick); // true or false
}

function getvalue(thediv,vari,ctl)
{
  var gourl="get_value.php?thediv="+thediv+"&"+vari+"="+ctl.value;
  ajax_do(gourl);
}

function loading(thediv,txt)
{
    document.getElementById(thediv).innerHTML="<img src=images/loading.gif border=0>"+txt;
}

function loadingm(thediv,txt)
{
    document.getElementById(thediv).innerHTML="<img src=user/images/loading.gif border=0>"+txt;
}

function add_status(frm)
{
  if(frm.f_statname.value=="")
  {
    alert("Please enter Status name");
    frm.f_statname.focus();
    return false;
  }
  if(frm.f_color.value=="")
  {
    alert("Please select a color");
    frm.f_color.focus();
    return false;
  }
  if(frm.f_textcolor.value=="")
  {
    alert("Please select a color for the text");
    frm.f_textcolor.focus();
    return false;
  }
  return true;
}

function send_mail(frm)
{
    if(frm.subject.value=="")
    {
        alert("Please enter the mail subject");
        frm.subject.focus();
        return false;
    }
    /*if(oHTMLEd1.GetHTML()=="")
    {
      alert("Please enter the mail content");
        //frm.content.focus();
        return false;
    }*/
    /*if(frm.content.value=="")
    {
        alert("Please enter the mail content");
        //frm.content.focus();
        return false;
    }*/
    if(!confirm("Are you sure you want to send this mail"))
    return false;

    

    return true;
}

function sbClock() {
 self.status=(new Date()).toString().substring(0,19);
 setTimeout("sbClock()",200);
}

function load_popup(url)
{
  window.open(url,'','location=0, scrollbars=1,resizable=1');
}

function justgoto(url)
{
  window.location.href=url;
}

function go_next(a)
{

  var s="div"+a;

  var n=++a;
  n="div"+n;

  var k=document.getElementById(s);
  var l=document.getElementById(n);

  if(k)
  {
    if(l)
    {
        k.style.display="none";
        l.style.display="inline";
    }
  }
}

function go_prev(a)
{

  var s="div"+a;

  var n=--a;
  n="div"+n;

  var k=document.getElementById(s);
  var l=document.getElementById(n);

  if(k)
  {
    if(l)
    {
        k.style.display="none";
        l.style.display="inline";
    }
  }
}

function change_password(frm)
{
  if(frm.f_old.value=="")
  {
    alert("Please enter your old password");
    frm.f_old.focus();
    return false;
  }
  if(frm.f_new.value=="")
  {
    alert("Please enter your new password");
    frm.f_new.focus();
    return false;
  }
  if(frm.f_new.value!=frm.f_cnew.value)
  {
    alert("password mismatch");
    frm.f_cnew.focus();
    return false;
  }
  return true;
}
function add_airforces(frm)
{
  if(frm.f_code.value=="")
  {
    alert("Please enter the Airforce code");
    frm.f_code.focus();
    return false;
  }
  if(frm.f_name.value=="")
  {
    alert("Please enter the Airforce Name");
    frm.f_name.focus();
    return false;
  }
  return true;
}

function check_settings(frm)
{
  for(i=0;i<frm.length;i++)
  {
    if(frm.elements[i].type!="submit")
    {
    if(frm.elements[i].value=="" || frm.elements[i].value==0)
    {
        //alert(frm.elements[i].name);
      alert("Entry cannot be NULL or zero");
      frm.elements[i].focus();
      return false;
    }
    }
  }
  return true;
}

