// ajax function to call the file and passing the value, added By Manish
function ajax(url,targetDiv,getForm,onFinalWhat)
{
	//alert(url);
	//alert(targetDiv);
try{	
	AjaxRequest.get(
			{
				'url': url
				,'onLoading':function() {}
				,'onLoaded':function() {}
				,'onInteractive':function() {}
				,'onComplete':function() {}
				,'onError':function(req){ }
				,'onSuccess':function(req){ 
				try{	
					result = req.responseText; 
					var jscode = "";												
						var parts = result.match(/<script[^>]*>(.|\n|\t|\r)*?<\/script>/gi);
						if(parts){
							for(i=0;i<parts.length;i++){
								jscode += parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
								result = result.replace(parts[i], "");
							}
						}

					if(onFinalWhat!='')
					{
						onFinalWhat(result)	
					}
					if(targetDiv !=''&& document.getElementById(targetDiv)){
						//alert(result);
						document.getElementById(targetDiv).innerHTML = result;
					}
					
					if(jscode != "")
					{
						var incomingScript = document.createElement('SCRIPT');
						incomingScript.type = 'text/javascript'; 
						incomingScript.lang = 'javascript';
						incomingScript.defer = true;
						incomingScript.text = jscode;
						document.getElementsByTagName('head')[0].appendChild(incomingScript);
					}
				}
				catch(e){}
			  }
			}
		);
	}
	catch(e){}
}
/*
document.observe('dom:loaded', applyPNGHacks);

function applyPNGHacks () {

  $('yourPNG').pngHack();

  $$('div#fixMe', 'img#andMe', 'img.andUsTo').invoke('pngHack');

  $('andMe').up().pngHack();
  
  $('anotherExample').pngHack();

}

function form_submit(){
	document.commentform.submit();
	}*/

function sbmt(){
if(event.keyCode ==13){
	document.loginform.submit();
}
}

function uid_in(){

	if(document.getElementById('user_login').value == 'User ID'){
	document.getElementById('user_login').value = ""
	}
	
}

function uid_out(){

	if(document.getElementById('user_login').value ==''){
	document.getElementById('user_login').value = "User ID"
	}
	
}

function pwd_in(){

	if(document.getElementById('user_pass').value =='Password'){
		document.getElementById('user_pass').value = ""
	}
	
}

function pwd_out(){

	if(document.getElementById('user_pass').value ==''){
		document.getElementById('user_pass').value = "Password"
	}	
}

function check_txt_in(){
	
if(document.getElementById('email').value == 'Enter your e-mail address'){
		
		document.getElementById('email').value ='';
	}
	
	
}
function check_txt_out(){
	
if(document.getElementById('email').value ==''){
		
		document.getElementById('email').value ='Enter your e-mail address';
		
	}
		
}

function echeck(str) {
var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

		 return true					
}


/* ---------------------------- */
/* XMLHTTPRequest Enable 		*/
/* ---------------------------- */

//function to pass the search code value and return output

//Make the XMLHttpRequest Object


function search_by_code(strURL,div) {
	document.getElementById('bt_orr').style.display = "none";
	document.getElementById('load_img').style.display = 'block';
	
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //alert(strURL+getquerystring());
    self.xmlHttpReq.open('GET', strURL+getquerystring(), true);
	
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        	
        }
    }
    self.xmlHttpReq.send(getquerystring());
    
}

function getquerystring() {

    var form    = document.forms['search_form'];
    var scode = form.s_code.value;
	//alert(scode);
	//var search_text = form.search-q.value;
	//var search_text = document.getElementById('s_code').value;
	//alert(search_text);
    qstr = '/includes/search_code.php?s_code=' + scode;  // NOTE: no '?' before querystring
    return qstr;
    
}

function updatepage(str){
	if(isNaN(str)){
		document.location.href = str;
	} else {
	    document.getElementById('search_code').style.display = "block";
	    if(str==0){
		    document.getElementById('search_code').innerHTML = "Invalid code.";
		    document.getElementById('bt_orr').style.display = 'block';
	       	document.getElementById('load_img').style.display = 'none';
		}else if(str==1){
		    document.getElementById('search_code').innerHTML = "You must be logged in to search ICD9 codes.";
		    document.getElementById('bt_orr').style.display = 'block';
	       	document.getElementById('load_img').style.display = 'none';
		}else if(str==2){
		    document.getElementById('search_code').innerHTML = "You must upgrade to search ICD9 codes.";
		    document.getElementById('bt_orr').style.display = 'block';
	       	document.getElementById('load_img').style.display = 'none';
		}
		
		
	}

}





/*********************
//* jQuery Drop Line Menu- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last updated: June 27th, 09'
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/

var droplinemenu={

//arrowimage: {classname: 'downarrowclass', src: 'images/down.gif', leftpadding: 5}, //customize down arrow image
//animateduration: {over: 100, out: 50}, //duration of slide in/ out animation, in milliseconds

arrowimage: {classname: 'downarrowclass', src: '/images/down.gif'}, //customize down arrow image
animateduration: {over: 100, out: 50}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid,uri){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={h:$curobj.find('a:eq(0)').outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			if (!this.istopheader)
				$subul.css({left:0, top:this._dimensions.h})
			var $innerheader=$curobj.children('a').eq(0)
			$innerheader=($innerheader.children().eq(0).is('span'))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that
			$innerheader.append(
				'<img src="'+uri+ droplinemenu.arrowimage.src
				+'" class="' + droplinemenu.arrowimage.classname
				+ '" style="border:0; padding-left: '+droplinemenu.arrowimage.leftpadding+'px" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						if (this.istopheader)
							$targetul.css({left: $mainmenu.offset().left, top: $mainmenu.offset().top+this._dimensions.h})
						if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
							$mainmenu.find('ul').css({overflow: (this.istopheader)? 'hidden' : 'visible'})
						$targetul.slideDown(droplinemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(droplinemenu.animateduration.out)
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible', width:$mainmenu.width()})
	}) //end document.ready
}
}


