﻿// JScript File

// *************************************
// * Jewel Menu Click functions        *
// * Created by Brite Global, Inc.     *
// *************************************

var clickCount = 0;
function showHideMenu(my)
{
    if (Menu.style.display == "none")
    {
        showMenu(my);
    }
    else
    {
        if (clickCount>1)
            hideMenu(my);
    }
}
function showMenu(my)
{
    Menu.style.top = ctl00_TabList.style.top + 86;
    Menu.style.left =  (screen.width - 900)/2; //ctl00_TabList.style.left + 10;
    //Menu.style.top = my.style.top + 86;         
    //Menu.style.left = my.style.left + 10;
    Menu.style.display = "block"; 
    my.src='/images/bgframe_topleft_down.png'
    clickCount++;
}

function hideMenu(my)
{
    Menu.style.display = "none"; 
    my.src='/images/bgframe_topleft_normal.png'
    clickCount = 0;
}


// *************************************
// * Rotating Partner Logo functions   *
// * Created by Brite Global, Inc.     *
// *************************************

var currentIndex = 1;
var dynamicIndex = 1;
window.setInterval('rotateDynamic()', 7500);
window.setInterval('rotateLogo()', 7500);


function rotateLogo()
{
    if (currentIndex==2) currentIndex=0;
    currentIndex+=1;
    showLogo(currentIndex);
}

function showLogo(index)
{
    var logoUrl = '/images/imgPartner' + index + '.jpg';
    var o = document.getElementById('imgLogo');
    if (o)
    {
        o.src = logoUrl;
    }
}

function rotateDynamic()
{
    if (dynamicIndex==3) dynamicIndex=0;
    dynamicIndex+=1;
    showDynamic(dynamicIndex);
}
function showDynamic(index)
{
    var dynamicUrl = '/images/imgDynamic' + index + '.gif';
    var o = document.getElementById('imgDynamic');
    if (o)
    {
        o.src = dynamicUrl;
    }
}


// *************************************
// * Open Image/Video Window functions *
// * Created by Brite Global, Inc.     *
// *************************************

function displayDemoWindow(my)
{
    var targetUrl = 'http://www.microsoft.com/dynamics/crm/demos/professional/crm.html';
    alert(targetUrl);
    window.open(targetUrl, 'Dynamics CRM Demo', 'width=780,height=600,scrollbars=1');
}

function displayTechImage(my, imageId)
{
    window.open('/images/tech_large' + imageId + '.jpg', 'Technology', 'width=600,height=500,scrollbars=1');
}

function loadDemo()
{
    var me = window.self;
    me.opener = window.self 
    me.open('http://www.microsoft.com/dynamics/crm/demos/professional/crm.html', '', 'width=750,height=480,scrollbars=1');
}

// *************************************
// * Open Video Functions              *
// * Created by Microsoft Corporation  *
// *************************************


function OpenVideo(url, width, height)
{
	if (FIsMac())
		{
		if (url.indexOf('?') < 0)
			url += '?';
		else
			url += '&';

		url += 'IsMac=1';
		}

	var fNSorFF =
		window.navigator.appName.toUpperCase().indexOf("NETSCAPE") >= 0 ||
		window.navigator.appName.toUpperCase().indexOf("FIREFOX") >= 0;

	var strUrlUpper = url.toUpperCase();
	var strAssetId = StrGetParamFromUrl(strUrlUpper, "ASSETID");
	var fHX = (null != strAssetId && 0 == strAssetId.indexOf("HX"));

	if ((!fNSorFF || fHX) && StrGetParamFromUrl(strUrlUpper, "TYPE") == "MEDIAPLAYER") 
	{
		OpenVideoPage(
			strAssetId,
			parseInt(StrGetParamFromUrl(strUrlUpper, "STARTINDEX")),
			parseInt(StrGetParamFromUrl(strUrlUpper, "VWIDTH")),
			parseInt(StrGetParamFromUrl(strUrlUpper, "VHEIGHT")),
			StrGetParamFromUrl(strUrlUpper, "ORIGIN"));

		return;
	}

	if (-1 != window.navigator.appName.toUpperCase().indexOf("NETSCAPE"))
		{

		window.open(url, '_AsstVidWnd');
		}
	else
		{
		window.open(url, '_AsstVidWnd', 'toolbar=0,status=0,menubar=0,resizable=0,width=' + width + ',height=' + height);
		}
}

function FIsMac()
{
	if (typeof(window.navigator.platform) != 'undefined')
		return (-1 != window.navigator.platform.toUpperCase().indexOf("MAC"));
	else
		return (-1 != navigator.userAgent.toUpperCase().indexOf("MAC"));
}

