/* -------------------------------------------------------------- 
  
   * Filename:     	globals.js
   * Version:       1.0.0 (2008-01-25) YYYY-MM-DD
   * Website:		http://memory.ucsf.edu
   * Author:		Navdeep, Ranish
   * Description:	Global Javascripts 
   
  
  == SECTIONS: =======================================  
  _assignedImage			Headings
  _dynFont					Dynamic font resizer
  _loadContent				Loads a DIV content inside a JS Popup
  _clientHeight				Gets height of BODY tag
  _banner					Homepage Banner
  _for_Related_Articles		Related Articles Block
  _for_features_block		Features Block
  _for_default_text_size	To assign default text size
  _for_initialize_text_size To get the initial font size on load of the page
  _for_set_cookie			To set a cookie in browser
  _for_get_cookie			To get a cookie in browser
  _for_clinical_block		To handle Next/Prev of clinical staff data in home page
  //_for_init_page			To initialise the Page
  ====================================================
  
*/


//GLOBAL VARS
var http = getXMLHTTPRequest(); //for ajax
var serverURL;
var base;// = "http://central.sourcen.com/ucsf/themes/channel_nine/ucsf_ajax_handler.php"; // server url

var current_staff=1; //to keep track of current visiting staff
var mouseX=0;//to keep track of X and Y of mouse
var mouseY=0;


// _setServerURL
function setServerURL(url)
{
	serverURL=url+"themes/channel_nine/ucsf_ajax_handler.php";	
}

				

// _clientHeight
function clientHeight(){
document.getElementById('greybox').style.height = parseInt(document.getElementById('dummy').clientHeight) + "px";
document.getElementById('greybox').style.width = parseInt(document.getElementById('dummy').clientWidth) + "px";
}


//_random Number
function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

//_assignedImage
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');	
	for (var i = 0; i < elem.length; i++){
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);}	
	return retnode;
};

function fun(j, k){
	var temp = document.getElementsByClassName(j);	
	document.getElementById(k).innerHTML = temp[0].innerHTML
}

//_dynFont
function setTextSize(size) {
	var fontSize=0;
    if(document.getElementsByTagName) {
        var bodyTag = document.getElementsByTagName("body");
        var textsize = document.getElementById('textsize');        
        if(bodyTag && textsize) { 
			fontSize=getCookie('fontSize');	
            switch(size) {
                case "small": 
                    fontSize = .6;
                    break;
                case "medium":
					if(fontSize=="")
                    	fontSize = .75;
					else
					{
						fontSize = parseFloat(fontSize)-0.05; 
					}
                    break;
                case "large": 
                    if(fontSize=="")
						fontSize = 1;
					else
					{
						fontSize = parseFloat(fontSize)+0.05;
					}
                    break;
            }	
			bodyTag.item(0).style.fontSize = fontSize+"em";
            //document.getElementById(size).className += " selected";                        
            setCookie("textsize", size, 365);
			setCookie("fontSize", fontSize, 365);
        }
    }
}
/*kamal*/
//_for_default_text_size
function setDefaultTextSize()
{
	var bodyTag = document.getElementsByTagName("body");
	bodyTag.item(0).style.fontSize = "0.75em";
	setCookie("fontSize", "0.75", 365);
}

//_for_initialize_text_size
function setInitTextSize() {
	var fontSize=0;
	fontSize=getCookie('fontSize');	
	if(fontSize==""){		
		fontSize="0.75em";
		setCookie("fontSize", "0.75", 365);
	}
	//var bodyTag = document.getElementById("dummy");	
	//bodyTag.style.fontSize = fontSize+"em"; 
	var bodyTag = document.getElementsByTagName("body");
	bodyTag.item(0).style.fontSize = fontSize+"em";
}

//_for_set_cookie
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

//_for_get_cookie
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

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)
		   return false
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		  return false
		
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		  return false
	   
	    if (str.indexOf(at,(lat+1))!=-1)
		  return false
	
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	       return false
	
	    if (str.indexOf(dot,(lat+2))==-1)
            return false
        if (str.indexOf(" ")!=-1)
		    return false

         return true					
}
function validateFeedback()
{
	var nm=document.getElementsByName("name");
	//var em=document.getElementById("edit-fmail");
	var em=document.getElementsByName("mail");
	var df=document.getElementsByName("comment");
	var status=false;
	var estatus=true;
	var stat = 0;
	var email='';
	var IE = document.all?true:false;
	
	if(em.length==3)
	  email=em[em.length-1];
	else
	  email=em[1];
	document.getElementsByName("name")[1].style.border="#CFCFCF solid 1px";
	email.style.border="#CFCFCF solid 1px";
	document.getElementsByName("comment")[1].style.border="#CFCFCF solid 1px";
	
	if(nm[1].value==0)
	{
	  document.getElementsByName("name")[1].style.border="red solid 1px";
	  document.getElementById("error_div").innerHTML = "Please fill required fields";
	  stat = 1;
	}
	else
		stat = 0;
	
	if(email.value==0)
	{
	  email.style.border="red solid 1px";
	  document.getElementById("error_div").innerHTML = "Please fill required fields";
	  stat = 1;
	}
	else
	{
	  if (echeck(email.value)==false ){ 	  
		email.style.border="red solid 1px";
	    document.getElementById("error_div").innerHTML = "Please fill required fields";
		estatus=false;
		stat = 1;
	  }
	  else
	   stat = 0;
	}
	
	if(df[1].value==0)
	{
	  document.getElementsByName("comment")[1].style.border="red solid 1px";
	  document.getElementById("error_div").innerHTML = "Please fill required fields";
	  stat = 1;
	}
	else
	  stat = 0;
	
    if(nm[1].value!=0 && email.value!=0 && df[1].value!=0 && estatus==true)
	   status=true;
	return status;
}
function hideflash(summ){
    var myLayer = document.getElementById("slideshow");
    if(summ==1) 
    {
       dis="block";
       document.getElementById("flash_hide").innerHTML='<a href="javascript:hideflash(0);">Hide tips flash cards</a>';
	
    }   
    else
    {
       dis="none";
       document.getElementById("flash_hide").innerHTML='<a href="javascript:hideflash(1);">See tips flash cards</a>';
	
	}
	myLayer.style.display = dis;	
}
//Raghuanth
function hideSummary(summary){
	var myLayer = document.getElementById(summary);	
	myLayer.style.display = 'none';	
}

