
//Various Errors using for Javascript Validation

var _NO_USER_NAME       = 'please enter the username.';
var _INVALID_USER_LEN   = 'Minimum 3 characters required.';
var _INVALID_USER_NAME  = 'please enter the username.';
var _NO_PASSWORD        = 'please enter the password.';
var _INVALID_PASS_LEN   = 'Minimum 6 characters.';
var _NO_CONFIRM_PASS    = 'Please enter confirm password.';
var _INVALID_LOGIN      = 'invalid username or password.';

var _NO_STATE           = 'please select any state.';
var _NO_DISTRICT        = 'please select any district.';
var _NO_PRACT_LOC       = 'please enter your Practice Location.';


var _NO_OPTION_SELECT   = 'please select an option';
var _NO_DOCTOR_SELECT   = 'please select a doctor';
var _SELECT_ONE_ONLY    = 'please select only one doctor';

//Common Errors
var _NOT_AN_INTEGER     = 'please enter an integer value';

//Errors for timeslot details
var _NO_OF_PATIENTS     = 'please enter no of patients in a slot';

var _SEPERATOR          = '###';


///Doctor Profile page validation
var _NO_NAME            = 'please enter the name.';
var _NO_EMAIL           = 'please enter the Email-id.';
var _INVALID_EMAIL      = 'please enter a valid Email-id.';
var _NO_MOBILE          = 'please enter your Mobile Number.';
var _INVALID_MOBILE     = 'please enter valid Mobile Number.';
var _NO_DEGREE          = 'please enter basic professional degree.';
var _NO_SPECIALITY      = 'please select any Speciality.';
var _NO_TOS             = 'you should accept our TOS.';




	// JavaScript Document
	function getDivByID(layerID) {
		if (document.getElementById) {
			// this is the way the standards work
			return document.getElementById(layerID);
		} else if (document.all) {
			// this is the way old msie versions work
			return document.all[layerID];
		} else if (document.layers){
			// this is the way nn4 works
			return document.layers[layerID];
		}
		return null;
	}
	
	//Trim Functions
	function ltrim(str) {
		for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
		return str.substring(k, str.length);
	}
	function rtrim(str) {
		for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
		return str.substring(0,j+1);
	}

	function trim(str) {
		return ltrim(rtrim(str));
	}

	function isAlphaNumeric(val){
		if (val.match(/^[a-zA-Z0-9]+$/))
		{
		return true;
		}
		else
		{
		return false;
		}
	}

	function isValidUserName(val){
		if (val.match(/^[a-zA-Z0-9_]+$/)){
			if(val.match(/^[_]+$/)){
				return false;
			}else{
				return true;
			}
		}else{
			return false;
		}
	}

	function isWhitespace(charToCheck) {
		var whitespaceChars = " \t\n\r\f";
		return (whitespaceChars.indexOf(charToCheck) != -1);
	}
	//End Trim Functions
	
	//Email Validation
		function isValidEmail(email){
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			if (filter.test(email)){
				return true;
			}else{
				return false;
			}

		}
	
	//Get Count Selected Values In Multi Select Combo
	function countOfMultiSelect(comboName,count){
		var objCombo=comboName;
		var selCount=0;
		for (var i=0; i<objCombo.options.length; i++)
			selCount += (objCombo.options[i].selected)?1:0;
		if (selCount > count){
			return false;
		}else{
			return true;
		}
	}
	
	//Function To Count Characters Dynamically
	function countChar(field,length,divName){
		//alert(field);
		var len,val,msg;
		if (field.value == '') return;
		msg = field.value;
		len = msg.length;
		if(len > length){
			len = length;
			val = field.value;
			val = val.replace(/\r\n/g,"\n");
					field.value = val.substring(0,length);
			val = val.replace(/\n/g,"\r\n");
		}
		//var leng = length-len;
		divName.innerHTML = "Count : "+len;
		return true;
	}
	
	function numbersonly(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			 key = window.event.keyCode;
		else if (e)
			 key = e.which;
		else
			 return true;
		keychar = String.fromCharCode(key);

		var val = myfield.value;
		if(val && keychar == '.'){
			if(val.split(".").length > 1){
				return false;
			}
		}

		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
			 return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			 return true;

		// decimal point jump
		else if ((dec) && (keychar == "."))
			 {
			 //myfield.form.elements[dec].focus();
			 return true;
			 }
		else
			 return false;
	}
	// Calcel Js function
	function __fncCancel(){
		thisForm.txtWhat2Do.value = '';
		thisForm.submit();
	}

	function makePOSTRequest(url, parameters, id) {
		var id = id;
		//var	http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/html');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}
		http_request.onreadystatechange = function alertContents_01(){
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					result = http_request.responseText;
					document.getElementById(id).innerHTML = result;
					if(url == "posts.php?action=addLocations"){
						thisForm.cboCountry.selectedIndex = 0;
					}
				} else {
					document.getElementById(id).innerHTML = 'There was a problem with the request.';
				}
			}
			};
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}

	function __fncTabMouseOut(obj){
		if(obj.className != 'tab_active'){
			obj.className = 'top_menu';
		}
	}
	function __fncTabMouseOver(obj){
		if(obj.className != 'tab_active'){
			obj.className = 'tab_hover';
		}
	}

	var blindList = new Array();

	function __fncFlickBlind(toFlick) {
		toFlick = document.getElementById(toFlick);
		if (blindList[toFlick.id]) {
			new Effect.BlindUp(toFlick);
			blindList[toFlick.id]=false;
			document.getElementById(toFlick.id+"_flick").innerHTML="+";
		}else{
			new Effect.BlindDown(toFlick);
			blindList[toFlick.id]=true;
			document.getElementById(toFlick.id+"_flick").innerHTML="-";
		}
		return false;
	}



