var m_strGateway = null;
var m_strSessionID = null;
var m_UniqueID = null;
var m_PageName = "";
var isNetscape6ForBnr=((!document.all) && (document.getElementById));
var strCurLang = strCiscoVLanguagenumber;
var m_banner_width = 0;
var m_strBnrCornerImg = 0;
var HelpIDPageArray = new Array();
var m_AllowProfileAccess = strCiscoG_RegistrynumberAllowProfileAccess;

HelpIDPageArray[0]		= "";
HelpIDPageArray[1]		= "sign_in";
HelpIDPageArray[2]		= "attend_meeting";
HelpIDPageArray[3]		= "find_meeting";
HelpIDPageArray[5]		= "account_basics";
HelpIDPageArray[7]		= "audio_service";
HelpIDPageArray[9]		= "browser_test";
HelpIDPageArray[21]		= "meeting_options";
HelpIDPageArray[22]		= "attachment_recording";
HelpIDPageArray[23]		= "invite_people_to_a_meeting";
HelpIDPageArray[24]		= "schedule_meeting";
HelpIDPageArray[30]		= "multiserver_meetings";
HelpIDPageArray[31]		= "multiserver_meetings_schedule";
HelpIDPageArray[51]		= "meeting_preferences";
HelpIDPageArray[70]		= "admin";
HelpIDPageArray[71]		= "database";
HelpIDPageArray[72]		= "replication_service";
HelpIDPageArray[74]		= "site_properties";
HelpIDPageArray[75]		= "web_server_properties";
HelpIDPageArray[76]		= "rollover_map_properties";
HelpIDPageArray[77]		= "user_group_properties";
HelpIDPageArray[78]		= "local_system_version";
HelpIDPageArray[79]		= "groups";
HelpIDPageArray[80]		= "meeting_categories";
HelpIDPageArray[81]		= "restricted_meeting_id_patterns";
HelpIDPageArray[82]		= "profiles";
HelpIDPageArray[83]		= "site_routes";
HelpIDPageArray[84]		= "user_interface_field_configuration";
HelpIDPageArray[85]		= "user_interface_string_configuration";
HelpIDPageArray[86]		= "templates";
HelpIDPageArray[221]	= "add_attachment";

function pophelp(tag)
{
	var lang = strCiscoVLanguagenumber;

	switch ( lang ) 
	{
		case "000":
		case "003":
		case "004":
		case "005":
		case "006":
		case "014":
		case "015":
			break;
		default:
			lang = "000";
			break;
	}

	window.open( "/mpweb/html/help/" + lang + "/pophelp.html?" + tag, "HelpSystem", "toolbar=0,location=0,personalbar=0,status=0,menubar=0,resizable=1,scrollbars=1" );
}

InsertThisPage();

function GoHome()
{
	NavAnchr(0);
}

function TakeMeLogin()
{
	if ( !IsUserLoggedIn( strCiscoUniqueID ) )
	{
		if ( strCiscouMtgID.length && strCiscouMtgID != "2" )
		{
			document.location = strCiscoGatewayInterface + "?FormType=Parse&STPL=wcLogin.tpl&FTPL=wcLogin.tpl&wcState=1&uMtgID=" + strCiscouMtgID;
		}
		else
		{
			document.location = strCiscoGatewayInterface + '?FormType=Parse&STPL=wcLogin.tpl&FTPL=wcLogin.tpl&wcState=0';
		}
	}
	else
	{
		document.location = strCiscoGatewayInterface + "?FormType=GetMeeting&STPL=wcSchedBasicsRO.tpl&FTPL=wcBase.tpl&wcState=1&uMtgID=" + strCiscouMtgID + "&TXT0=" + strCiscoG_String5227 + "URL0=wcBase.tpl"
	}
}	

function LoadLang()
{
	if (document.NavForm.selLang)
	{
		if (document.NavForm.selLang.value != "-1")
		{
			var strSelLang = document.NavForm.selLang.value;
			if (strSelLang.length == 1)
				strSelLang = "00" + strSelLang;
			if (strSelLang.length == 2)
				strSelLang = "0" + strSelLang;
				
			document.location = "/mpweb/scripts/mpx.dll?formtype=parse&SessionID=" + strCiscoSessionIDGUID + "&stpl=wcBase.tpl&SP_VLanguage=lang999i" + strSelLang;
		}
	}
}

