
var _http_root;


// 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 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").val()=="")
    {
        alert("Enter the values in text field");
        return;
    }
    if(trim($("#txtSearch").val())!="")
    {
        
        if(!isValidName(trim($("#txtSearch").val())))

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


function convertToDate(st_date)
{
    var sd_arr=new Array();
    sd_arr=st_date.split("-");
    var temp=sd_arr[0];
    sd_arr[0]=sd_arr[1];
    sd_arr[1]=temp;
    var sd_str=sd_arr.join("/");
    var n_date=new Date(sd_str);
    return n_date;
}

function getConvertedTime(timestat,hours,minitue)
{

	if($(timestat).val().toLowerCase()	==	'am')
    {
		time1	=	parseInt($(hours).val(),10);

        if($(hours).value == 12)
        {
			time1	=	parseInt($(hours).val(),10)-12;
        }


	}else{
		if($(hours).val() == 12){
			//time1	=	parseInt($(hours).value,10)-12;
			time1	= 12;

		}else{
			time1	=	parseInt($(hours).val(),10)+12;
		}
	}
	return parseInt((time1*60)+parseInt($(minitue).val(),10),10);
}




function __fncUpdateTotalAppointmentCount(drid)
    {

        $.ajax({
            type:'POST',
            url: 'ajaxpost.php',
            dataType : 'json',
            data:{action:'GET_APP_COUNT',drid:drid},
            success:function(data){

                
            
                $('#updateAppointments').html(data.apps);

                setTimeout(function(){__fncUpdateTotalAppointmentCount(drid)}, 5000);
                
            },
            error : function(XMLHttpRequest, textStatus, errorThrown)
            {

                alert(textStatus);
				alert(XMLHttpRequest.responseText);

			}});

    
    }

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

function __fncValidatePasswordPair(firstId,secondId)
{

        if($('#'+firstId).val()=="")
        {

            alert("Please enter your Password.");
            $('#'+firstId).focus();
            return false;
        }else if($('#'+firstId).val().length<6)
        {

            alert("Please enter a valid Password.");
            $('#'+firstId).focus();
            return false;
        }else if($('#'+secondId).val()=="")
        {

            alert("Please Re-enter your Password.");
            $('#'+secondId).focus();
            return false;
        }else if($('#'+firstId).val()!=$('#'+secondId).val())
        {

            alert("Password mismatch.");
            $('#'+secondId).focus();
            return false;
        }

        return true;

}


