var enableHeaderAccordian = false;

var objURL = new Object();
window.location.search.replace(
	new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
	function( $0, $1, $2, $3 ){
		objURL[ $1 ] = $3;
	}
);

for (var strKey in objURL){
	if(strKey == "hsi_domain")
	{
		setCookie(strKey, unescape(objURL[ strKey ]), 30);
	}
	if(strKey == "hsi_locale")
	{
		setCookie(strKey, unescape(objURL[ strKey ]), 30);
	}
}

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())
}

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 jumpto_CountrySelector()
{
	var redirectUrl = "http://{domain}/{locale}/CountrySelector.aspx";

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);

	BrowseWindow(redirectUrl, 1, '_new', '490', '602');
}

function jumpto_ContactUs()
{
	var redirectUrl = "http://{domain}/{locale}/Contact.aspx";

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);

	location.href = redirectUrl;
}

function jumpto_DivisionHomePage(division)
{
	var redirectUrl = "http://{domain}/{locale}/{division}.aspx"

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	var hsiDivision = ((division=="") ? "Dental" : division);

	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);
	redirectUrl = redirectUrl.replace( new RegExp( "{division}", "g" ), hsiDivision);

	location.href = redirectUrl;
}

function jumpto_CorporateSub(filename)
{
	var redirectUrl = "http://www.henryschein.com/us-en/Corporate/{filename}?hsi_domain={domain}&hsi_locale={locale}";
	
	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	redirectUrl = redirectUrl.replace( new RegExp( "{filename}", "g" ), filename);
	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);

	location.href = redirectUrl;
}

function jumpto_InvestorPresentation()
{
	// This is not domain/locale specific.
	// It is in this file so that we can update the URL if the filename changes.
	var redirectUrl = "http://www.henryschein.com/us-en/images/corporate/2008IRPresentation_Final.pdf";
	BrowseWindow(redirectUrl, 1, '_new', '490', '602');
}

function jumpto_PrivacyStatement()
{
	var redirectUrl = "http://{domain}/redirect.aspx?did=corporate&amp;returnurl=/{locale}/Privacy.aspx?PageType=popup";
	
	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);
	
	BrowseWindow(redirectUrl, 1, '_new', '490', '602');
}

function jumpto_GlobalHome()
{
	var redirectUrl = "http://{domain}/{locale}/Global.aspx"

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);

	location.href = redirectUrl;
}

function jumpto_SiteMap(division)
{
	var redirectUrl = "http://{domain}/redirect.aspx?did={division}&amp;returnurl=/{locale}/{division}/SiteMap.aspx"

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	var hsiDivision = ((division=="") ? "Dental" : division);

	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);
	redirectUrl = redirectUrl.replace( new RegExp( "{division}", "g" ), hsiDivision);

	location.href = redirectUrl;
}

function countryNameFromLocale(hsi_locale)
{
	switch(hsi_locale)
	{
		case 'us-en':
			return 'United States';
			break;
		case 'us-es':
			return 'United States';
			break;
		case 'ca-en':
			return 'Canada';
			break;
		case 'ca-fr':
			return 'Canada';
			break;
		case 'be-fr':
			return 'Belgium';
			break;
		case 'be-nl':
			return 'Belgium';
			break;
		case 'nl-nl':
			return 'Netherlands';
			break;
		case 'gb-en':
			return 'Great Britain';
			break;
		case 'ie-en':
			return 'Ireland';
			break;
		default:
			return 'United States';
			break;
	}
}

function setSiteMapLinksVisibility(hsi_locale)
{	
	var myObj = document.getElementById('SiteMapLinks');
	if (myObj != null)
	{
		if (hsi_locale == '' || hsi_locale == 'us-en' || hsi_locale == 'us-es')
		{
			myObj.style.display = '';
		}
	}
}

function sendMeHome(division)
{
	var redirectUrl = "http://{domain}/{locale}/{division}.aspx"

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	var hsiDivision = ((division=="") ? "Dental" : division);

	redirectUrl = redirectUrl.replace( new RegExp( "{domain}", "g" ), hsiDomain);
	redirectUrl = redirectUrl.replace( new RegExp( "{locale}", "g" ), hsiLocale);
	redirectUrl = redirectUrl.replace( new RegExp( "{division}", "g" ), hsiDivision);

	location.href = redirectUrl;
}

$(document).ready(function(e) {

	var hsiDomain = ((getCookie("hsi_domain")=="") ? "www.henryschein.com" : getCookie("hsi_domain"));
	var hsiLocale = ((getCookie("hsi_locale")=="") ? "us-en" : getCookie("hsi_locale"));
	
	if (hsiDomain == "www.henryschein.com" || hsiDomain == "www.eschein.com" || hsiDomain == "us.qa.eschein.com")
	{
	
    
    //fix for browser history back which cause colorbox url broken
    var iframeFlag=true;
    if($.browser.msie) iframeFlag=false;
    
		$('a.Dental_Landing').click(function(e) {
			e.preventDefault();
			$.fn.colorbox({href:'http://' + hsiDomain + '/' + hsiLocale + '/Dental.aspx?divisionid=Dental', open:true,width:"850px", height:"500px", iframe:iframeFlag});
		});

		$('a.Medical_Landing').click(function(e) {
			e.preventDefault();
			$.fn.colorbox({href:'http://' + hsiDomain + '/' + hsiLocale + '/Medical.aspx', open:true,width:"850px", height:"500px", iframe:iframeFlag});
		});

		$('a.Veterinary_Landing').click(function(e) {
			e.preventDefault();
			$.fn.colorbox({href:'http://' + hsiDomain + '/' + hsiLocale + '/Veterinary.aspx', open:true,width:"850px", height:"500px", iframe:iframeFlag});
		});
	
	} else {
	
		$('a.Dental_Landing').click(function(e) {
			e.preventDefault();
			jumpto_DivisionHomePage('Dental');
		});
		
		$('a.Medical_Landing').click(function(e) {
			e.preventDefault();
			jumpto_DivisionHomePage('Medical');
		});
		
		$('a.Veterinary_Landing').click(function(e) {
			e.preventDefault();
			jumpto_DivisionHomePage('Veterinary');
		});
		
	}

});
