/*   TOP HEADER
--------------------------------------- */
function initTopNav()
{ 
  $('.dropdownDiv').each(function () {	
	  $(this).parent().eq(0).hover(
		  function () {
			  var curDropdown = $('.dropdownDiv:eq(0)', this);		
			  curDropdown.clearQueue();
			  curDropdown.css("opacity", 0);
			  curDropdown.css("marginTop", 4);
			  curDropdown.animate({
				  marginTop: 0,
				  opacity: 1
			  }, 300 );
		  },
		  function () {}
	  );
  });
}

var isLangDropdownOpen = false;
var langHideTimer;

function langSelectClick(){
	if(isLangDropdownOpen == false){
		isLangDropdownOpen = true;
		$('#langDrop').hide();
		$('#langDrop').fadeIn(400);
	}else{
		isLangDropdownOpen = false;
		clearTimeout(langHideTimer);
		hideLangDropdown();
	}
}

function langSelectMouseOut(str){
	langHideTimer=setTimeout("hideLangDropdown()",450);
}

function langSelectMouseOver(){
	clearTimeout(langHideTimer);
}

function hideLangDropdown(){
	isLangDropdownOpen = false;
	$('#langDrop').fadeOut(400);
}


function SetCountryLanguange(aCountryCd, aLocaleType)
{
  var timeStampDate = new Date();
  var isSecure = false;
  if(document.location.href.substring(0,6).toLowerCase() == "https:"){
    isSecure = true;
  }
  var domain = "";
  if(window.location.hostname == "my.localhost.com")
    domain = "my.localhost.com"
  else if (window.location.hostname == "localhost")
    domain = "";
  else
    domain = ".yorhealth.com";
    
  createCookieFullDetail("YHCountry", "CountryCd=" + aCountryCd + "&Timestamp=" + timeStampDate.getTime(), 60, "/", domain, isSecure);
  createCookieFullDetail("YHLocale", "LocaleType=" + aLocaleType + "&Timestamp=" + timeStampDate.getTime(), 60, "/", domain, isSecure);
  return true;
}


	
	
/*   COOKIES
--------------------------------------- */
function createCookie(c_name,value,days)
{
  if(document.location.href.substring(0,6).toLowerCase() == "https:"){
    createCookieFullDetail(c_name,value,days,"/","",true);
  }else{
    createCookieFullDetail(c_name,value,days,"/","",false);
  }	
}

function createCookieFullDetail(c_name,value,days,path,domain,isSecure)
{
  var expires = "";
  var secureStr = "";
  value = escape(value);
	if (days) {
	  var exdate = new Date();
		exdate.setTime(exdate.getTime()+(days*24*60*60*1000));
		value += (exdate==null) ? "" : "; expires="+exdate.toGMTString();
	}
	if(isSecure){
	  secureStr = "; secure";
	}
	
	var cookieStr = c_name + "=" + value + "; path=" + path + "; domain=" + domain + secureStr;
	document.cookie = cookieStr;
}

function readCookie(c_name) {
	var c_nameEQ = c_name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(c_nameEQ) == 0) return c.substring(c_nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(c_name) {
	createCookie(c_name,"",-1);
}

function validateNumericKeypress(evt)
{
  var charCode = (evt.which) ? evt.which : event.keyCode
  
  if (charCode > 31 && (charCode < 48 || charCode > 57)){
    return false;
  }

  return true;
}



/*   MISC
--------------------------------------- */
function GetPage(){
  return window.location.href;
}

//returns http://www.yorhealth.com/ or http://beta.www.yorhealth.com/ or http://localhost:9999/
function getDomainUrl(){
  var url = window.location.href;
  var splitArr = url.split("/");
  url = ""
  for (n = 0; n <= 2; n++) {
  	url += splitArr[n] + "/";
  }
  return url;
}


/* SWF Utility */
function GetPage(){
  return window.location.href;
}

function getFlexApp(){
	return document.getElementById(SWFID);
}


function ResizeApp(newHeight){
  getFlexApp().style.height = newHeight + "px";
}
