﻿//window.onbeforeunload = function () {
//    for(i=0;i<wtTrackArray.length;i++){
//        
//    }
// alert(wtTrackArray[0][1]);
//};
//window.onunload=function(evt){
//alert("opera");
//};

//Browser detection Start
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = '';
var fullVersion  = 0; 
var majorVersion = 0;
var isFF3 = false;

// In Internet Explorer, the true version is after "MSIE" in userAgent
if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName  = "Microsoft Internet Explorer";
 fullVersion  = parseFloat(nAgt.substring(verOffset+5));
 majorVersion = parseInt(''+fullVersion);
}

// In Opera, the true version is after "Opera" 
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName  = "Microsoft Internet Explorer";
 fullVersion  = parseFloat(nAgt.substring(verOffset+6));
 majorVersion = parseInt(''+fullVersion);
}

// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName  = nAgt.substring(nameOffset,verOffset);
 fullVersion  = parseFloat(nAgt.substring(verOffset+1));
 if (!isNaN(fullVersion)) majorVersion = parseInt(''+fullVersion);
 else {fullVersion  = 0; majorVersion = 0;}
}

// Finally, if no name and/or no version detected from userAgent...
if (browserName.toLowerCase() == browserName.toUpperCase()
 || fullVersion==0 || majorVersion == 0 )
{
 browserName  = navigator.appName;
 fullVersion  = parseFloat(nVer);
 majorVersion = parseInt(nVer);
}
//FF3
if(browserName=="Firefox" && majorVersion=="3"){
    isFF3 = true;
}
//Browser detection End

//wtTrackArray Start
var wtTrackArray = new Array();
//wtTrackArray End

if (!window.Silverlight) 
		Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
    return function() {
	    return method.apply(instance, arguments);
    }
}

//Create Ext js File in Head
function createExtJS(js_url)
{
    var newJSExtFile = document.createElement("script");
    newJSExtFile.type="text/javascript";
    newJSExtFile.src=js_url;
    document.getElementsByTagName("HEAD")[0].appendChild(newJSExtFile);
}

//TOC Menu
var menuids=["mainmenudiv1"]; //Enter id(s) UL menus, separated by commas

function buildsubmenus(){
    for (var i=0; i<menuids.length; i++){
        if(document.getElementById(menuids[i])!=null){
            var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
            var test = ultags.childElements;        
            for (var t=0; t<ultags.length; t++){
                ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle";
	            if (ultags[t].parentNode.parentNode.id==menuids[i])
		            ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px"
	            else

                    ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
                    ultags[t].parentNode.onmouseover=function(){
                        this.getElementsByTagName("ul")[0].style.display="block";
                    }
                    ultags[t].parentNode.onmouseout=function(){
                        this.getElementsByTagName("ul")[0].style.display="none";
                    }
            }
            for (var t=ultags.length-1; t>-1; t--){
                ultags[t].style.visibility="visible";
                ultags[t].style.display="none";
            }
        }
    }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)
//TOC Menu End