function GoToHelp()
{
	pophelp(HelpIDPageArray[m_PageID]);
}

function CheckForStale()
{
	var fIsSessionStale = false;
	var fIsPwdChanged = false;
	var ret = new Array();
	ret = fillCheckForStale(fIsSessionStale, fIsPwdChanged);
	fIsSessionStale = ret[0];
	fIsPwdChanged = ret[1];
	
	
	if (fIsSessionStale == false && strCiscoU_IsLoggedIn == "false" && m_PageID != 0 && m_PageID != 1 && m_PageID != 12 && m_PageID != 9 && !fIsPwdChanged)
	{
		if (strCiscowcState == "")
		{
			TakeMeLogin();
		}
		else
		{
			alert(strCiscoG_String5255);
			fIsSessionStale = true;
			if (strCiscobChangesMade!="")
				bChangesMade = false;
		}
	}

	if ( fIsSessionStale )
	{
		if (isNetscape6ForBnr)
			return;           // Netscape screws up everything
		else
			document.location = strCiscoGatewayInterface + "?FormType=Parse&STPL=wcBase.tpl&FTPL=wcBase.tpl";
	}
}

function CheckDirtyBanner()
{
	var strError = true;
	
	if(m_PageID == 2 ||		// wcSchedBasics 
		m_PageID == 24 ||	// wcSchedBasicsRO
		m_PageID == 23 ||	// wcSchedPart
		m_PageID == 22 ||	// wcSchedAtt
		m_PageID == 221 ||	// wcSchedAddAtt
		m_PageID == 21 )	// wcSchedAdv
	{
		if (!CheckDirty())
		{
			strError = false;
		}
	}
	return strError;
}

function HomeAfterLogout()
{
	if ( document.forms[0] )
	{
		FillNavParams( document.forms[0], 1 );

		document.forms[0].action = strCiscoGatewayInterface;
		document.forms[0].FTPL.value = "wcBase.tpl";
		document.forms[0].wcState.value = "6";
		document.forms[0].FormType.value = "LogoutProfile";
		document.forms[0].STPL.value = "wcBase.tpl";

		document.forms[0].submit();
	}
}

function ExpireCookie(strName) 
{
	document.cookie = strName + "=" + "; path=/ ;expires=Mon, 01-Jan-1990 00:00:01 GMT";
}

function DeleteLoginCookies()
{
	ExpireCookie("U_U");
	ExpireCookie("U_LoginTime");
	ExpireCookie("U_Checksum");
}

function Logout()
{
	if ( confirm( strCiscoG_String5244 ) )
	{
		DeleteLoginCookies();
		HomeAfterLogout();
	}
}

function IsUserLoggedIn(UniqueID)
{
	if ( UniqueID == 3 || UniqueID == 0 )
		return false;
	else
		return true;
}

function GetUserName(UniqueID, strFirstName, strLastName)
{
	var strUserName = "";

	if ( IsUserLoggedIn( UniqueID ) )
	{
		if ( parseInt( strCiscoVLanguagenumber ) == 6 )
		{
			strUserName = "," + "&nbsp;" + strLastName + "&nbsp;" + strFirstName + "&nbsp;" + strCiscoG_String5243Style;
		}
		else
		{
			strUserName = "," + "&nbsp;" + strFirstName + "&nbsp;" + strLastName;
		}
	}		
	else if ( !IsUserLoggedIn( UniqueID ) && strCiscoU_IsLoggedIn == "true" )
	{
		if ( parseInt( strCiscoVLanguagenumber ) == 6 )
		{
			strUserName = "," + "&nbsp;" + strFirstName + "&nbsp;" + strCiscoG_String5243Style;
		}
		else
		{
			strUserName = "," + "&nbsp;" + strFirstName;
		}
	}
	else
	{
		strUserName = strCiscoG_String5245Style;
	}

	return strUserName;	
}

