sfHover = function() {
//	var sfEls = document.getElementById("country_list").getElementsByTagName("LI");
//	for (var i=0; i<sfEls.length; i++) {
//		sfEls[i].onmouseover=function() {
//			this.className+=" sfhover";
//		}
//		sfEls[i].onmouseout=function() {
//			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//		}
//	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function goToPage(page) {
	document.location.href = page;
}


function ddHighLight(objReference, blOn) {

	var elem = document.getElementById(objReference);
	
	if (blOn) {
		elem.className = "ddCountryOn";
	} else {
		elem.className = "";
	}
	
}

function resetForm() {
	
	document.forms[0].reset();
	
	for (var i=0; i < document.forms[0].elements.length; i++) {
					
		if(document.forms[0].elements[i].type == "select-one") {
			document.forms[0].elements[i].selectedIndex = 0;
		}
		if(document.forms[0].elements[i].type == "text") { 
			document.forms[0].elements[i].value = "";
		}
		if(document.forms[0].elements[i].type == "checkbox") { 
			document.forms[0].elements[i].checked = false;
		}
		if(document.forms[0].elements[i].type == "radio") { 
			document.forms[0].elements[i].checked = false;
		}
		
	}
	
}

function popUpWindow(strURL, intWidth, intHeight) {
	window.open( strURL, "_blank", "status=1, height=" + intHeight + ", width=" + intWidth + ", resizable=1, scrollbars=1, toolbar=1, location=1" )
}
function popUpWindowNoScroll(strURL, intWidth, intHeight) {
	window.open( strURL, "_blank", "status=1, height=" + intHeight + ", width=" + intWidth + ", resizable=0, scrollbars=0, toolbar=0, location=0" )
}

// clickButton() function
// This function is used to make sure the "Enter" key submits the correct form button
// based on which form the focus is on