//Home Tabs 3
var Home_Tabs = Class.create
(
	{
		initialize:function(type,mailtostr)
		{
		    document.getElementById("tab3_box_2_cpy").style.display="none";
            document.getElementById("tab3_box_3_cpy").style.display="none";
            document.getElementById("tab3_active").style.backgroundImage="url(/germany/dynamics/_global/templates/img/tab3_top_1.jpg)";
            var url = pageUrl;
            var dynmicshome = "http://www.microsoft.com/germany/dynamics";
            var hometabprefix = "/tabs/";

            var title="";
            Event.observe("tab3_box_1_top_a", 'click', function(){
                var tmpurl = "";
                title = document.getElementById("tab3_box_1_top_a").firstChild.innerHTML.strip();
                tmpurl = "/germany/dynamics" + hometabprefix + title;
                //alert("WT Link-Tracking:\n\nTitle: " + title + "\nURL: " + tmpurl + "\nChannel: " + WtChannel);
                dcsMultiTrack('DCS.dcsuri', tmpurl, 'WT.ti', title, 'WT.sp', WtChannel,'WT.dl','1');
                document.getElementById("tab3_box_1_cpy").style.display = "block";
                document.getElementById("tab3_box_2_cpy").style.display = "none";
                document.getElementById("tab3_box_3_cpy").style.display = "none";
                document.getElementById("tab3_active").style.backgroundImage="url(/germany/dynamics/_global/templates/img/tab3_top_1.jpg)";
            });
            Event.observe("tab3_box_2_top_a", 'click', function(){
                var tmpurl = "";
                title = document.getElementById("tab3_box_2_top_a").firstChild.innerHTML.strip();
                title = title.replace(/ /g, "%20");
                tmpurl = "/germany/dynamics" + hometabprefix + title;
                //alert("WT Link-Tracking:\n\nTitle: " + title + "\nURL: " + tmpurl + "\nChannel: " + WtChannel);
                dcsMultiTrack('DCS.dcsuri', tmpurl, 'WT.ti', title, 'WT.sp', WtChannel,'WT.dl','1');
                document.getElementById("tab3_box_1_cpy").style.display="none";
                document.getElementById("tab3_box_2_cpy").style.display="block";
                document.getElementById("tab3_box_3_cpy").style.display="none";
                document.getElementById("tab3_active").style.backgroundImage="url(/germany/dynamics/_global/templates/img/tab3_top_2.jpg)";
            });

            Event.observe("tab3_box_3_top_a", 'click', function() {
                var tmpurl = "";
                title = document.getElementById("tab3_box_3_top_a").firstChild.innerHTML.strip();
                title = title.replace(/ /g, "%20");
                tmpurl = "/germany/dynamics" + hometabprefix + title;
                //                alert("WT Link-Tracking:\n\nTitle: " + title + "\nURL: " + tmpurl + "\nChannel: " + WtChannel);
                dcsMultiTrack('DCS.dcsuri', tmpurl, 'WT.ti', title, 'WT.sp', WtChannel, 'WT.dl', '1');
                document.getElementById("tab3_box_1_cpy").style.display = "none";
                document.getElementById("tab3_box_2_cpy").style.display = "none";
                document.getElementById("tab3_box_3_cpy").style.display = "block";
                document.getElementById("tab3_active").style.backgroundImage = "url(/germany/dynamics/_global/templates/img/tab3_top_3.jpg)";
            });
			
		}
	}
);
//Home Tabs 3 End

//CTA_Box