function hidePopup(summary){
	var myLayer = document.getElementById(summary);	
	myLayer.style.display = 'none';	
}

function getEmailContent(e){
	
	hidePopup("feedback_popup");
	var outerLayer = document.getElementById("outer_popup");	

	//Blocking Error Div
	/*var errorDiv = document.getElementById("email_error");
	errorDiv.innerHTML = " ";
	errorDiv.style.display = "none";*/
	
	var myLayer = document.getElementById("inner_popup");	 
	var formId = document.getElementById("forward-form");	
	var formContents = formId.innerHTML; 

	//formContents = formContents.replace("<input name='op'","<div id='email_error' style='display:none'></div><input name='op'");

	w = parseInt(outerLayer.style.width);
	h = parseInt(outerLayer.style.height);

		if (e != '') {
			if (isIE()) {
				x = e.clientX;				
				browserX = document.body.offsetWidth - 25;
				browserY = document.body.offsetHeight;
				x += document.body.scrollLeft;			
				
				y = (e.clientY + document.documentElement.scrollTop) - 20;

			}
			if (!isIE()) {
				x = e.pageX;
				y = e.pageY - 20; 
				browserX = window.innerWidth;
				browserY = document.height;			
		   }
		}
	
		x1 = x - 30;
		y1 = y + 10;
				
		if (x1 + w > browserX) {			
			x1 = browserX - w;
		}
		
		if(y1 + 410 > browserY)
			y1 = y1 - ((y1 + 410) - browserY);

		outerLayer.style.left = parseInt(x1)+ "px";
		outerLayer.style.top = parseInt(y1) + "px";
		outerLayer.style.display = "block";
	
	myLayer.innerHTML = '<input type="button" name="close" id="close" onclick="javascript:hideSummary(\'outer_popup\');"/><form id="frd-form" name="frd-form" action="'+formId.action+'"  accept-charset="UTF-8" method="post" onsubmit="return validateForward();"> '+formContents+'<div id="email_error" style="display:none"></div></form>';	

}

function validateForward(){
	var msg = "";
	var errorLayer = document.getElementById("email_error");
	var yemail = document.getElementsByName("yemail");
	var yname = document.getElementsByName("yname");
	var message = document.getElementsByName("message");
	var recipients = document.getElementsByName("recipients");
	
	//Resetting  the border color
	recipients[1].style.border="#CFCFCF solid 1px";
	yemail[1].style.border="#CFCFCF solid 1px";
	yname[1].style.border="#CFCFCF solid 1px";
	message[1].style.border="#CFCFCF solid 1px";

	if(recipients[1].value!=0){
		
		var recips = recipients[1].value.replace(/\n/g,",");     //str = str.replace(/find/g,”replace”)
		var arr_rec_enter = recips.split(",");
		
		for(var i=0;i<arr_rec_enter.length;i++){								
				if(arr_rec_enter.length[i]!=0)
					if(!(echeck(arr_rec_enter[i]))){
						msg += "Invalid recipients Email address <br/>";	
							recipients[1].style.border="red solid 1px";
						}
		}		
	}
	else{
		msg += "Invalid recipients Email address <br/>";
		recipients[1].style.border="red solid 1px";
	}

	if(!(echeck(yemail[1].value))){
		msg += "Invalid sender Email address <br/>";
		yemail[1].style.border="red solid 1px";
	}	

	if(yname[1].value == 0){
		msg += "Invalid sender Name <br/>";
		yname[1].style.border="red solid 1px";
	}

	if(message[1].value == 0){
		msg += "Invalid Message <br/>";
		message[1].style.border="red solid 1px";
	}

	
	
	if(msg != ""){
		errorLayer.style.display = "block";
		errorLayer.innerHTML = "Please fill required fields";		
		//errorLayer.innerHTML = msg;	
		return false;
	}
	else{
		errorLayer.innerHTML = "";
		return true;
	}
}

function isIE() {
		return document.all;
}

