

function str_explode(separator, str)
{
	var str_array = str.split(separator);
	return str_array;
}




function IsNumber(val)
{
	for (i = 0; i < val.length; i++) {
		if (val.charAt(i) < "0") {
			return false;
		}
		if (val.charAt(i) > "9") {
			return false;
		}	
	}		
	return true;
}

function daysElapsed(d1,m1,y1,d2,m2,y2) {
    var difference =
        Date.UTC(y1,m1-1,d1,0,0,0)
      - Date.UTC(y2,m2-1,d2,0,0,0)
    return Math.abs(difference/1000/60/60/24);
}


function days_in_month (year, month) {
     return 32 - new Date(year, month, 32).getDate();
}


function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}


function outputComma(number) {
    
	
	number = '' + number;
	suffix = number.substring(number.indexOf(".")); 
	number = number.substring(0,number.indexOf(".")); 

    if (number.length > 3) {
        var mod = number.length%3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
                output+= ',' + number.substring(mod+3*i,mod+3*i+3);
        }
        return (output+suffix);
    }
    else return number+suffix;
}



function cent(amount) {
// returns the amount in the .99 format
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}



function confirmLogout(){

	if (confirm("Are you sue u want to logout?"))
		document.location.href = "logout.dti"

}

function isInt(string) {
    if (string.length == 0)
        return false;
    for (var i=0;i < string.length;i++)
        if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9'))
            return false;
    
    return true;
}


function toUpper(str) { //capitalise first letter of every word
    
	if (trim(str) == '')
	{
		return '';
	}

	var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 

    var a = str.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    return a.join(' '); // join it back together
}


function strlen(str)
{
	return str.length
}


function timeTillDate(whenDay,whenMonth,whenYear) {
    var now = new Date();
    var then = new Date(y2k(whenYear),whenMonth-1,whenDay);

    var difference = Date.UTC(y2k(then.getYear()),then.getMonth(),then.getDate(),0,0,0) -
                     Date.UTC(y2k(now.getYear()),now.getMonth(),now.getDate(),0,0,0);
    
    return difference/(1000*60*60*24);
}

function getExtension(value) {
  return value.substring(value.lastIndexOf('.') + 1,value.length);
}

 
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}


function y2k(number)
{
  return (number < 1000) ? number + 1900 : number;
}


function datePosition(d1,m1,y1,d2,m2,y2,flag)
{
	m1 = parseFloat(m1, 10)
	m2  = parseInt(m2, 10)
	d1 = parseFloat(d1, 10)
	d2  = parseFloat(d2, 10)

  if (m1 < 10)
    m1 = "0" + m1;

  if (m2 < 10)
    m2 = "0" + m2;

  if (d1 < 10)
    d1 = "0" + d1;

  if (d2 < 10)
    d2 = "0" + d2;



  /*
     type 5 : 05/29/1997

     'flag' determines if we are comparing date1 with todays date or not
     Returns -1 if the date1 is behind date2
     Returns 0 if the date1 is equal to date2
     Returns 1 if the date1 is ahead of date2

     Added Y2K checking.  (Works for any century cross over)
  */

    //date format needs to be "mm/dd/yyyy"
    dateString1 = m1 + "/" + d1 + "/" + y1;

    var now = new Date();

    if (flag==1)  //compare with given (second) date
      {
        var dateString2 = m2 + "/" + d2 + "/" + y2;
        var date2 = new Date(dateString2.substring(6,10),
                            dateString2.substring(0,2)-1,
                            dateString2.substring(3,5));
      }


    else //compare with today's date
      var date2 = new Date(now.getFullYear(),now.getMonth(),now.getDate());


      var date1 = new Date(dateString1.substring(6,10),
                            dateString1.substring(0,2)-1,
                            dateString1.substring(3,5));

    if (date1 < date2)
       return -1;

    else if (date1 > date2)
       return 1;

    else
      return 0;

}


function isValidDate (day,month,year)
{
  // checks if date passed is valid
 
    var today = new Date();
    year = ((!year) ? y2k(today.getFullYear()):year);
	month = ((!month) ? today.getMonth():month-1);
  

    if (!day) return false


    var test = new Date(year,month,day);
    if ( (y2k(test.getFullYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false

}




function replaceCarriageReturn(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceCarriageReturn(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function trim(strText) { 

    strText = replaceCarriageReturn(replaceCarriageReturn(strText,'\r',''),'\n','');

	// this will get rid of leading spaces 
    while ((strText.substring(0,1) == ' ')||(strText.substring(0,2) == '\r')) 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while ((strText.substring(strText.length-1,strText.length) == ' ')||(strText.substring(strText.length-2,strText.length) == '\r'))
        strText = strText.substring(0, strText.length-1);

   return strText;
} 


function is_empty(form, field)
{
  form.field.value = trim(form.field.value);
  if ( (temp_str == null) || (temp_str == " ") || (temp_str == '\t') || (temp_str == "") )
	return true;
  else
	return false;
}




function doMouseOver(el, colour) {
    el.style.background = colour;
    }

function doMouseOut(el, colour) {
		el.style.background = colour;	
    }


function mOvr(src,colorOver){ 
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'hand'; 
		src.bgColor = colorOver; 
	} 
} 
function mOut(src,colorIn){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.bgColor = colorIn; 
	} 
} 
function mClk(src){ 
	if(event.srcElement.tagName=='TD')
		src.children.tags('A')[0].click();
}