var cta_box = Class.create
(
	{
		initialize:function(type,mailtostr)
		{
//		    this.classNames = new Array('ctaBoxTop','ctaBoxMiddle','ctaBoxBottom');		    
//		    for(i=0;i<this.classNames.length;i++){
//		        this.tmpObject = $('cta_box').getElementsByClassName(this.classNames[i])
//		        for(z=0;z<this.tmpObject.length;z++){
//		            this.cta_hover_watcher(this.tmpObject[z]);
//		        }
//		    }
		},
		cta_hover_watcher:function(obj){
		    var cta_object = obj.getElementsByTagName("a")[0];
            if(cta_object.innerHTML==""){
                cta_object = obj.childElements()[0].childElements()[1];
            }
            Event.observe(cta_object, 'mouseover', function() {
                var tmpstyle=cta_object.getStyle('background-image');
                tmpstyle = tmpstyle.sub('.png','_hvr.png');
                cta_object.style.backgroundImage=tmpstyle;
            });
            Event.observe(cta_object, 'mouseout', function() {
                var tmpstyle=cta_object.getStyle('background-image');
                tmpstyle = tmpstyle.sub('_hvr.png','.png');
                cta_object.style.backgroundImage=tmpstyle;
            });
		}
	}
);
//CTA_Box End
//wt_track_links Start
var wt_track_links = Class.create
(
	{
		initialize:function(typ)
		{
		    wtTrackArrayCount = 0;
            for (i=0; i < document.links.length; i++)
            {
                if(document.links[i].getAttribute('wttyp')){
                    this.wt_obj = document.links[i];
                    this.wt_typ = document.links[i].getAttribute('wttyp');
                    this.wt_href = document.links[i].href;
                    if(this.wt_href.indexOf("/germany/")>-1){
                        this.wt_href = this.wt_href.slice(this.wt_href.indexOf("/germany/"),this.wt_href.length);
                    }
                    this.wt_url_varsactive=false;
                    if(pageWtUrl.indexOf("&")>-1){
                        this.wt_url_varsactive=true;
                    }
                    this.wt_link_title = "";
                    this.wt_title = "";
                    this.wt_url = "";
                    this.wt_channel = "";
                    this.foundtyp_flag = false;
                    this.exe_win_loc = false;
                    
                    if(pageUrl[pageUrl.length-1]=="/"){
                        this.lastslash=true;
                    }else{
                        this.lastslash=false;
                    }

                    if(document.links[i].childNodes[0].innerHTML){
                        this.wt_link_title = document.links[i].childNodes[0].innerHTML;
                    }else{
                        this.wt_link_title = document.links[i].innerHTML;
                    }
                    //this.wt_link_title = this.wt_link_title.replace(/ /g, "%20");
                    this.wt_link_title = escape(this.wt_link_title);
                    //this.wt_page_title = pageTitle.replace(/ /g, "%20");
                    
                    switch (this.wt_typ) {
                        case "ql":
                            this.exe_win_loc = true;
                            this.foundtyp_flag = true;                      
                            this.track_typ_ql(this.wt_obj,this.wt_link_title,this.wt_href);
                        break;
                        case "cta_box":
                            this.exe_win_loc = true;
                            this.foundtyp_flag = true;
                            //alert(this.wt_obj.childNodes[0].innerHTML + " - " + this.wt_obj.childNodes[1].innerHTML);
//this.wt_link_title=escape(this.wt_obj.childNodes[0].childNodes[0].innerHTML + " - " + this.wt_obj.childNodes[0].childNodes[1].innerHTML);
                            this.wt_link_title=escape(this.wt_obj.childNodes[0].innerHTML + " - " + this.wt_obj.childNodes[1].innerHTML);
                            this.track_typ_cta_box(this.wt_obj,this.wt_link_title,this.wt_href);
                        break;
                        case "page_show_all":
                            this.foundtyp_flag = true;
                            this.track_typ_page_show_all();
                        break;
                        case "page_print":
                            this.foundtyp_flag = true;
                            this.track_typ_page_print();
                        break;
                        case "page_recommend":
                            this.foundtyp_flag = true;
                            this.track_typ_page_recommend(this.wt_obj);
                        break;
                        //Text Link
                        case "tl":
                            this.exe_win_loc = true;
                            this.foundtyp_flag = true;
                            this.track_typ_tl(this.wt_obj,this.wt_link_title,this.wt_href);
                        break;
                    }
                    if(this.foundtyp_flag){
                        this.link_observe(this.wt_obj, changeToHex(this.wt_title), this.wt_url, this.wt_channel, this.wt_href, this.exe_win_loc);
                    }
                }
            } 
		},
		link_observe:function(link_obj, title, url, channel, href, exe_win_loc)
		{
		    Event.observe(link_obj, 'click', function(){
                //alert("WT Link-Tracking:\n\nTitle: " + title + "\nURL: " + url + "\nChannel: " + channel);
                dcsMultiTrack('DCS.dcsuri', url, 'WT.ti', title, 'WT.sp', channel,'WT.dl','1');
            });
		},
		track_typ_tl:function(link_obj,title,href){
		    wt_link_typ = link_obj.getAttribute('wtval');
		    if(wt_link_typ == null){
                wt_link_typ = "N/A";
            }
            this.wt_title = "TL%20-%20" + this.wt_link_title + "%20Typ:%20" + wt_link_typ;
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?target=" + encodeURIComponent(this.wt_href);
            }else{
                this.wt_url = pageWtUrl + "&target=" + encodeURIComponent(this.wt_href);
            }
		    this.wt_channel = WtChannel;
		},
		track_typ_ql:function(link_obj,title,href){
            wt_link_typ = link_obj.getAttribute('wtval');
            if(wt_link_typ == null){
                wt_link_typ = "N/A";
            }
            this.wt_title = "QL%20-%20" + this.wt_link_title + "%20Typ:%20" + wt_link_typ;
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?target=" + encodeURIComponent(this.wt_href);
            }else{
                this.wt_url = pageWtUrl + "&target=" + encodeURIComponent(this.wt_href);
            }
		    this.wt_channel = WtChannel;
		},
		track_typ_cta_box:function(link_obj,title,href){
            this.wt_title = "CTA-Box%20-%20" + this.wt_link_title;
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?target=" + encodeURIComponent(this.wt_href);
            }else{
                this.wt_url = pageWtUrl + "&target=" + encodeURIComponent(this.wt_href);
            }
		    this.wt_channel = WtChannel;
		},
		track_typ_page_show_all:function(){
            this.wt_title = pageTitle + "%20-%20Auf%20einer%20Seite%20anzeigen";
            wt_url_addon = "seite=999";
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?" + wt_url_addon;
            }else{
                this.wt_url = pageWtUrl + "&" + wt_url_addon;
            }
		    this.wt_channel = WtChannel;
		},
		track_typ_page_print:function(){
            this.wt_title = pageTitle + "%20-%20Seite%20drucken";
            wt_url_addon = "pf=print";
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?" + wt_url_addon;
            }else{
                this.wt_url = pageWtUrl + "&" + wt_url_addon;
            }
		    this.wt_channel = WtChannel;
		    
		},
		track_typ_page_recommend:function(link_obj){
//		    var tmpUrl=link_obj.href;
//		    link_obj.href="";
            this.wt_title = pageTitle + "%20-%20Seite%20empfehlen";
            wt_url_addon = "pf=recommend";
            if(this.wt_url_varsactive){
                this.wt_url = pageWtUrl + "?" + wt_url_addon;
            }else{
                this.wt_url = pageWtUrl + "&" + wt_url_addon;
            }
		    this.wt_channel = WtChannel;
		    Event.observe(link_obj, 'click', function(){
                win = window.open(link_obj.getAttribute('mailto'),'emailWindow'); 
            if (win && win.open &&!win.closed) win.close();   
            });
		    
		}
	}
);
//wt_track_links End