function LoginAndGoHome()
{
	if ( document.forms[0] ) 
	{
		FillNavParams( document.forms[0], 1 );

		document.forms[0].action = strCiscoGatewayInterface;	
		document.forms[0].SessionID.value = strCiscoSessionIDGUID;
		document.forms[0].FTPL.value = "wcBase.tpl";
		document.forms[0].wcState.value = "0";
		document.forms[0].FormType.value = "Parse";
		document.forms[0].STPL.value = "wcLogin.tpl";

		if ( document.forms[0].ExpireStpl )
		{
			document.forms[0].ExpireStpl.value = "Yes";
		}

		document.forms[0].submit();
	}
}

function Administration() 
{	
	if (!CheckDirtyBanner())
		return;
	
	if ( document.forms[0] ) 
	{
		FillNavParams( document.forms[0], 1 );

		document.forms[0].action = strCiscoGatewayInterface;
		document.forms[0].wcState.value = "7";
		document.forms[0].FormType.value = "Parse";
		document.forms[0].FTPL.value = "wcBase.tpl";

		if ( IsUserLoggedIn( strCiscoUniqueID ) || strCiscoU_IsLoggedIn == "true" )
		{
			document.forms[0].STPL.value = "wcFormProxy.tpl";
		}
		else
		{
			document.forms[0].STPL.value = "wcLogin.tpl";
		}

		document.forms[0].submit();
	}
}

function isIEonMac()
{
	return ((navigator.appVersion.indexOf ("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") > 0))
}

function KeyPressHandler(formElement) 
{
	if(isIEonMac())
		return true;
	if((formElement == null) || (window.event == null))
		return KeyPress(null, null);
	else {			
		var theKey = window.event.keyCode;
		var target = formElement;
		return KeyPress(theKey, target);
	}
}

var retnChar = 13;
var backChar = 8;

function KeyPress(theKey, target)
{
	if ((target == null) || 
		(theKey == null) || 
		(theKey != retnChar)) return true;
	AttendMtg();
	return false;
}

function isValidPhoneStr(szVal) 
{	
	var slen = szVal.length;
		
	if ( slen != 0 )
	{
		for ( var i = 0; i < slen; i++ ) 
		{
			if ((!((szVal.charCodeAt(i) >= 48) && (szVal.charCodeAt(i) <= 57))) && //0-9
				(!((szVal.charCodeAt(i) >= 65) && (szVal.charCodeAt(i) <= 90))) && //A-Z
				(!((szVal.charCodeAt(i) >= 97) && (szVal.charCodeAt(i) <= 122))) ) { //a-z
					alert(strCiscoG_String5260);
					return false;
				}
		}
	}
	return true;
}

