//
//  last cnahge: 2007_09_06 henning.busacker@logicacmg.com
//
// File   msd_scriptlib.js   
// 
// Purpose: 
// For the use in the health - microsites of www.msd.de
//
// Contents:
// navigation-highlight script
// Respective to the path of a html-page, the highlight-images of the navigation are set
//
// include stylesheet script
// Respective to the browser the right stylesheet is included
var trackurl="http://report.msd.de/MSDdeTrack/track?site=";
//
var productsites=new Array ("asthma","bluthochdruck","cholesterin","gelenkschmerz","migraene","osteoporose","prohaar");
var productsites_text=new Array ("Asthma","Bluthochdruck","Cholesterin","Gelenkschmerz","Migräne","Osteoporose","ProHaar");

// the actual folder-structure
var folderlist=new Array("wissen","tun","aktiv","asthma","sitemap","kontakt","uebermsd", "elternratgeber");
// the logical navigationstructure  (if different from the folderstructure)
var imagelist=new Array( "wissen","tun","aktiv","asthma","meta_sitemap","meta_kontakt","meta_uebermsd", "elternratgeber");
// image-preload arrays
var buttons_in=new Array();
var buttons_out=new Array();
// imagepath
var loc = window.location.pathname;
var gfxsrc= "/images/navi/";

if (window.location.pathname.indexOf("/home.html")==0 || window.location.pathname == '/') {
 gfxsrc = "/images/home/";
} 
// imagetype (gif, jpg, png ...)
var type = "gif";
// highlight extention
var highlight = "_hi";
// the path of the html-file (with folder structure)

var hl_position = -1;
var lastsuperpos = -1;
// Bullets fuer serviceboxen
var outimg = new Image();
outimg.src = "/images/content/hohl_quadrat.gif";
var inimg = new Image();
inimg.src = "/images/content/voll_quadrat.gif";
var trennimg = new Image();
trennimg.src = gfxsrc+"trenner_gewaehlt.gif";

//--------------------------------------------------------------------------------------------------------------------
// set stylesheet
//--------------------------------------------------------------------------------------------------------------------
document.open();
document.write("<LINK rel='stylesheet' type='text/css' href='/css/msd.css'>");
document.close();
//-----------------------------------------------------------------------------------------------------------------
// preload Images
//-----------------------------------------------------------------------------------------------------------------
	for (i=0;i<(imagelist.length);i++){
		buttons_in[i]=new Image();
		buttons_out[i]=new Image();
		buttons_in[i].src=gfxsrc+imagelist[i]+highlight+"."+type;
		buttons_out[i].src=gfxsrc+imagelist[i]+"."+type;
	}
//-----------------------------------------------------------------------------------------------------------------
// highlight
//-----------------------------------------------------------------------------------------------------------------

function loadimages(){
	for (i=0;i<(folderlist.length);i++){
		if (loc.indexOf(folderlist[i]) != -1) {
			hl_position = i;
			if (document.images["button"+i]) {document.images["button"+i].src=buttons_in[i].src}
			if (i==0 || i==1) 
				document.images["trenn1"].src=trennimg.src;
			if (i==1 || i==2) 
				document.images["trenn2"].src=trennimg.src;
			if (i==2 || i==3) 
				document.images["trenn3"].src=trennimg.src;

			return;		  	
		}
	}        
}

function change_over(i){ 
	document.images["button"+i].src=buttons_in[i].src; 
	if ((i != hl_position) && (hl_position!=-1)){
		if (document.images["button"+hl_position]) {
			document.images["button"+hl_position].src=buttons_out[hl_position].src;

		}
	}
} 

function change_out(i){ 
	document.images["button"+i].src=buttons_out[i].src; 
	if (hl_position!=-1 && document.images["button"+hl_position]) {
		document.images["button"+hl_position].src=buttons_in[hl_position].src;
	}
}

//---------------------------------------------------------------------------------------------------------------
// open pop-up window
//---------------------------------------------------------------------------------------------------------------
function open_popup(sUrl,width,heigth,scroll,x,y) {
	sTmp = "width=" + width + ",height=" + heigth + ",scrollbars=" + scroll + ",status=0" + ",left=" + x + ",top=" + y + ",resizable=no";
		
	if(!window.popWin)
	{
		window.popWin = window.open(sUrl,'popup',sTmp);
	}
    else if(window.popWin.closed)
	{
		window.popWin = window.open(sUrl,'popup',sTmp);
	}
    else
    {
		if (window.popWin) window.popWin.close();
		window.popWin = null;             
		window.popWin = window.open(sUrl,'popup',sTmp);
    }
	window.popWin.focus();
}
	
