// AJAX Function
var xmlHttp, xmlHttp2

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function isDate(sText, allowBlank) {
	var i, j;
	var dd, mm, yyyy;
	var i_dd, i_mm, i_yyyy;
	var temp;
	var isLeap;

	sText=trim(sText)
	
	if ( (allowBlank) && (sText=="") )
		return true;
		
	i = sText.indexOf("/")
	dd = sText.substring(0, i)
	temp = sText.substring(i+1)

	i = temp.indexOf("/")
	mm = temp.substring(0, i)
	yyyy = temp.substring(i+1)
	
	if ( (!(isnumeric(dd))) || (!(isnumeric(mm))) || (!(isnumeric(yyyy))) ){
		return false;
	}

	i_dd = parseInt(dd, 10)
	i_mm = parseInt(mm, 10)
	i_yyyy = parseInt(yyyy, 10)
	
	if ( (i_mm<0) || (i_mm>12) ) {
		return false;
	}
	
	if ( ( ((i_yyyy%4)==0) && ((i_yyyy%100)!=0) ) || ((i_yyyy%400)==0) ){
		isLeap = 1;
	} else {
		isLeap = 0;
	}
	switch (i_mm) {
	case 4:
	case 6:
	case 9:
	case 11:
		if ( (i_dd>0) && (i_dd<=30) )
			return true;
		else
			return false;
		break;
		
	case 2:
		if ( (i_dd>0) && (i_dd<=28 + isLeap) )
			return true;
		else
			return false;
		break;
	default:
		if ( (i_dd>0) && (i_dd<=31) )
			return true;
		else
			return false;
		break;
	}
}

function isnumeric(sText) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
			break;
		}
	}
	return IsNumber;   
}
   
function isdecimal(sText) {
	var ValidChars = ".0123456789";
	var isdecimal=true;
	var Char;
	var i;
	var j;
	var decimalExist = false;
 
	for (i = 0; i < sText.length; i++) { 
		Char = sText.charAt(i); 
		j = ValidChars.indexOf(Char) 
		if (j == -1) {
			isdecimal = false;
			break;
		} else {
			if (j == 0) {
				if (!decimalExist) {
					decimalExist = true
				} else {
					isdecimal = false
				}
			}
		}
	}
	
	return isdecimal;   
}
   
function trim(str) {
	var temp = str
	var ind = 0
	
	for (var i=0; i<temp.length; i++) {
		if (temp.charAt(i) == " ") {
			ind = i
		} else {
			break
		}
	}
	temp = temp.substring(ind, temp.length)
	
	ind = temp.length
	for (var i=temp.length-1; i>=0; i--) {
		if (temp.charAt(i) == " ") {
			ind = i-1
		} else {
			break
		}
	}
	temp = temp.substring(0, ind+1)
	return temp
}

function convertDateFormat(str) {
	if (str.length != 6) {
		if (str.length != 8) {
			return "Incorrect Format";
		} else if (!(isDate(str.substr(3,2) + str.substr(2,1) + str.substr(0,2) + str.substr(5,1) + str.substr(6,2), false) ) ) {
			return "Incorrect Format";
		} else {
			return str.substr(0,2) + "/" + str.substr(3,2) + "/" + str.substr(6,2);
		}
	} else if (!(isnumeric(str) ) ) {
		return "Incorrect Format";
	} else if (!(isDate(str.substr(2,2) + "/" + str.substr(0,2) + "/" + str.substr(4,2), false ) ) ) {
		return "Incorrect Format";
	} else {
		return str.substr(0,2) + "/" + str.substr(2,2) + "/" + str.substr(4,2);
	}
}