// start platform and browser detection variables
var ie = (document.all) ? true : false;
var ns = (document.layers) ? true : false;
var moz = (document.getElementById && !document.all) ? true : false;

var platform = (navigator.platform.toLowerCase().indexOf("mac") >= 0) ? "mac" : "win";
var browser = (ns) ? "ns" : "ie";
// end browser detection variables


// start common functions
function openReprintWin(page_name) {
	var myWin = window.open("/vorinostat/zolinza/hcp/physician_resources/journal_reprints/"+page_name+".jsp","reprint","width=790,height=600,scrollbars=no,location=no,status=no,resizable=yes")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}
function openguidelineWin(page_name) {
	var myWin = window.open("/vorinostat/zolinza/hcp/shared/"+page_name+".jsp","reprint","width=790,height=600,scrollbars=no,location=no,status=no,resizable=yes")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}
function openPrivacyWin() {
	var myWin = window.open("http://www.merck.com/policy/privacy/home.html","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=477,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openPrivacyWinSpanish() {
	var myWin = window.open("http://www.merck.com/policy/privacy/sp_policy.html","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openPrivacyWinAppendQueryString(queryString) {
	var myWin = window.open("http://www.merck.com/policy/privacy/home.html" + queryString,"Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openPrivacyWinAppendQueryStringSpanish(queryString) {
	var myWin = window.open("http://www.merck.com/policy/privacy/sp_policy.html" + queryString,"Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openPAPWin() {
	var myWin = window.open("http://www.merck.com/program/pap/","Physician","toolbar=no,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,width=760,height=480")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openExternalWin(product, url) {
	if(! confirm("Thank you for visiting " + product + ".com.\n\nMerck does not review or control the content at the site to which this hyperlink connects;\ntherefore, this hyperlink does not constitute an endorsement by Merck of the content of any\nnon-Merck site.\n\nDo you wish to continue?"))
    	return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
    	externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openExternalWinMerckSchering(product, url) {
	if(! confirm("Thank you for visiting " + product + ".com.\n\nMerck/Schering-Plough does not review or control the content at the site to which this\nhyperlink connects; therefore, this hyperlink does not constitute an endorsement by\nMerck/Schering-Plough of the content of any non-Merck/Schering-Plough site.\n\nDo you wish to continue?"))
    	return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
    	externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openExternalWinSpanish(product, url) {
	if(! confirm("¡Gracias por visitar " + product + ".com!\n\nMerck no revisa ni controla el contenido del sitio al que lo llevará este hiperenlace;\npor lo tanto, este hiperenlace no significa que Merck respalde el contenido de cualquier sitio que\nno sea de Merck.\n\n¿Usted desea continuar?"))
    	return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
    	externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openExternalWinMerckScheringSpanish(product, url) {
	if(! confirm("Gracias por visitar " + product + ".com.\n\nMerck/Schering-Plough no analiza ni controla el contenido del sitio al cual lo llevará este hiperenlace.\nPor lo tanto, este hiperenlace no constituye un respaldo de parte de\nMerck/Schering-Plough del contenido de cualquier sitio que no sea de Merck/Schering-Plough.\n\n¿Desea continuar?"))
    	return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
    	externalWin.opener=window;
        externalWin.opener.name="opener";
}

function activate(imgName) {
	if (document.images)
		var last_position = document[imgName].src.lastIndexOf("_");  		
 		if(document[imgName].src.substr(last_position+1,2).toLowerCase().indexOf("on") < 0)
		document[imgName].src = eval("btn_" + imgName + "_over.src");
}

function inactivate(imgName) {
	if (document.images)
		var last_position = document[imgName].src.lastIndexOf("_");  
 		if(document[imgName].src.substr(last_position+1,2).toLowerCase().indexOf("on") < 0)
		document[imgName].src = eval("btn_" + imgName + "_off.src");
}

function openInParentWin(url) {
	parent.opener.location.href=url;
	parent.opener.focus();
	//parent.self.close();
}

function allowSubmission(theForm) {
	return (theForm.redirectPage.selectedIndex > 0);
}
	
function changeParentLocation(url) {
	opener.location.href = url;
	opener.name = "opener";
	opener.focus();
}

function gotoMerck() {
	if (window.name == "Healthcare") //the HCP consent popup
		self.close()
		
	window.open("http://www.merck.com","merck","");
	/*if (opener != null) {
		if (opener.closed) {
			if (window.name == "merck")
				window.name = "main";
			
			window.open("http://www.merck.com","merck","");
		} else {
			opener.location.href="http://www.merck.com"; 
			self.close();
		}
	} else {
		window.location.href="http://www.merck.com";
	}*/
	
	return false;
}

function AttachEvent(obj,evt,fnc,useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else if (obj['on'+evt]){
		//this untested, designed not to whack existing inline code for old browsers
		obj['old_on'+evt]=obj['on'+evt];
		obj['new_on'+evt]=fnc;
		obj['on'+evt]=new Function("this.old_on"+evt+"(); this.new_on"+evt+"();");
	}else obj['on'+evt]=fnc;
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toUTCString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=0";
    }
}

/*
* Busy-wait (pause) for the specified number of milliseconds.
*/
function pause(millisec) {
    var timeNow = new Date();
    var timeDone = timeNow.getTime() + millisec;
    while (true) {
        timeNow = new Date();
        if (timeNow.getTime() > timeDone)
            return;
    }
}

/*
* Generate server-side access log metrics for a simulated page hit.
* Call 'pause' after this if the browser is being redirected to a new page.
*/
function trackPageHit(url) {
    if (document.images) {
        var newImage = new Image;
        newImage.src = url;
        pause(100); // Needed for IE6
    }
}

// end common functions



/************************************************************************************
DESCRIPTION: Change font size of disclaimer text upon selecting state 'TX' or 'CA'

PARAMETERS:
	fname - form name
	textid - Existing css ID or Class of disclaimer text (make sure to remove any font-size from this style.
	******CREATE TWO CLASSES WITH DEFAULT AND LARGE FONT SIZES****
	class1 - Default font size class (normally 12px)
	class2 - Large font size class (normally 14pt)  *make sure its PT not PX	
************************************************************************************/
function changeFontSize(fname,textid,class1,class2) {	
	var i = document[fname].state.selectedIndex; 
	var st = document[fname].state.options[i].value;
	
	if((st=="CA") || (st=="TX")) {
		if (document.getElementById) {
			document.getElementById(textid).className = class2;
			}
	} else {
		if (document.getElementById) {
			document.getElementById(textid).className = class1;
			}
		}
	} 