function isValid(parm) {
 var val = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
 if (parm == "") return false;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function advsearch()
{
	document.getElementById("block-block-22").style.display = "none";
	document.getElementById("block-block-29").style.display="block";
	document.getElementById("edit-filter5").style.display="none";
	
}
function simpsearch()
{
	document.getElementById("block-block-22").style.display = "block";
	document.getElementById("block-block-29").style.display="none";
}
function changeAuthor()
{
	//alert("news");
	var authorDiv=document.getElementsByClassName("field-author-nid");
    var len= authorDiv.length;
	for(var i=1;i<len;i++)
	{
      var authorDiv1=authorDiv[i].childNodes;
	  for(var j=0;j<authorDiv1.length;j++)
	    authorDiv1.replace('/node/','/staff?nid=');
	 //alert(authorDiv1.length);
	}
	
	
}

function showNewsArticle()
{
	var fromDiv =document.getElementsByClassName("articlecontent");
	if(fromDiv.length>0)
	{
		var fromcontents='';
		var popup = document.getElementsByClassName("field-field-publisher");
	    if(popup.length>0)
		{
		  popup[0].style.display = "none";
		  fromcontents='<div class="field-publisher">'+document.getElementsByClassName("field-publisher")[0].innerHTML+'</div>';
		}
	    var author = document.getElementsByClassName("field-field-author");
	    if(author.length>0)
		{
	      author[0].style.display = "none";
		  fromcontents+='<div class="field-author">'+document.getElementsByClassName("field-author")[0].innerHTML+'</div>';
		  var authorDiv=author[0].childNodes;
		  var len= authorDiv[1].childNodes.length;
		  for(var i=0;i<len;i++)
		  {
			  fromcontents= fromcontents.replace('/node/','/staff?nid=');
			  var IE = document.all?true:false;
			  if(IE)
			    fromcontents= fromcontents.replace('/node/','/staff?nid=');
			  
			
		  }
		}
		var volume = document.getElementsByClassName("field-field-volume");
	    if(volume.length>0)  
		{
		  volume[0].style.display = "none";
		  fromcontents+='<div class="field-volume">'+document.getElementsByClassName("field-volume")[0].innerHTML+'</div>';
		}
		var publisherdate = document.getElementsByClassName("field-publisherdate");
	    if(publisherdate.length>0)  
		{
		  publisherdate[0].style.display = "none";
		  fromcontents+=' <div class="field-publisherdate">'+document.getElementsByClassName("field-publisherdate")[0].innerHTML+'</div>';
		}
		var source = document.getElementsByClassName("field-source");
	    if(source.length>0) 
		{
		  source[0].style.display = "none";
		  fromcontents+=' <div class="field-source">'+document.getElementsByClassName("field-source")[0].innerHTML+'</div>';
		}
		var authorcomp = document.getElementsByClassName("field-field-authorcomp");
	    if(authorcomp.length>0)  
		  authorcomp[0].style.display = "none";
		
		
		fromDiv[0].innerHTML=fromcontents;
	}
}
function getFormContentReplace(fromcontents)
{
	    fromcontents= fromcontents.replace("<form", "<form onsubmit='return validateFeedback();'");
	   fromcontents= fromcontents.replace("</div></form>", "<div id='error_div' class='error_div'></div></div></form>");
		
	 
		fromcontents= fromcontents.replace("<label for='edit-homepage'>Homepage: </label>", "");      
		//fromcontents= fromcontents.replace('id="edit-mail"', 'id="edit-fmail"');  
		
		var IE = document.all?true:false;
		if(IE)
		{
		   fromcontents= fromcontents.replace("<FORM", "<FORM onsubmit='return validateFeedback();'");
			fromcontents= fromcontents.replace("</DIV></FORM>", "<div id='error_div' class='error_div'></div></DIV></FORM>");
			 
		    fromcontents= fromcontents.replace("<LABEL for='edit-homepage'>Homepage: </LABEL>", "");      
			
			//fromcontents= fromcontents.replace('id="edit-mail"', 'id="edit-fmail"');  
	    }
	return fromcontents;
}
/*kamal*/

// _loadContent
function getContent(from,to){
	var fromDiv = document.getElementById(from);	
	if(fromDiv)
	{
	    if(from=="comment-form")
		{
		 	fromcontents = fromDiv.parentNode.innerHTML;
			fromcontents=getFormContentReplace(fromcontents);
			
			
		}
		else
		  fromcontents = fromDiv.innerHTML;
	
	}
	else{
		if(document.getElementsByClassName(from)){
			fromDiv = document.getElementsByClassName(from);
			if(fromDiv.length > 0)//kamal
			if(from=="comment-form")
			{
			  fromcontents = fromDiv[0].parentNode.innerHTML;
			  fromcontents=getFormContentReplace(fromcontents);
			    
			}
			else
			  fromcontents = fromDiv[0].innerHTML;	
		
		}
	}
    		
	var toDiv = document.getElementById(to);
	if(toDiv)
	{
		toDiv.innerHTML = fromcontents;
	}
	else{
		toDiv = document.getElementsByClassName(to);
		if(toDiv.length > 0)//kamal
		{
		  toDiv[0].innerHTML = fromcontents;
		}
	}
	
	/*document.getElementById("edit-homepage").style.display = "none";
	var labels=document.getElementsByTagName("label");
	for( i=0; i<labels.length;i++ )
	 if(labels[i].htmlFor==document.getElementById("edit-homepage").id)
	     labels[i].style.display = "none";*/
	
}
function getfeedbackContent(from,to,e){
	
	hideSummary("outer_popup");

	var outerLayer = document.getElementById("feedback_popup");	
	var myLayer = document.getElementById("feedback");	 	
		
	var fromDiv = document.getElementById(from);	
//alert(fromDiv.parentNode.innerHTML);
	if(fromDiv)
	{
	    if(from=="comment-form")
		{
		 	fromcontents = fromDiv.parentNode.innerHTML;
			fromcontents = getFormContentReplace(fromcontents);		
			
		}
		else
		  fromcontents = fromDiv.innerHTML;
	
	}
	else{
		if(document.getElementsByClassName(from)){
			fromDiv = document.getElementsByClassName(from);
			if(fromDiv.length > 0)
			if(from=="comment-form")
			{
			  fromcontents = fromDiv[0].parentNode.innerHTML;
			  fromcontents = getFormContentReplace(fromcontents);
			    
			}
			else
			  fromcontents = fromDiv[0].innerHTML;	
		
		}
	}
    	
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

		if (e != '') {
			if (isIE()) {
				x = e.clientX;
				browserX = document.body.offsetWidth;
				browserY = document.body.offsetHeight;				
				y = (e.clientY + document.documentElement.scrollTop) - 20;				
							
			}
			if (!isIE()) {				
				x = e.pageX;
				y =  e.pageY - 20;				
				browserX = document.body.clientWidth;
				browserY = document.height;
		   }
		}

		
		x1 = x - 30;		
		y1 = y + 10;
		
		
		if (x1 + w > browserX) {
			x1 = browserX - w;
		}
	
		if(y1 + 310 > browserY)
			y1 = y1 - ((y1 + 310) - browserY);

		outerLayer.style.left = parseInt(x1)+ "px";
		outerLayer.style.top = parseInt(y1) + "px";
		outerLayer.style.display = "block";

	//myLayer.innerHTML = '';			
	//myLayer.innerHTML = '<div class="feed-popup-close"><input type="button" name="close" id="close" onclick="javascript:hideSummary(\'feedbackSummary\');"/></div>';	
	myLayer.innerHTML = fromcontents;
	fDiv = document.getElementsByName("homepage")[1];
	fDiv.parentNode.style.display = "none";
	/*document.getElementById("edit-homepage").style.display = "none";
	document.getElementsByName("homepage")[1].style.display = "none";
	var labels=document.getElementsByTagName("label");
	for( i=0; i<labels.length;i++ )
	 if(labels[i].htmlFor==document.getElementById("edit-homepage").id)
	     labels[i].style.display = "none";*/

}

function hidepop(){	
	if(document.getElementById("showDiv")){
		var showbutton = document.getElementById("showDiv");
		var popup = document.getElementsByClassName("greybox");
		popup[0].style.display = "none";	
		showbutton.style.display = "block";
	
	}
	var popup = document.getElementsByClassName("greybox");
	popup[0].style.display = "none";
}

function showpop(){
	var popup = document.getElementsByClassName("greybox");
	popup[0].style.display = "block";
	popup[0].style.left=popup[0].parentNode.offsetLeft+65+"px";
	popup[0].style.top=mouseY;	
}


// _banner
var timer;
var c=1;
var staff_present = 1;
var count;

function changeContent(id)
{
	if(document.getElementById("count"))
	{
		count=document.getElementById("count").value;
		for(var i=1;i<=count;i++)
		{			
			document.getElementById("contentDiv"+i).style.display="none";
			document.getElementById("ahref"+i).parentNode.className="";
		}	
		document.getElementById("contentDiv"+id).style.display="block";
		document.getElementById("ahref"+id).parentNode.className="home_banner_navi_sel";	
		c=id;
	}
	//clearTimeout(timer);
}	
function startBanner()
{			
	
	if(document.getElementById("count"))
	{
		count=document.getElementById("count").value;
		for(var i=1;i<=count;i++)
		{			
			document.getElementById("contentDiv"+i).style.display="none";
			document.getElementById("ahref"+i).parentNode.className="";
		}	
		document.getElementById("contentDiv"+c).style.display="block";	
		document.getElementById("ahref"+c).parentNode.className="home_banner_navi_sel";
		c++;
		if(c>count)		
			c=1;
		timer=setTimeout("startBanner()",20000);
	}
	
	
	//_for_submit_story
	
	if(document.getElementById("webform-client-form-9"))
	{
		var div = document.getElementById("webform-client-form-9").getElementsByTagName("DIV");
		var rep_html="<div class='story_top'>";
		//document.getElementById("webform-client-form-9").innerHTML = div[0].innerHTML;
		rep_html+=div[0].innerHTML+'</div>';
		document.getElementById("webform-client-form-9").innerHTML = rep_html;
		
	}
}
var atimer;
var ac=0;
var anncount;
function ancementHighlight()
{			
		
	if(document.getElementById("anncount"))
	{
		anncount=document.getElementById("anncount").value;
		for(var i=0;i<anncount;i++)
		{			
			document.getElementById("annDiv"+i).style.display="none";
		}
		document.getElementById("annDiv"+ac).style.display="block";	
		ac++;
		if(ac>anncount-1)		
			ac=0;
		atimer=setTimeout("ancementHighlight()",10000);
	}
	
}


var sc=0;
var sscount;
var sc2=0;
var sscount2;
function slideshowHighlight()
{			
  slideshow1Highlight();
  slideshow2Highlight();
}
function slideshow1Highlight()
{
   if(document.getElementById("sscount"))
	{
		sscount=document.getElementById("sscount").value;
		for(var i=0;i<sscount;i++)
		{			
			document.getElementById("slideshow"+i).style.display="none";
			document.getElementById("nav"+i).className="ss_grey";
		}
		document.getElementById("slideshow"+sc).style.display="block";
		document.getElementById("nav"+sc).className="ss_orange";
	}
}
function slideshow2Highlight()
{
   if(document.getElementById("sscount2"))
	{
		sscount2=document.getElementById("sscount2").value;
		for(var i=0;i<sscount2;i++)
		{			
			document.getElementById("slideshow2_"+i).style.display="none";
			document.getElementById("nav2_"+i).className="ss_grey";
		}
		document.getElementById("slideshow2_"+sc2).style.display="block";
		document.getElementById("nav2_"+sc2).className="ss_orange";
	}
}
function goLeft(cid)
{
  if(cid==1)
  {
    if(sc<=0)
      sc=0;
    else
      sc--;
    slideshow1Highlight();
  }
  else
  {
    if(sc2<=0)
      sc2=0;
    else
      sc2--;
	slideshow2Highlight();
  }
  
}
function goRight(cid)
{
  if(cid==1)
  {
    if(sc>=0)
      sc++;
    if(sc>=(sscount-1))
      sc=sscount-1;
    slideshow1Highlight();
  }
  else
  {
    if(sc2>=0)
      sc2++;
    if(sc2>=(sscount2-1))
      sc2=sscount2-1;
    slideshow2Highlight();
  }
 
}

//_Ajax methods - Kamal

function getXMLHTTPRequest() {
	try 
	{
		req = new XMLHttpRequest();
	}
	catch(err1)
	{
	  try 
	  {
	  	req = new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (err2) 
	  {
		try 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (err3) 
		{
		  req = false;
		}
	  }
	}
	return req;
}



function usepushContent() {
   document.getElementById('clinical_staff_name').innerHTML ="";
   document.getElementById('clinical_staff_image').innerHTML ="";
   document.getElementById('clinical_staff_short_desc').innerHTML="";
   document.getElementById('clinical_staff_long_desc').innerHTML="<img src='themes/channel_nine/images/assets/loading.gif'/>";
   document.getElementById('clinical_staff_quote').innerHTML = "";
   document.getElementById('clinical_staff_artical_link').innerHTML ="";
   document.getElementById('clinical_staff_mailto').innerHTML ="";
   if (http.readyState == 4)
   {
   		if(http.status == 200)
		{						
			var clinicalstaff = http.responseXML.getElementsByTagName("clinicalstaff")[0];		
			document.getElementById('clinical_staff_name').innerHTML = clinicalstaff.childNodes[0].childNodes[0].nodeValue;
			document.getElementById('clinical_staff_image').innerHTML = "<img src='files/"+clinicalstaff.childNodes[1].childNodes[0].nodeValue+"'>";
			document.getElementById('clinical_staff_quote').innerHTML = clinicalstaff.childNodes[7].childNodes[0].nodeValue;
			document.getElementById('clinical_staff_long_desc').innerHTML = clinicalstaff.childNodes[3].childNodes[0].nodeValue;
			document.getElementById('clinical_staff_short_desc').innerHTML = '<table cellspadding="0" cellspacing="0" border="0"><tr><td class="short_desc" valign="middle"><p><span class="quotes_left">"</span>'+clinicalstaff.childNodes[2].childNodes[0].nodeValue+'<span class="quotes_right">"</span></p></td></tr></table>';
			if(clinicalstaff.childNodes[5].childNodes[0].nodeValue != "")
				//document.getElementById('clinical_staff_artical_link').innerHTML = '<a href="'+clinicalstaff.childNodes[5].childNodes[0].nodeValue+'">See the articles written by Dr. '+clinicalstaff.childNodes[0].childNodes[0].nodeValue+'</a>';
				document.getElementById('clinical_staff_artical_link').innerHTML = '<a href="'+clinicalstaff.childNodes[5].childNodes[0].nodeValue+'">'+clinicalstaff.childNodes[9].childNodes[0].nodeValue+'</a>';
			else
				document.getElementById('clinical_staff_artical_link').innerHTML = '';
			var str=clinicalstaff.childNodes[0].childNodes[0].nodeValue;
			var s = str.split(",");
			var ss=s[0].replace(" ","&nbsp;");
			ss=ss.replace(" ","&nbsp;");
			document.getElementById('clinical_staff_mailto').innerHTML = '<a onclick=sendMail('+clinicalstaff.childNodes[8].childNodes[0].nodeValue+',"'+clinicalstaff.childNodes[6].childNodes[0].nodeValue+'","'+ss+'",event) href="javascript:void(0);">Send Mail</a>';	
			
    	}
		else
		{
			 
		}
  	} else {
	
  }
}

function usegetRelatedArticles() {     
   var div = "<ul>";
   if (http.readyState == 4)
   {
	   	if(http.status == 200)
		{				 
			 var related_articles = http.responseXML.getElementsByTagName("related_articles")[0];			
			 for(i=0;i<related_articles.childNodes.length;i++)
	    	 {
				    if(i < related_articles.childNodes.length - 1)
	    				div +="<li class='article_"+i+"'>";
					else
						div +="<li style='border:none' class='article_"+i+"'>";
					div +="<div class='view-item view-item-recent-articles'>";
					div +="<div class='view-field view-data-node-title'>";
					div +="<a href='"+base+related_articles.childNodes[i].childNodes[2].childNodes[0].nodeValue+"'>"+related_articles.childNodes[i].childNodes[0].childNodes[0].nodeValue +"</a>";
					div +="</div>";
					div +="<div class='view-field view-data-node-body'>";
					div +="<p>"+related_articles.childNodes[i].childNodes[1].childNodes[0].nodeValue +"</p>";
					div +="</div>";
					div +="<div class='view-field view-data-node-view'>";
					div +="<a href='"+base+related_articles.childNodes[i].childNodes[2].childNodes[0].nodeValue+"'>View</a>";
					div +="</div>";
					div +="</div>";
					div +="</li>";
					//div += related_articles.childNodes[i].childNodes[0].childNodes[0].nodeValue;
	    	 }
			 div +="</ul>";
			 document.getElementById('related_articles').innerHTML = div;
    	}
		else
		{
			 
		}
  	} else {
	
  }
}

//_for Clinical Staff

function pushContent(nid) {	
	//setCookie("clinicalstaffID", nid, 365);
	var  myurl= serverURL+"?method=pushContent&request="+nid;		
	http.open("GET", myurl, true);
	http.onreadystatechange = usepushContent;
	http.send(null);
}

function loadInitContent()
{	
	var staffnodes = document.getElementsByClassName("view-content-clinical-staff");
	if(staffnodes.length!=0)
	{			
		//var id=getCookie('clinicalstaffID');
		//if(id == "")
		//{		
			var h2 = staffnodes[0].getElementsByTagName("H2");
			var idarray = new Array(h2.length);
			for(var i=0;i<h2.length;i++)
			{			
				var anchor = h2[i].getElementsByTagName("A");
				var tokens= anchor[0].href.split("/");	
				idarray[i]=tokens[tokens.length-1];
			}	
			pushContent(idarray[rand(idarray.length)-1]);
			/*var  myurl= serverURL+"?method=pushContent&request="+idarray[rand(idarray.length)-1]+"&rand="+Math.random();	
			http.open("GET", myurl, true);
			http.onreadystatechange = usepushContent;
			http.send(null);*/			
		/*}
		else
		{
			pushContent(id);
		}*/
	}
}

//_for_Related_Articles
function getRelatedArticles(){	
	var param="";
	if(document.getElementById("related_articles"))
	{		
		try
		{
			 var classcontent = document.getElementsByClassName("field-field-related-articles-from-art"); 
			 var classdivs = classcontent[0].getElementsByTagName("DIV");
			 var fielddivs = classdivs[1].getElementsByTagName("DIV");
			 for(var i=0;i<fielddivs.length;i++)
			 {
				var anchor = fielddivs[i].getElementsByTagName("A");
				var tokens= anchor[0].href.split("/");	
				if(param == "")
				{
					param = tokens[tokens.length-1];
				}
				else
				{
					param = param+"|"+tokens[tokens.length-1];
				}			
			 }				 
			 
			 var  myurl= serverURL+"?method=getRelatedArticles&request="+param;	
			 http.open("GET", myurl, true);
			 http.onreadystatechange = usegetRelatedArticles;
			 http.send(null);
		}
		catch(err){		
			if(document.getElementById("block-block-6"))
				document.getElementById("block-block-6").style.display="none";
		} 
		if(param=="")
		{
			if(document.getElementById("block-block-6"))
				document.getElementById("block-block-6").style.display="none";
		}
	}
}
//ajax-end - Kamal

//_for_clinical_block

function staff_prev()
{
	document.getElementById('home_next').innerHTML='<a href="javascript:void(0);" onclick="staff_next();" class="active">Next</a>';
	var staffs = document.getElementsByClassName("home_clinical_block");
	if(current_staff > 1)
	{
		for(var i=1;i<=staffs.length;i++)
		{
			document.getElementById('home_clinical_'+i).style.display="none";
		}		
		current_staff--;
		document.getElementById('home_clinical_'+current_staff).style.display="block";
		document.getElementById('home_no_of_staff').innerHTML= current_staff +" of "+staffs.length;
	}
	if(current_staff == 1)
	{
		document.getElementById('home_prev').innerHTML='<a href="javascript:void(0);" onclick="staff_prev();" class="inactive">Previous</a>';
	}
	else
	{
		document.getElementById('home_prev').innerHTML='<a href="javascript:void(0);" onclick="staff_prev();" class="active">Previous</a>';
	}	
}

function staff_next()
{
	//alert(current_staff);
	if(current_staff != 0)
		document.getElementById('home_prev').innerHTML='<a href="javascript:void(0);" onclick="staff_prev();" class="active">Previous</a>';
	else
		document.getElementById('home_prev').innerHTML='<a href="javascript:void(0);" onclick="staff_prev();" class="inactive">Previous</a>';
		
	var staffs = document.getElementsByClassName("home_clinical_block");
	if(current_staff < staffs.length)
	{
		
		for(var i=1;i<=staffs.length;i++)
		{
			document.getElementById('home_clinical_'+i).style.display="none";
		}		
		current_staff++;
		document.getElementById('home_clinical_'+current_staff).style.display="block";
		document.getElementById('home_no_of_staff').innerHTML= current_staff +" of "+staffs.length;
	}	
	if(current_staff == staffs.length)
	{
		document.getElementById('home_next').innerHTML='<a href="javascript:void(0);" onclick="staff_next();" class="inactive">Next</a>';
	}
	else
	{
		document.getElementById('home_next').innerHTML='<a href="javascript:void(0);" onclick="staff_next();" class="active">Next</a>';
	}	
}

//_for_staff_mailing

/*for tracking the mouse events*/
var http_mail = getXMLHTTPRequest(); //for ajax
var http_features = getXMLHTTPRequest(); //for ajax
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEDOWN)
document.onmousedown = getMouseXY;	
function getMouseXY(e) {

  if (IE) { // grab the x-y pos.s if browser is IE
	mouseX = event.clientX + document.body.scrollLeft;
	mouseY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
	mouseX = e.pageX;
	mouseY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  
  return true
}

function sendMail(nid,email,name,e){	
    var myLayer = document.getElementById("staff_mail_popup");
	

	//document.getElementById('button_div').innerHTML='<input type="button" value="" onclick="sendStaffMail();" class="send"/>';

	document.getElementById("mail_email").style.border="#CFCFCF solid 1px";
	document.getElementById("mail_name").style.border="#CFCFCF solid 1px";
	document.getElementById("mail_comments").style.border="#CFCFCF solid 1px";
	document.getElementById("mail_email").value ="";
	document.getElementById("mail_name").value="";
	document.getElementById("mail_comments").value="";
	document.getElementById("error_div").innerHTML = "";
	document.getElementById("staff_mail_popup").style.display="none";
	
	/*document.getElementById("staff_mail_popup").style.left=document.getElementById("sendmail_href").parentNode.offsetLeft+65+"px";
	document.getElementById("staff_mail_popup").style.top=mouseY-350+"px";
	document.getElementById("staff_mail_popup").style.display="block";
	*/

	document.getElementById("mail_nid").value = nid;
	document.getElementById("mail_to").value = email;
	document.getElementById("doct_name").innerHTML = "Your comments for  "+name;  
	
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

		if (e != '') {
			if (isIE()) {
				x = e.clientX;				
				browserX = document.body.offsetWidth - 25;
				x += document.body.scrollLeft;			
				
				y = (e.clientY + document.documentElement.scrollTop) - 20;

			}
			if (!isIE()) {
				x = e.pageX;
				y = e.pageY; 
				browserX = window.innerWidth;
		   }
		}
		
		x1 = x + 10;		
		y1 = y + 10;
		
		
		if (x1 + w > browserX) {
			x1 = browserX - w;
		}		
		myLayer.style.left = parseInt(x1)-30+ "px";
		myLayer.style.top = parseInt(y1)- 410+ "px";
		document.getElementById("staff_mail_popup").style.display="block";
}

function sendStaffMail()
{
	var nid=document.getElementById("mail_nid").value;
	var to=document.getElementById("mail_to").value;
	var from_email=document.getElementById("mail_email").value;
	var from_name=document.getElementById("mail_name").value;
	var message=document.getElementById("mail_comments").value;
	
	var stat = 0;
	
	document.getElementById("mail_email").style.border="#CFCFCF solid 1px";
	document.getElementById("mail_name").style.border="#CFCFCF solid 1px";
	document.getElementById("mail_comments").style.border="#CFCFCF solid 1px";
	
	if(message=="")
	{
		document.getElementById("mail_comments").style.border="red solid 1px";
		document.getElementById("error_div").innerHTML = "Please fill required fields";
		stat = 1;
	}
	else
		stat = 0;
	if(from_name=="")
	{
		document.getElementById("mail_name").style.border="red solid 1px";
		document.getElementById("error_div").innerHTML = "Please fill required fields";
		stat = 1;
	}
	else
		stat = 0;
	if(from_email=="")
	{		
		document.getElementById("mail_email").style.border="red solid 1px";
		document.getElementById("error_div").innerHTML = "Please fill required fields";
		stat = 1;
	}
	else
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(from_email)){
			stat = 0;
		}else{
			document.getElementById("error_div").innerHTML = "Please enter valid email";
			document.getElementById("mail_email").style.border="red solid 1px";
			stat = 1;
		}
	}
	
	
	if(stat==0)
	{
		var  myurl= serverURL+"?method=sendStaffMail&nid="+nid+"&to="+to+"&from_email="+from_email+"&from_name="+from_name+"&message="+message;	
		http_mail.open("GET", myurl, true);
		http_mail.onreadystatechange = usesendMail;
		http_mail.send(null);
	}
}