function DrawBanner()
{	
	CheckForStale();
	
	var strFName = strCiscoFirstName;
	var strLName = strCiscoLastName;
	var strRemoteUser = strCiscoREMOTE_USER;
	var boolIsRemoteUserAllowed = strCiscoIsRemoteUserAllowed;
	var numUniqueID = strCiscoUniqueID;
	var strUserType = strCiscoKindNum;
	var strExternalUser = strCiscoExternalUser;
	
	m_strGateway = strCiscoGatewayInterface;
	m_strSessionID = strCiscoSessionIDGUID;
	m_UniqueID = numUniqueID;

	document.write('<table border="0" width="100%" cellspacing="0" cellpadding="0" cellmargin="0" bgcolor="#639E9C">');	
	document.write('<tr>');
	document.write('	<td bgcolor="#FFFFFF">');
	document.write('		<img src="/mpweb/images/wcBannerCorner.gif" name="I1" border="0" valign="top">');
	document.write('	<\/td><td rowspan="10">&nbsp;&nbsp;&nbsp;&nbsp;<\/td>');
	document.write('	<td width="50%" align="left">');
	document.write('		<table border="0" cellspacing="0" cellpadding="0" cellmargin="0" style="height:60px">');
	document.write('			<tr>');
	document.write('				<td>');
	if ( m_PageID == 9 )
		document.write('				<font color="black" size="4">' + m_PageName + '<\/font>');
	else
		document.write('				<font color="black" size="4">' + strCiscoG_String5246Style + GetUserName(numUniqueID, strFName, strLName) + '<\/font>');
	document.write('				<\/td>');
	document.write('			<\/tr>');
	document.write('			<tr>');
	document.write('				<td>');
	if ( m_PageID == 0 )
	{	
		document.write('<table border=0>');
		document.write('<tr>');
		document.write('<td>');
		document.write('							<font color="white" size="+1">*<\/font><b><font color="white" size="2">' + strCiscoG_String5247Style +'<\/font><\/b>');
		document.write('<\/td>');
		document.write('<td>');
		document.write('							<input type="text" id="wcMeetingID" name="wcMeetingID" value="' + strCiscowcMtgID  + '" maxlength="' + strCiscoMTGIDMax + '" size="20" onKeyPress="return KeyPressHandler(this)">');

		writeWebPart()

		document.write('<\/td>');
		if(strCiscoExternalUser == "Yes")
		{
			document.write('<td>');
			document.write('						<a href="Javascript:if(!self.document.NavForm){history.back();}else{AttendMtg()};"><img alt="' + strCiscoG_String6176 + '" src="/mpweb/images/' + strCiscoVLanguagenumber + '/wcAttendMeeting.gif" width="110" height="18" border="0"><\/a>');
			document.write('<\/td>');
		}
		document.write('<\/tr>');
		document.write('</table>');
	}	
	else
	{

		if (m_PageID == 25 || m_PageID == 9)
			document.write("&nbsp;");
		else					
			WriteNav();
	}
	document.write('				<\/td>');
	document.write('			<\/tr>');
	document.write('		<\/table>');
	document.write('	<\/td>');
	document.write('	<td width="50%" align="right" valign="top">');
	document.write('		<table border="0" cellspacing="0" cellpadding="0" cellmargin="0" align="right" width="100%" style="height:60px">');
	document.write('			<tr>');
	document.write('				<td valign="top">');
	document.write('					<table border="0" cellspacing="0" cellpadding="0" cellmargin="0" align="right">');
	document.write('						<tr valign="top">');

	if( IsUserLoggedIn( numUniqueID ) )
	{
		if ( parseInt(strUserType) >= 3 && m_PageID != 4 && m_PageID != 25 && m_PageID != 9 && strCiscoExternalUser != "Yes")
		{
			document.write('					<td valign="top"><a href="javascript:Administration()"><font color="white" size=-2>' + strCiscoG_String5248Style + '<\/font><\/a><font color="white" size=-1>&nbsp;|&nbsp;<\/font>');
			document.write('					<\/td>');
		}
	
		if ( m_PageID != 25 && m_PageID != 9 && (strRemoteUser == "" || boolIsRemoteUserAllowed == 0 || numUniqueID == 3) )
		{
			document.write('					<td><a href="javascript:Logout()"><font color="white" size=-2>' + strCiscoG_String5249Style + '<\/font><\/a><font color="white" size=-1>&nbsp;|&nbsp;<\/font>');
			document.write('					<\/td>');
		}
		if (m_AllowProfileAccess == 1 && m_PageID != 4 && m_PageID != 25 && m_PageID != 9 && strCiscoExternalUser != "Yes")
		{
			document.write('						<td><a href="javascript:NavToProf(m_UniqueID)"><font color="white" size=-2>' + strCiscoG_String5250Style + '<\/font><\/a><font color="white" size=-1>&nbsp;|&nbsp;<\/font>');
			document.write('						<\/td>');
		}
	}
	else if ( !IsUserLoggedIn( numUniqueID ) && strCiscoU_IsLoggedIn == "true" && m_PageID != 9 )
	{
		document.write('						<td><a href="javascript:Logout()"><font color="white" size=-2>' + strCiscoG_String5249Style + '<\/font><\/a><font color="white" size=-1>&nbsp;|&nbsp;<\/font>');
		document.write('						<\/td>');
	}
	else if(strExternalUser != "Yes" && m_PageID != 1 && m_PageID != 12 && m_PageID != 7 && m_PageID != 71 && m_PageID != 72 && m_PageID != 73 && m_PageID != 74 && m_PageID != 75 && m_PageID != 76 && m_PageID != 77 && m_PageID != 78 && m_PageID != 8 && m_PageID != 9)
	{
		document.write('						<td><a href="javascript:LoginAndGoHome()"><font color="white" size=-2>' + strCiscoG_String5251Style + '<\/font><\/a><font color="white" size=-1>&nbsp;|&nbsp;<\/font>');
		document.write('						<\/td>');
	}
	document.write('							<td><a href="javascript:GoToHelp()"><font color="white" size=-2>' + strCiscoG_String5252Style + '<\/font><\/a><font color="white" size=-1>&nbsp;<\/font>');
	document.write('							<\/td>');
	document.write('						<\/tr>');
	document.write('					<\/table>');
	document.write('				<\/td>');
	document.write('			<\/tr>');
	document.write('			<tr valign="bottom">');
	document.write('				<td align="right" valign="bottom">');
	
	
	if ( (m_PageID == 2 || m_PageID == 24) && m_wcSchdState != "6" ) 
	{
		if ( numUniqueID != 3 && strCiscoExternalUser != "Yes" )
		{	
			if (strCiscoG_String6822.length) {
				document.write( '<input type="button" class="buttonBanner" onclick="javascript:TBarNav(1)" value="' + strCiscoG_String6822 + '">' );
			}
		}
		
		if ((uMTGId!="")||(uMTGId!= null))
		{
			if (uMTGId!="2") 
			{
				if( numUniqueID != 3 && strCiscoExternalUser != "Yes" )
				{
					if (strCiscoG_String17002.length) {
						document.write( '<input type="button" class="buttonBanner" onclick="javascript:TBarNav(2)" value="' + strCiscoG_String17002 + '">' );
					}
				}
				
				// ENDUSER = 0, CONTACT = 1, ATTENDANT = 2, SYSADMIN = 3, TECHNICIAN = 4, VOICEACCESS = 5
				
				if ( m_MtgType=="futr" && ( (strCiscoSchedulerID==strCiscoUniqueID || parseInt(strUserType) >= 2) || (parseInt(strUserType) == 1  && strCiscoUniqueID == strCiscoContactID) ) )
				{
					document.write( '<input type="button" class="buttonBanner" onclick="javascript:TBarNav(3)" value="' + strCiscoG_String6958 + '">' );
				}
			}

		}
	}
	else if ( m_PageID == 5 ) 
	{
		document.write( '<input type="button" class="buttonBanner" onclick="javascript:TBarNav(3)" value="' + strCiscoG_String6647 + '">' );
	} 
	else if ( m_PageID == 51 )
	{
		if ( numUniqueID != 3 )
		{
			document.write( '<input type="button" class="buttonBanner" onclick="javascript:TBarNav(2)" value="' + strCiscoG_String8646 + '">' );
		}
	}
	else
	{
		document.write("&nbsp;");
	}
	
	
	document.write('<img src="/mpweb/images/wcBlankBnr.gif" width="1" height="18">');
	document.write('<img src="/mpweb/images/wcBlankBnr.gif" width="1" height="18">');

	if (m_PageID == 0) {

		strLanTxt = '<table><tr><td><select name=selLang onChange="LoadLang();"><option value=-1>'+ strCiscoG_String5350;
		nL = 0;
		strLanTxt = strLanTxt + fillLanguageOption();

		strLanTxt = strLanTxt + '</select></td></tr></table>';
		if (nL > 0)
			document.write (strLanTxt);
	}

	document.write('				<\/td>');
	document.write('			<\/tr>');
	document.write('		<\/table>');
	document.write('	<\/td>');
	document.write('<\/tr>');
	document.write('<\/table>');
	
}