/***  Date and Year Validation

on 2008-07-08

*/


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
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 __fncCancel(){
		thisForm.txtWhat2Do.value="";
		thisForm.submit();
}
function isDate(obj){
	var dtStr=obj.value;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+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")
		obj.value="";
		obj.focus;
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		obj.value="";
		obj.focus;
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		obj.value="";
		obj.focus;
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		obj.value="";
		obj.focus;
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		obj.value="";
		obj.focus;
		return false
	}
return true
}

function checkYear(obj){
	var strYear=obj.value;
	if (strYear.length != 4 || strYear==0 || strYear<minYear || strYear>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		obj.value="";
		obj.focus;
		return false
	}
}
/*function CheckPhoneNumber(phonenumber,type){
	if(type	==	1){
		if((phonenumber).length !=10)
        {
			return false;
		}
        else if(phonenumber[0]!='9'|| phonenumber[0]!='8')
        {
			return false;
		}
        else
            {
                return true;
            }
	}else{
		if((phonenumber).length < 6  ||   (phonenumber).length > 8 ){
			return false;
		}else{
			return true;
		}
	}

}*/
function removeErrorMessage(divisionId)
{
	
    if (document.getElementById(divisionId) == null)
        {
            return false;
        }
    else
        {
            document.getElementById(divisionId).style.display	=	'none';
            return true;
        }

	    
}

function __fncShowdiv(number,total)
{
    var divid;
    var hidediv;
    var  hidenumber;

    number=parseInt(number);

    for(var i=1;i<=number;i++)
    {
        divid="div"+i;
        $(divid).style.display = 'none';
    }
    hidenumber=number+1;

    for(i=hidenumber; i<=total;i++)
    {
        hidediv="div"+i;
        $(hidediv).style.display = 'none';
    }

    divid="div"+number;
    
    $(divid).style.display = 'block';

 }

// function added for doctors/hospital search added by Jineesh Mani
function __fncMainSearch()
{


    if($("txtSearch").value=="")
    {
        alert("Enter the values in text field");
        return;
    }
    if(trim($("txtSearch").value)!="")
    {
        
        if(!isValidName(trim($("txtSearch").value)))

         {
          alert("Special characters are not allowed");
          return;
         }


    }

    thisForm.action="advancesearch.php?action=main";
    thisForm.txtWhat2Do.value='MAIN_SEARCH';
   // window.location="advancesearch.php";
    thisForm.submit();
}



function isValidName(data)
{
var iChars = "!@#$%^&*()+=-[]\\\'`;,/{}|\":<>?~";
   for (var i = 0; i < data.length; i++) {
  	if (iChars.indexOf(data.charAt(i)) != -1)
    {
  	  //alert ("Your string has special characters. \nThese are not allowed.");
  	  return false;
  	}
  }
  
  return true;
}

function isValidHospitalName(data)
{
var iChars = "!@#$%^&*()+=[]\\\'`;,/{}|\":<>?~";
   for (var i = 0; i < data.length; i++) {
  	if (iChars.indexOf(data.charAt(i)) != -1)
    {
  	  //alert ("Your string has special characters. \nThese are not allowed.");
  	  return false;
  	}
  }

  return true;
}



/*Added on JULY 28th 2010*/
//Ajax Periodical updater

function __fncUpdateTotalAppointmentCount(drid)
{

  
  url ='ajaxpost.php';
  
  new Ajax.PeriodicalUpdater('updateAppointments', url,
    {
     parameters: {action: 'getAppointmentCount', drid: drid },
     method: 'get', frequency: 3, decay: 2
   });

}
function __fncCheckMobileNumber(phonenumber)
{
     
    
    if((phonenumber).length !=10)
        {
			return false;
		}
    else if(phonenumber.charAt(0)=='9' || phonenumber.charAt(0)=='8')
        {
			
           
            return true;
		}
    else
        {
            return false;
        }
}