function usesendMail() {  
	document.getElementById('error_div').innerHTML="<img src='themes/channel_nine/images/assets/sending_mail_process.gif'/>";
   if (http_mail.readyState == 4)
   {
   		if(http_mail.status == 200)
		{				 
			 var mail_status = http_mail.responseXML.getElementsByTagName("mail_status")[0];
			 document.getElementById('button_div').innerHTML='<input type="button" value="" onclick="close_staff_popup();" class="close"/>';
			 if(mail_status.childNodes[0].childNodes[0].nodeValue == 1)
			 	 document.getElementById('error_div').innerHTML="<div class='success'>Mail Sent Successfully</div>";
			 else
			 	document.getElementById('error_div').innerHTML="<div class='failure'>Mail Delivery Failed</div>";		 
    	}
		else
		{
			 
		}
  	} else {
	
  }
}

function close_staff_popup()
{
	document.getElementById("staff_mail_popup").style.display="none";
}


//_for_features_block
function usegetFeatures() {     
   var div = "<ul>";
   if (http_features.readyState == 4)
   {
   		if(http_features.status == 200)
		{				 
			 var features = http_features.responseXML.getElementsByTagName("features")[0];			
			 for(i=0;i<features.childNodes.length;i++)
	    	 {
				    if(i < features.childNodes.length - 1)
	    				div +="<li>";
					else
						div +="<li style='border:none'>";
						
					div +="<div class='view-item view-item-recent-articles'>";
					div +="<div class='view-field view-data-node-title'>";
					if(features.childNodes[i].childNodes[2].childNodes[0].nodeValue!="#")
					div +="<a href='"+base+features.childNodes[i].childNodes[2].childNodes[0].nodeValue+"'>"+features.childNodes[i].childNodes[0].childNodes[0].nodeValue +"</a>";
					else
						div +="<span>"+features.childNodes[i].childNodes[0].childNodes[0].nodeValue +"</span>";
					div +="</div>";
					div +="<div class='view-field view-data-node-body'>";
					div +="<p>"+features.childNodes[i].childNodes[1].childNodes[0].nodeValue +"</p>";
					div +="</div>";
					div +="<div class='view-field view-data-node-view'>";
					if(features.childNodes[i].childNodes[2].childNodes[0].nodeValue!="#")
					div +="<a href='"+base+features.childNodes[i].childNodes[2].childNodes[0].nodeValue+"'>View</a>";
					
					var link = features.childNodes[i].childNodes[4].childNodes[0].nodeValue;
					if(features.childNodes[i].childNodes[3].childNodes[0].nodeValue!="#")
					{
						if(link!='#')
							div+="<div class='mike_img'><a href='"+features.childNodes[i].childNodes[4].childNodes[0].nodeValue+"'>";						
						div +="<img align='center' src = '"+base+"files/article/"+features.childNodes[i].childNodes[3].childNodes[0].nodeValue+"'/>";
						if(link!='#')
							div+="</a></div>";
					}
					div +="</div>";
					div +="</div>";
					div +="</li>";
	    	 }
			 div +="</ul>";
			 document.getElementById('feature_articles').innerHTML = div;
    	}
		else
		{
			 
		}
  	} else {
	
  }
  
  
}

