
function ValidCharacters(strValue)
{
	if(((strValue == "") || (strValue.length == 0)))
		return true;
	
	var ValidChars = "1234567890,.$";
	var Char;
	var Text=strValue;
		for (i = 0; i < Text.length; i++) 
		{ 
			Char = Text.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
    			return(false);			
			}
			
		
		}  
		return true;
		
	
  }
	 function IsValidCharacters(strValue)
	{
	if(((strValue == "") || (strValue.length == 0)))
		return true;
	
	var IsValidChars = " 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,@!_-.";
	var IsChar;
	var ISText=strValue;
		for (i = 0; i < ISText.length; i++) 
		{ 
			IsChar = ISText.charAt(i); 
			if (IsValidChars.indexOf(IsChar) == -1) 
			{
    			return(false);			
			}
		
		}  
		return true;	
  }
  
		function IsContainSpclChar(strValue)
		 {
		 	if(((strValue == "") || (strValue.length == 0)))
				return false;
			var InValidChars = ">#%/\<";
			var InChar;
			var InText=strValue;
			for (i = 0; i < InText.length; i++) 
			{ 
				InChar = InText.charAt(i); 
				if (InValidChars.indexOf(InChar) != -1) 
				{						
    				return (true);			
				}
			
			}  
			return false;				
		}
  
function isEmptyString(strValue) {
	if(((strValue == "") || (strValue.length == 0)))
		return true;
	return false;
	}
/********************************************************************************************************/	
function trimString(strValue) {
	var chrSpace = " ";
	/*This section is for LEFT trimming of any string*/
	for(var i = 0; i < strValue.length; i++) {
		if(strValue.charAt(i) != chrSpace)
			break;
		}
	if(i != 0)
		strValue = strValue.substring(i,strValue.length);
	/*This section is for RIGHT trimming of any string*/
	for(i = (strValue.length-1); i >= 0; i--) {
		if(strValue.charAt(i) != chrSpace)
			break;
		}
	if(i != (strValue.length-1))
		strValue = strValue.substring(0,(i+1));
	return strValue;
	}	
/********************************************************************************************************/
function isIntegerValue(theParam) {
	var theNumArray = new Array(0,1,2,3,4,5,6,7,8,9,'.');
	var index = 0, j;
	if(theParam.charAt(0) == "+" || theParam.charAt(0) == "-")
		index = 1;
	for( ; index < theParam.length; index++) {
		var isValidFlag = false;
		for(j = 0; j < theNumArray.length; j++) {
			if(theParam.charAt(index) == theNumArray[j]) {
				isValidFlag = true;
				break;
				}
			}
		if(!isValidFlag)	
			return false;
		}	

		if (theParam < 0)
			{
		return false;
			}
  		var ValidChars = "1234567890.";
  		var Char;
  		var Text=theParam.value;
  		for (i = 0; i < theParam.length; i++) 
  		{ 
  		  Char = theParam.charAt(i); 
  		  if (ValidChars.indexOf(Char) == -1) 
  		  {
       
  		   return(false);
  		  }
  		}		
    return true;
	}
	
/***************************************************************************************************/



/***************************************************************************************************/
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 strMonth = dtStr.substring(pos1+1,pos2)
	var strDay = dtStr.substring(0,pos1)
	var strYear=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 : dd/mm/yyyy")
		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 toFix(num){
  num = Math.round(num * 10000);
 // if(num==0) return "0.00";
  if(num==0) return "";
  num = (num/10000+"").split(".");
  if (num[1] > 0)
  {
  return num[0]+"."+(num[1]+"0").substr(0,4);
  }
  return num[0]+"."+"00".substr(0,2);
}
//*************************************************************
function IsValidTime(timeStr) {
			// Checks if time is in HH:MM:SS AM/PM format.
			// The seconds and AM/PM are optional.

			var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

			var matchArray = timeStr.match(timePat);
			if (matchArray == null) {
			alert("Time is not in a valid format.");
			return false;
			}
			hour = matchArray[1];
			minute = matchArray[2];
			second = matchArray[4];
			ampm = matchArray[6];

			if (second=="") { second = null; }
			if (ampm=="") { ampm = null }
			
			if (ampm == null)
			{
				if (hour <= 0  || hour > 12) {
				alert("Hour must be between 1 and 12.");
				return false;
				}							
				if (minute<0 || minute > 59) {
				alert ("Minute must be between 0 and 59.");
				return false;
				}
				if (second != null && (second < 0 || second > 59)) {
				alert ("Second must be between 0 and 59.");
				return false;
				}
			}
			else
			{
			alert ("Remove AM / PM from the time field.");
			return false;
			}
			return true;
		}
function setFormat(thisItem)
{
thisItem.value=formatCurrency(thisItem.value);
}

function formatCurrency(num)
 {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);

}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}



function sendrequest(http_request,divid)
	{
		if(http_request.readyState ==4)
		   { 
			   if(http_request.status ==200)
			   {
				resText=http_request.responseText;
				document.getElementById(divid).innerHTML=resText;
			   }
			    else {
			document.getElementById(divid).innerHTML = "<FONT SIZE='4' COLOR='red'>Query not submitted!</FONT>";
					}
		   }
	}

	function callStates(id,op,divid)
{	 

 	  
		var url= 'ajax.php?op='+op+'&id='+id+'&divid='+divid;
		//alert(url);
 		var post_data=url;

		document.getElementById(divid).innerHTML = "<FONT SIZE='2' COLOR='red'><img src='../healthcare/images/ajax-loader-clock.gif' border='0'></font>";
		if(window.XMLHttpRequest)
		{
			http_request=new XMLHttpRequest();
		if(http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/html');
			}
			
		}else if(window.ActiveXObject)
		{
			try{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e)
				{
				try{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){}
				}
		
		}
	
	http_request.onreadystatechange=function(){sendrequest(http_request,divid);};
	http_request.open('GET',url,true);
	http_request.send(null);
	
	}

	function validateHospital()
	{
	if(document.getElementById('cb_hospitalname').value=='')
		{
		alert("Please enter Hospital Name");
		document.getElementById('cb_hospitalname').focus();
		return false;
		}
		if(document.getElementById('cb_hospitaltype').value=='')
		{
		alert("Please choose Hospital Type");
		document.getElementById('cb_hospitaltype').focus();
		return false;
		}
	}

	function showHideDiv(divid)
{
	if(document.getElementById(divid).style.display=='none')
	{
	document.getElementById(divid).style.display='';
	}
	else
	{
 	document.getElementById(divid).style.display='none'
	}
}


function callStatesAll(id,op,divid)
{	 

 	  
		var url= 'statesAll.php?country='+id;
		//alert(url);
 		var post_data=url;

		document.getElementById(divid).innerHTML = "<FONT SIZE='2' COLOR='red'><img src='images/ajax-loader-clock.gif' border='0'></font>";
		if(window.XMLHttpRequest)
		{
			http_request=new XMLHttpRequest();
		if(http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/html');
			}
			
		}else if(window.ActiveXObject)
		{
			try{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e)
				{
				try{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){}
				}
		
		}
	
	http_request.onreadystatechange=function(){sendrequest(http_request,divid);};
	http_request.open('GET',url,true);
	http_request.send(null);
	
	}

	function resetState()
	{
	
	document.getElementById('state2').selectedIndex=0;
	return false;
	}