function IsSupportedLang(inpLangNo)
{
	var arLng = new Array("0", "3", "4", "5", "6", "7", "14", "15");
	var iL  = 0;
	for (iL = 0; iL < arLng.length; iL++)
		if (arLng[iL] == inpLangNo)
			return true;
	return false;
}

function CheckLangOption(lang)
{
	var ArrayNum = fillCheckLangOption();
	var i = 0;
	for (i = 0; i < ArrayNum.length; i++)
	{
		if(ArrayNum[i] == lang)
			return true;
	}
	return false;
}

/********************************************** Banner Navgation code ****************************************************/

function NavA0() 
{
	NavAnchr(0);
}

function NavA1() 
{
	NavAnchr(1);
}

function NavA2() 
{
	NavAnchr(2);
}

function NavA3() 
{
	NavAnchr(3);
}

function NavA4() 
{
	NavAnchr(4);
}

function NavA5() 
{
	NavAnchr(5);
}

function NavA6() 
{
	NavAnchr(6);
}

function NavAnchr(uintIndx) 
{
	NavigatePage(uintIndx);
	return;	
}

function WriteNav() 
{
	
	if ((m_BnrTVal[0]==null)||(m_BnrTVal[0]=="")) 
	{
		document.write('<a href="javascript:GoHome()">' + strCiscoG_String5253Style + '<\/a>');
		return;
	}

	for (i=0; i<m_BnrTVal.length; i++) 
	{
		if ((m_BnrTVal[i]==null)||(m_BnrTVal[i]==""))
			continue;
		if (i>0)
			document.write("<font color='white'>&nbsp;>&nbsp;<\/font>");
		if ((m_BnrTVal[i+1]==null)||(m_BnrTVal[i+1]==""))
			document.write("<font FACE='arial' color='white' size=-1><b>"+m_BnrTVal[i]+"<\/b><\/font>");
		else
			document.write("<a href='javascript:NavA"+i+"()'><font FACE='arial' color='white' size=-1><b>"+m_BnrTVal[i]+"<\/b><\/font><\/a>");
	}

}