//Page_recommend link Start
var link_page_recommend = Class.create
(
	{
		initialize:function(typ)
		{
		    obj = document.getElementById("page_recommend")
            wt_link_typ = obj.getAttribute('values');
		    wt_link_typ_array = wt_link_typ.split(";;");
		    type = wt_link_typ_array[0];
		    mailtostr = "";
		    mailtostr = wt_link_typ_array[1];
		    this.pageTitle = pageTitle;
		    this.pageDescription = pageDescription;
		    if(type == "custom" && mailtostr != ""){
                obj.href = mailtostr;
            }else{
                // Umlaute
                // Ä=%C4 Ö=%D6 Ü=%DC ä=%E4 ö=%F6 ü=%FC ß=%DF &=%26 lineBreak=%0A
                subject = changeToUmlaute(pageTitle);
                body_standard = changeToUmlaute(pageDescription) + "%0A%0A" + pageUrl;
                this.wt_href = "mailto:?subject="+subject+"&body="+body_standard;
                obj.setAttribute('mailto',this.wt_href);
            }	
		}
	}
);
		
//Page_recommend link End
function changeToHex(input){
    input = input.replace(/ /g, "%20");
    input = input.replace(/ä/g, "%E4");
    input = input.replace(/Ä/g, "%C4");
    input = input.replace(/ö/g, "%F6");
    input = input.replace(/Ö/g, "%D6");
    input = input.replace(/ü/g, "%FC");
    input = input.replace(/Ü/g, "%DC");
    input = input.replace(/ß/g, "%DF");
    input = input.replace(/lineBreak/g, "%0A");
    
    return input;
}
function changeToUmlaute(input){
    input = input.replace(/ /g, "%20");
    input = input.replace(/ä/g, "ae");
    input = input.replace(/Ä/g, "Ae");
    input = input.replace(/ö/g, "oe");
    input = input.replace(/Ö/g, "Oe");
    input = input.replace(/ü/g, "ue");
    input = input.replace(/Ü/g, "Ue");
    input = input.replace(/ß/g, "ss");
    input = input.replace(/lineBreak/g, "%0A");
    return input;
}
//Custom Error Start
var page_error = Class.create
(
	{
		initialize:function(msg)
		{
            msgArray1 = msg.split(";;;;");
            for(i=0;i<msgArray1.length-1;i++){
                msgArray2 = msgArray1[i].split(";;");
                alert(msgArray2[0] + " - " + msgArray2[1]);
            }
		}
	}
);
//Custom Error End
//img_preload Start
function img_preload()
{
    document.PL = new Array();

    if(document.images)
    {
        for(var i = 0; i < img_preload.arguments.length; i++)
        {
            document.PL[i] = new Image();
            document.PL[i].src = img_preload.arguments[i];
        }
    }
  return true;
}
//img_preload End