function pic_popup(pic,text,x,y,title,alt,yoffset) {
	var wx=x+20;
	var wy=y+(yoffset?yoffset:86);
	var pop=window.open('about:blank','pic_pop','height='+wy+',width='+wx+',menubar=no,resizable=no,scrollbars=no,status=no');
	pop.document.writeln('<html><head><title>'+title+'</title></head><body marginwidth="10" marginheight="10" topmargin="10" leftmargin="10">');
	pop.document.writeln('<div align="center" valign="top"><img src="'+pic+'" border="0" alt="'+alt+'" width="'+x+'" height="'+y+'"></div>');
	pop.document.writeln('<img src="/images/tab.gif" border="0" alt="" height="8" width="8"><br>');
	pop.document.writeln('<table border="0" width="'+x+'" bgcolor="#dbd9d8" cellspacing="0" cellpadding="4"><tr><td style="background-color:#dbd9d8;font-family:Verdana,Arial,Helvetica;font-size:9px;line-height:12px;color:#000000;">'+text+'</td></tr></table>');
	pop.document.writeln('<img src="/images/tab.gif" border="0" alt="" height="8" width="8"><br>');
	pop.document.writeln('<table border="0" width="'+x+'"><tr><td bgcolor="#ffffff" align="left" width="50%"><a href="javascript:window.print();"><img src="/images/content/drucken_button.gif" border="0"></a></td><td align="right" width="50%"><a href="" onclick="window.close();"><img src="/images/content/schliessen.gif" border="0"></a></td></tr></table>');
	pop.document.writeln('</body></html>');
	pop.document.close();
	pop.focus();
}
//-----------------------------------------------------------
// open search popup window
//-----------------------------------------------------------
function openSearch() {
	targetvalue=encodeURI("/MSDdeSearch/MSDdeSearchServlet");
	colvalue=encodeURI(document.forms.query.col.value);
	qpvalue=encodeURI("+url:"+getProductname()+".msd.de -url:*print.html");
	lavalue=encodeURI(document.forms.query.la.value);
	qtvalue=encodeURI(document.forms.query.qt.value);
	url = targetvalue + "?col=" + colvalue + "&qp=" + qpvalue + "&la=" + lavalue + "&qt=" + qtvalue;
	mywin = window.open(url, 'winsuche', 'width=608,height=550,scrollbars,resizable=yes');
	mywin.focus();
}


function doNothing() {}

function swap_service_on(i) {
	document.images[i].src=inimg.src;
}
function swap_service_off(i) {

	document.images[i].src=outimg.src;
}
//----------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------
function getProductname() {
	host=location.host;
	host=host.replace(/www\./,"");
	host=host.replace(/\.msd\.de/,"");
	host=host.replace(/\.avinci.*/,"");
	host=host.replace(/(msd)?de-ut.merck.com/,"");
	host=host.replace(/asthma\-balance\.de/,"asthma");
	host=host.replace(/(www\.)?(kein-)?erbrechen.*/,"erbrechen");
	return host;
}

function writeProducts() {
	host=getProductname();
	for (i=0;i<productsites.length;i++) {
 		var product=productsites[i];
 		var prodlc=product.toLowerCase();
 		if (prodlc!=host) {
			l=location.host;
			if (l=="www.asthma-balance.de")
				l = "asthma.msd.de";
			if (prodlc=="erbrechen") {
				l = "www.erbrechen-chemo.de";
			}
			else {
				l = l.replace(host,prodlc);
			}
			document.writeln('<option value="'+l+'">'+productsites_text[i]+'</option>');
 		} else {
			productindex=i;
		}
	}	
}
function productChanged(site) {
	if (site) {
		location.href="http://"+site+"/";
 	}
}

//***************************************************************
// Checks cookies out
//***************************************************************
function cookieCheck(name) {
	 if(document.cookie && document.cookie.match(name)) {
		return true;
	 } else {
		return false;
	 }
}


//***************************************************************
// Read cookies
//***************************************************************
function getCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}
//**************************************************************
// Tracking
//**************************************************************
function track_explicit(url) {
	unc=getCookie('unique_visitor');
	if (unc) {
		img=new Image();
		img.src=trackurl+window.location.host+"&url="+url+"&unc="+unc;
	}
}

function msdtrack() {
	i=window.location.search.indexOf("referrer=");
	amp=window.location.search.indexOf("&",i);
	if (amp < 0) { 
 		amp=window.location.search.length;
	}
 	referrer="";
 
	if (i!=-1) {
		referrer="&referrer="+window.location.search.substring(i+9,amp);
	} else {
	 	if ((window.document.referrer != '') && (window.document.referrer.indexOf(window.document.location.host) == -1)) {
			if (window.document.referrer.search(/\.groupinfra\.de|\.dnsalias\.com|\.ua-s\.de|-ut\.merck\.com/) == -1) {
				e=/^http[s]?:\/\/(.*?)\//
				e.exec(window.document.referrer);
				referrer="&referrer="+RegExp.$1;
			}
		}
	}

	unc=getCookie('unique_visitor');
	if (unc) {
		img=new Image();
		img.src=trackurl+window.location.host+"&url="+loc+"&unc="+unc+referrer;
	}
}
// Tracking aufrufen
msdtrack();

	
// Flash-Aufrufe
function flash_popup(path,flash,title,width,height,bgcolor) {
	var base=document.location.protocol+"//"+document.location.host+path+"/";
	var pop=window.open('about:blank','flash_pop','height='+height+',width='+width+',menubar=no,resizable=no,scrollbars=no,status=no');
	pop.document.writeln('<html><head><base href="'+base+'">');
	pop.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'+title+'</title></head><body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" style="padding:0px;background-color:'+bgcolor+'">');
	pop.document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="film" align="middle">');
	pop.document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
	pop.document.writeln('<param name="movie" value="'+flash+'" />');
	pop.document.writeln('<param name="quality" value="high" />');
	pop.document.writeln('<param name="bgcolor" value="'+bgcolor+'" />');
	pop.document.writeln('<embed src="'+flash+'" quality="high" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="film" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	pop.document.writeln('</object>');
	pop.document.writeln('</body></html>');
	pop.document.close();
	pop.focus();
}

// Adobe-Code
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
      case "style":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