function OpenVideoPage(strAssetID, iStartIndex, nWidth, nHeight, strOrigin)
{
	if (typeof(strAssetID) == 'undefined' || null == strAssetID ||
		typeof(iStartIndex) == 'undefined' ||
		typeof(nWidth) == 'undefined' || typeof(nHeight) == 'undefined')
	{
		return;
	}

	var fHX = (0 == strAssetID.toUpperCase().indexOf("HX"));

	if (fHX)
	{
		nWidth = 0;
		nHeight = 0;
	}

	if (isNaN(iStartIndex))
		iStartIndex = 0;

	if (isNaN(nWidth) || isNaN(nHeight))
		return;

	if (typeof(strOrigin) == 'undefined' || null == strOrigin)
		strOrigin = "";

	var fNSorFF =
		window.navigator.appName.toUpperCase().indexOf("NETSCAPE") >= 0 ||
		window.navigator.appName.toUpperCase().indexOf("FIREFOX") >= 0;

	if (fNSorFF && !fHX)
	{
		OpenVideo(
			"/assistance/asstvid.aspx" +
			"?assetid=" + strAssetID +
			"&vwidth=" + nWidth.toString() +
			"&vheight=" + nHeight.toString() +
			"&type=mediaplayer" +
			"&CTT=11" +
			"&Origin=" + strOrigin,
			nWidth, nHeight);

		return;
	}

	var strUrl = "/home/video.aspx" +
		"?assetid=" + StrEncodeUrlComponent(strAssetID) +
		"&width=" + StrEncodeUrlComponent(nWidth.toString()) +
		"&height=" + StrEncodeUrlComponent(nHeight.toString()) +
		"&startindex=" + StrEncodeUrlComponent(iStartIndex.toString()) +
		"&CTT=11" +
		"&Origin=" + StrEncodeUrlComponent(strOrigin);

	if (fNSorFF && fHX)
	{
		window.location.href = strUrl + "&asx=1";
		return;
	}

	window.open(strUrl, "_OfficeVideoWindow",
		"toolbar=0,status=0,menubar=0,resizable=1," +
		"width=756" + 
		",height=580").focus(); 
}

function StrEncodeUrlComponent(strUrlComponent)
{
	if (typeof(strUrlComponent) == "undefined" ||
		null == strUrlComponent)
		return "";

	if (typeof(encodeURIComponent) != "undefined")
		return StrEncodeUrlComponent55(strUrlComponent);

	return StrEncodeUrlComponent50(strUrlComponent);
}

function StrEncodeUrlComponent55(strUrlComponent)
{
	return encodeURIComponent(strUrlComponent);
}

function StrEncodeUrlComponent50(strUrlComponent)
{
	var i=0;
	var strEncoded = "";
	for (i=0; i < strUrlComponent.length; i++)
		{
		var chr = strUrlComponent.charAt(i);
		var iChr = strUrlComponent.charCodeAt(i);

		if (iChr < 128)
			{
			if ('!' == chr || '\'' == chr || '(' == chr || 	')' == chr || '~' == chr)
				strEncoded += chr;
			else if (0 == iChr)
				strEncoded += "%00";
			else if (127 == iChr)
				strEncoded += "%7F";
			else if ('+' == chr)
				strEncoded += "%2B";
			else if ('/' == chr)
				strEncoded += "%2F";
			else if ('@' == chr)
				strEncoded += "%40";
			else
				strEncoded += escape(chr);
			}
		else if (iChr < 2048)
			{
			strEncoded += "%";
			strEncoded += ( (iChr >> 6) + 192).toString(16).toUpperCase();

			strEncoded += "%";
			strEncoded += ( (iChr & 63) + 128).toString(16).toUpperCase();
			}
		else 
			{
			strEncoded += "%";
			strEncoded += ( (iChr >> 12) + 224).toString(16).toUpperCase();

			strEncoded += "%";
			strEncoded += ( ((iChr >> 6) & 63) + 128).toString(16).toUpperCase();

			strEncoded += "%";
			strEncoded += ( (iChr & 63) + 128).toString(16).toUpperCase();
			}
		}

	return strEncoded;
}

function StrGetParamFromUrl(strUrl, strParam)
{
	var iStart = strUrl.indexOf("?" + strParam + "=");
	if (iStart < 0)
		iStart = strUrl.indexOf("&" + strParam + "=");
	if (iStart < 0)
		return null;

	iStart += strParam.length + 2;
	var iEnd = strUrl.indexOf("&", iStart+1);
	if (iEnd <= iStart)
		iEnd = strUrl.length;

	return strUrl.substring(iStart, iEnd);
}