//pageinfo Tabs 3
var PageInfo_Tabs = Class.create
(
	{
		initialize:function(type,mailtostr)
		{
		    var flag_errors = false;
		    if(document.getElementById("page_info_error")!=undefined || document.getElementById("page_info_error")!=null){
		        flag_errors = true;
		    }
		    var flag_warnings = false;
		    if(document.getElementById("page_info_warning")!=undefined || document.getElementById("page_info_warning")!=null){
		        flag_warnings = true;
		    }
		    document.getElementById("pageinfo_nav_infos").setAttribute("href","javascript:void(0);");
		    document.getElementById("page_info_ads").style.display="none";
		    document.getElementById("pageinfo_nav_ads").setAttribute("href","javascript:void(0);");
		    if(flag_errors){
                document.getElementById("page_info_error").style.display="none";
                document.getElementById("pageinfo_nav_errors").setAttribute("href","javascript:void(0);");
            }
            if(flag_warnings){
                document.getElementById("page_info_warning").style.display="none";
                document.getElementById("pageinfo_nav_warnings").setAttribute("href","javascript:void(0);");
            }

            var dynmicshome = "http://www.microsoft.com/germany/dynamics";

            Event.observe("pageinfo_nav_infos", 'click', function(){
                document.getElementById("page_info_info").style.display = "block";
                document.getElementById("page_info_ads").style.display = "none";
                if(flag_errors){
                    document.getElementById("page_info_error").style.display = "none";
                }
                if(flag_warnings){
                    document.getElementById("page_info_warning").style.display = "none";
                }
            });
            Event.observe("pageinfo_nav_ads", 'click', function(){
                document.getElementById("page_info_info").style.display = "none";
                document.getElementById("page_info_ads").style.display = "block";
                if(flag_errors){
                    document.getElementById("page_info_error").style.display = "none";
                }
                if(flag_warnings){
                    document.getElementById("page_info_warning").style.display = "none";
                }
            });
            if(flag_errors){
                Event.observe("pageinfo_nav_errors", 'click', function(){
                    document.getElementById("page_info_info").style.display = "none";
                    document.getElementById("page_info_ads").style.display = "none";
                    document.getElementById("page_info_error").style.display = "block";
                    if(flag_warnings){
                        document.getElementById("page_info_warning").style.display = "none";
                    }
                });
            }
            if(flag_warnings){
                Event.observe("pageinfo_nav_warnings", 'click', function(){
                    document.getElementById("page_info_info").style.display = "none";
                    document.getElementById("page_info_ads").style.display = "none";
                    if(flag_errors){
                        document.getElementById("page_info_error").style.display = "none";
                    }
                    document.getElementById("page_info_warning").style.display = "block";
                });
            }
            Event.observe("page_info_close_a",'click',function(){
                document.getElementById("page_info").style.display="none";
            });
			
		}
	}
);
//pageinfo Tabs End


function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        //strReturn = strReturn.replace(/'%2B'/,'%20');
        //strReturn=decodeURIComponent(strReturn);        
        strReturn=encodeURIComponent(strReturn);
        strReturn = strReturn.replace(/%2B/gi,'%20');
        break;
      }
    }
  }
  return unescape(strReturn);
  //return encodeURIComponent(strReturn);
} 