function getFeatures(){	
	var param="";
	if(document.getElementById("feature_articles"))
	{
		try
		{
			 var classcontent = document.getElementsByClassName("field-field-features"); 
			 var classdivs = classcontent[0].getElementsByTagName("DIV");
			 var fielddivs = classdivs[1].getElementsByTagName("DIV");
			 for(var i=0;i<fielddivs.length;i++)
			 {
				var anchor = fielddivs[i].getElementsByTagName("A");
				var tokens= anchor[0].href.split("/");	
				if(param == "")
				{
					param = tokens[tokens.length-1];
				}
				else
				{
					param = param+"|"+tokens[tokens.length-1];
				}			
			 }		
			 var  myurl= serverURL+"?method=getFeatures&request="+param;	
			 http_features.open("GET", myurl, true);
			 http_features.onreadystatechange = usegetFeatures;
			 http_features.send(null);
		}
		catch(err){		
			if(document.getElementById("block-block-16"))
				document.getElementById("block-block-16").style.display="none";
		} 
		if(param=="")
		{
			if(document.getElementById("block-block-16"))
				document.getElementById("block-block-16").style.display="none";
		}
	}
}


//_for_init_page
function init(url,baseurl){
	var fontSize="";	
	fontSize=getCookie('fontSize');	
	if(fontSize==""){		
		fontSize="0.75em";
		setCookie("fontSize", "0.75", 365);
	}
	if(document.getElementById("block-block-29"))// block for advanced search
		document.getElementById("block-block-29").style.display="none";
	
	if(document.getElementsByClassName("view-custom-search"))//in custom search view
	   if(document.getElementById("views-filters"))// filed in advanced search block
		 document.getElementById("views-filters").style.display="none";	
	 		
	base=baseurl;
	
	setServerURL(url);	
	startBanner();
	getRelatedArticles();
	getFeatures();
	clientHeight();
	ancementHighlight();
	showNewsArticle();
	slideshowHighlight();
	hidepop();
	resizeBookNav();
	staffImgResize();
	newsletter();
	forwardError();
	startStaffshow();

	/*if(document.getElementById("video_li_0"))
		document.getElementById("video_li_0").style.display="none";*/
	if(document.getElementById("edit-submitted-phone"))
	{
		document.getElementById("edit-submitted-phone").parentNode.innerHTML+="<span>(optional)</span>";
	}
	if(document.getElementById("edit-submitted-name"))
	{
		document.getElementById("edit-submitted-name").parentNode.innerHTML+="<span>(optional)</span>";
	}
	setInitTextSize();	
}