function clickButton(e, buttonid)
{
    var bt = document.getElementById(buttonid);	
    
    if (typeof bt == 'object')
    {
        if(navigator.appName.indexOf("Netscape")>(-1))
        {
            if (e.keyCode == 13)
            {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
        {
            if (event.keyCode == 13)
            {
				//bt.focus();
                bt.click();
                return false;
            }
        }
    } 
} 

function changeImages(strImageID, strType) {
      if ((document.images) && (changeImages.arguments[0] != '')) {
            for (var i=0; i<2; i+=2) {          
                  strNewImagePath = eval(changeImages.arguments[i+1] + ".src").toString();                      
                  document[changeImages.arguments[i]].src = strNewImagePath;  
            }
      }
}

function readCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
		offset += search.length;
		end = document.cookie.indexOf(";", offset);
		if (end == -1) end = document.cookie.length;
		cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function changeClass(object, style){
    object.setAttribute("class", style);
    object.setAttribute("className", style);
}
function changeSubListClass(id, style,subpage, page,  state){
    document.getElementById(id).className = style;
    document.getElementById('subnavimage'+subpage).src = '/hcp/images/nav/subpage'+page+'-'+subpage+ state +'.gif'
}
function changeListClass(id, style, page, state){
    document.getElementById(id).className = style;
    document.getElementById('navimage'+page).src = '/hcp/images/nav/page'+page+ state +'.gif'
}
function goToPage(url){
	window.location=url;
}

function changeTab(show, hide1 , hide2){
	document.getElementById(show+'cnt').style.display = "inline"
	document.getElementById(hide1+'cnt').style.display = "none"
	document.getElementById(hide2+'cnt').style.display = "none"
	document.getElementById(show).className="tab_on"
	document.getElementById(hide1).className="tab_off"
	document.getElementById(hide2).className="tab_off"							
}

function tabHover(id, hover){
	var currentClassName = ""
	currentClassName = id.className
	if(!(currentClassName == "tab_on")){
		if(hover){
			id.className = "tab_off_over"
		}else {		
				id.className =	"tab_off"				
		}
	}			
}

function menuonstate()
{
	
	var nav5 = document.getElementById('list5');
	var img5 = document.getElementById('navimage5');
	
	nav5.setAttribute("class", "menuListItemIsActive");
	nav5.setAttribute("className", "menuListItemIsActive");
	nav5.setAttribute("onmouseout", "newMouseOutState()");
	img5.setAttribute("src", "/hcp/images/nav/page5_on.gif");
				
	return;
}
function newMouseOutState()
{
	img5.setAttribute("src", "/hcp/images/nav/page5_on.gif");
		
	return;
}


//Javascript for Dr. KK Bio
function onDoctorRollOver()
{
	//showDoctorInfo();
	showDoctorBio();
}
function onDoctorRollOut()
{
	//hideDoctorInfo();
	hideDoctorBio();
}
function showDoctorBio()
{
	//hideDoctorInfo();
	var doctorBio = document.getElementById('doctorBioDiv');
	doctorBio.style.visibility = 'visible';
	
	// For 'click away from div' functionality
	document.addEvent("mousedown", checkThenHide.bind(this));
}
function hideDoctorBio()
{
	var doctorBio = document.getElementById('doctorBioDiv');
	doctorBio.style.visibility = 'hidden';
}
function showDoctorInfo()
{
	var doctorInfo = document.getElementById('doctorBioInfo');
	doctorInfo.style.visibility = 'visible';
}
function hideDoctorInfo()
{
	var doctorInfo = document.getElementById('doctorBioInfo');
	doctorInfo.style.visibility = 'hidden';
}
function checkThenHide(ev) 
{
    ev = new Event(ev); 
    
    if (ev.target.id != 'doctorBioDiv' && ev.target.parentNode.id != 'doctorBioDiv' && ev.target.parentNode.parentNode.id != 'doctorBioDiv' && ev.target.parentNode.parentNode.parentNode.id != 'doctorBioDiv') 
		hideDoctorBio();
}


// Share div js
function openShare()
{
    var viewWidthAndHeight = getWidthAndHeight()
	var viewScrollXY = getScrollXY()
	var mask = 	document.getElementById('share_shadow');
	var popup = document.getElementById('share_site')
		
	mask.style.display = "block";
	mask.style.height = viewWidthAndHeight[1] + "px";
	mask.style.top = viewScrollXY[1] + "px";
	
	popup.style.display = "block";	
	popup.style.top = viewScrollXY[1] + 50 + "px";
	
	document.getElementById('step1').style.display = "block";
	document.getElementById('step2').style.display = "none";
    document.getElementById("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtRecipientEmail").value = "";
    document.getElementById("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtYourEmail").value = "";
    document.getElementById("txtRecipientName").value = "";
    document.getElementById("txtYourName").value = "";
    document.getElementById("l_recipientEmail").className = "norm";
    document.getElementById("l_yourEmail").className = "norm"
    document.getElementById("l_recipientName").className = "norm";
    document.getElementById("l_yourName").className = "norm"
}

function closeShare()
{
    document.getElementById('share_shadow').style.display = "none";
    document.getElementById('share_site').style.display = "none";
}

window.onscroll = checkMask;
window.onresize = checkMask;

function checkMask(){
	var mask = 	document.getElementById('share_shadow');
	var popup = document.getElementById('share_site');
	if (mask) {
		if( mask.style.display == "block") {
		
		    var viewWidthAndHeight = getWidthAndHeight(); // 0 for width 1 for height
		    var viewScrollXY = getScrollXY(); // 0 for X 1 for Y
    		
		    mask.style.top = viewScrollXY[1] + "px";
		    mask.style.height = viewWidthAndHeight[1] + "px";
	    }
	}
}

function getWidthAndHeight(){
    var mask = 	document.getElementById('share_shadow');
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		mask.style.width = myWidth + "px";
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function submitShare()
{
    var bRegistration = validateRegistration()
    var v_form = document.getElementById("step1");
    
    if (!bRegistration)
    {
        error = true;
        v_form.style.display = "block";
        return false;
     }
     
        //alert("to: " + to.value);
        //alert("from: " + from.value);
    
    if (sendToAjax() == "Y"){
        showConfirmShare();
    }
    else { 
        showConfirmShare();
    };
   
}

/* Ajax check */
var request = null;
	try{		
			request = new XMLHttpRequest();			
			}catch (trymicrosoft) {			
			try{			
				request = new ActiveXObject("Msxml2.XMLHTTP");			
			}catch (othermicrosoft) {			
				try{					
					request = new ActiveXObject("Microsoft.XMLHTTP");					
				}catch (failed) {				
					request = null;					
				}
			}
			
		} 
		if (request == null){
			alert("Error: AJAX interaction failed.");
		}
		var sendSuccess = "default";
/* end ajax check */

function sendToAjax() {
    
    var to = document.getElementById("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtRecipientEmail");
    var from = document.getElementById("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtYourEmail");
    var url = "/hcp/controls/email-ajax.aspx?to="+to.value+"&from="+from.value;
    
    request.open("GET", url, false);
	request.onreadystatechange = test2;
	request.send(null);
    
	var sendSuccess = request.responseText;
	sendSuccess = request.responseText;
	//alert(sendSuccess);
	return sendSuccess;
	
}
function test2() {
		if (request.readyState == 4) {
			//alert("inside test2= " +request.responseText);
			sendSuccess = request.responseText;
			//alert("inside test = "+inOrnotInDb);
		}
		else {
		//alert("else");
		}
	}

function showConfirmShare()
{
    //show thank you
    var v_form = document.getElementById("step1");
    if(v_form != null)
    {
        v_form.style.display = "none";
        document.getElementById("step2").style.display = "block";
    }
}

function validateRegistration()
    {
        var totalErrors = 0;
        totalErrors += addError(validateEmailAddress(d("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtRecipientEmail"), "l_recipientEmail"));
        totalErrors += addError(validateEmailAddress(d("_ctl0_plhUtilityNav_Utilbar1_objEmailThisPage_txtYourEmail"), "l_yourEmail"));
        totalErrors += addError(validateName(d("txtYourName"), "l_yourName"));
        totalErrors += addError(validateName(d("txtRecipientName"), "l_recipientName"));

        if (totalErrors == 0)
            return true;        // Everything validated
        else
            return false;       // One or more didn't validate
    }

function addError(test)
    {
        if (test) 
            return 0;
        else
            return 1;
    }

function getValue(myField)
	{
		var myValue = '';
		switch(myField.type)
		{
			case "button" :
			case "text" :
			case "textarea" :
			default : 
				myValue = myField.value;
				break;
		}
		return myValue;
	}

function validateEmailAddress(myField, myLabel)
	{
		var myValue = getValue(myField);
		if ( (isValidEmailAddress(myValue)) && 
			 (hasNoSpaces(myValue)) && 
			 (hasNoCrLf(myValue)) &&
			 (maxLength(myValue,50)) )
		{
            toggleError(myLabel, "norm");
			return true;
		} else {
			toggleError(myLabel, "error_state");
			return false;
		}
	}

function validateName(myField, myLabel)
	{
		var myValue = getValue(myField);
		if ( (isNotNull(myValue)) && 
			 (maxLength(myValue,50)) )
		{
            toggleError(myLabel, "norm");
			return true;
		} else {
			toggleError(myLabel, "error_state");
			return false;
		}
	}
	
	function toggleError(myLabel, myClass)
	{
	    if (d(myLabel))
	    {
	        var el = d(myLabel);
	        el.className = myClass;
	    }
	}
	
	function isNotNull(myText)
	{
		if ( (myText.length > 0) && (trim(myText).length > 0) ) {
			return true;
		} else {
			// alert("Not Null!");
			return false;
		}
	}
	function trim(stringToTrim) {
	    return stringToTrim.replace(/^\s+|\s+$/g,"");
    }
	
	function isValidEmailAddress(myText)
	{
		//var regEmail = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		var regEmail = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
		var regex = new RegExp(regEmail);
		if (!regex.test(myText))
		{
			// alert("E-mail Address Is Not Valid");
			return false;
		}
		return true;
	}
	
	function hasNoSpaces(myText)
	{
		var charpos = myText.search(/\s/); 
		if(myText.length > 0 && charpos >= 0) 
		{		  
			// alert("Space at position " + eval(charpos + 1)); 
			return false; 
		}
		return true;
	}

	function hasNoCrLf(myText)
	{
		var charpos = myText.search(/\r\n/); 
		if(myText.length > 0 && charpos >= 0) 
		{		  
			// alert("Carriage Return or Line Feed at position " + eval(charpos + 1)); 
			return false; 
		}
		return true;
	}
	
	function maxLength(myText,myMaxLength)
	{
		if (myText.length > myMaxLength)
		{
			// alert("More than " + myMaxLength + "!");
			return false;
		} else {
			return true;
		}
	}
	
function d(fieldName)
	{
        var x;
        return (x = document.getElementById(fieldName)) ? x : alert(fieldName + " not found");
    }