function FindParamEnd() 
{
	var uintIndx=0;
	for (var i=0; i<m_BnrTVal.length; i++) 
	{
		if ((m_BnrTVal[i]==null)||(m_BnrTVal[i]==""))
			continue;
		else
			uintIndx++;
	}

	return uintIndx
}

function InsertThisPage() 
{
	var uintIndx=FindParamEnd();
	m_BnrTVal[uintIndx]=m_PageTXT;
	m_BnrUVal[uintIndx]=m_PageURL;
}

function FillNavParams(formObj, uintIndx) 
{
	if ((m_BnrUVal[0]==null)||(m_BnrUVal[0]==""))
		return;

	for (i=0; i< m_BnrUVal.length; i++) 	
	{
		eval("formObj.URL"+i+".value=''");
		eval("formObj.TXT"+i+".value=''");
	}
	
	for (i=0; i<uintIndx; i++) 
	{
		if ((m_BnrUVal[i]==null)||(m_BnrUVal[i]==""))
			continue;
		eval("formObj.URL"+i+".value='"+m_BnrUVal[i]+"'");
		eval("formObj.TXT"+i+".value='"+m_BnrTVal[i]+"'");
	}

	if( formObj.SessionID )
	{
  	  formObj.SessionID.value = m_strSessionID;
    }
}

function NavToProf(UniqueID) 
{
	if (!CheckDirtyBanner())
		return;
		
	if ( document.forms[0] ) 
	{
		FillNavParams( document.forms[0], 1 );
		
		document.forms[0].action = strCiscoGatewayInterface;
		document.forms[0].wcState.value = "5";
		document.forms[0].FormType.value = "Parse";
		if (IsUserLoggedIn(UniqueID)) 
		{
			document.forms[0].STPL.value = "wcFormProxy.tpl";
		}
		else
		{
			document.forms[0].STPL.value = "wcLogin.tpl";
			if (document.forms[0].ExpireStpl)				// This is going to be used if I want to expire the pages - SemK
				document.forms[0].ExpireStpl.value = "Yes";
		}
		
		document.forms[0].submit();
	}
}

function StrReplace(s, t, u) 
{
	i = s.indexOf(t);
	r = "";
	if ( i == -1 ) return s;
	r += s.substring(0,i) + u;
	if ( i + t.length < s.length )
		r += StrReplace( s.substring( i + t.length, s.length ), t, u );
	return r;
}