function startStaffshow()
{
	if(document.getElementById("block-block-8"))
	{
		var staffs = document.getElementsByClassName("home_clinical_block");
		if(current_staff > staffs.length-1)		
			current_staff=0;
		staff_next();
		staff_timer=setTimeout("startStaffshow()",20000);
	}
}



function staffImgResize()
{
	var sta = document.getElementsByClassName("view-content-clinical-staff");
	if(sta.length>0)
	{
		var imgs = document.getElementsByClassName("view-content-clinical-staff")[0].getElementsByTagName("IMG");
		for(var i=0;i<imgs.length;i++)
		{
			imgs[i].style.width="116px";
			imgs[i].style.height="80px";
		}	
	}
}

function resizeBookNav(){
	if(document.getElementById("block-block-4"))
	{
		var ul = document.getElementById("block-block-4").getElementsByTagName("UL")[0];
		var li = ul.getElementsByTagName("LI");
		if(li.length > 10)
		{
			var oldHTML='';
			for(var i=0;i<6;i++)
			{
				oldHTML+='<li class="leaf">'+li[i].innerHTML+'</li>';
			}			
			
			
			var newHTML='<ul class="menu">';
			for(var i=6;i<li.length;i++)
			{
				newHTML+='<li class="leaf">'+li[i].innerHTML+'</li>';
			}						
			newHTML+='</ul>';
			
			document.getElementById("accomp_img").innerHTML=newHTML;
			ul.innerHTML=oldHTML;
		}		
	}
}
function initURLs(url,baseurl){
	base=baseurl;
	setServerURL(url);
}

//Raghunath
function newsletter(){
	var sta = document.getElementsByClassName("view-content-Matters");
	if(sta.length>0)
	{
		var ul = sta[0].getElementsByTagName("UL");
		if(ul.length>0){
		  var li = ul[0].getElementsByTagName("LI");
		  li[li.length-1].style.border="none";
		}
	}

}

function forwardError(){
	var sta = document.getElementsByClassName("messages error");
	if(sta.length>0){
		sta.style.visibility = "hidden";
	}
}
