

function LogOut()
{
	SetHiddenValue("_H_Load", "true");
	Open("pg_Expired.aspx?exp=0");
	//window.setTimeout("Open('page_expired.aspx')", 3000);
}

function DisableRightClick()
{
	//Disable right mouse click Script
	if (document.layers)
	{
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all && !document.getElementById)
	{
		document.onmousedown=clickIE4;
	}
}

/**
*/
function AutoSubmit()
{
	var AutoSubmit = GetHiddenValue("_Basic__Form__H_AutoSubmit");
	//alert(AutoSubmit);
	if(AutoSubmit == "1")
	{
		SetHiddenValue("_Basic__Form__H_Action", "AutoSubmit");
		window.setTimeout("document.forms[0].submit()", 200);
	}
}

function SessionExpired()
{
	var Expired = GetHiddenValue("_H_Expired");
	//alert(AutoSubmit);
	if(Expired == 1)
	{
		SetHiddenValue("_H_Expired", "0");
		SetHiddenValue("_H_Load", "true");
		Open("pg_Expired.aspx?exp=0");
		SetHiddenValue("_H_Load", "false");
	}
}

function RedirectOut()
{
	var RedirectPage = GetHiddenValue("_H_RedirectPage");
	//alert(AutoSubmit);
	if(RedirectPage != null && RedirectPage != "")
	{
		RedirectFromMenu(RedirectPage);
	}
}

function clickIE4()
{
	if (event.button == 2)
	{
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers || document.getElementById && !document.all)
	{
		if (e.which==2 || e.which==3)
		{
			return false;
		}
	}
}

//////////////// CONTROL LOGIN SECTION//////////////////////////////////
/*
function ValidateLogin()
{
	alert("Validate Login!!!!");
	var UserName = GetHiddenValue("_Login__T_UserName");
	var Password = GetHiddenValue("_Login__T_Password");		
	var Message1 = GetHiddenValue("_Login__H_Warning_1");		
	var Message2 = GetHiddenValue("_Login__H_Warning_2");		
			
	if(UserName == "" || Password == "")
	{
		alert(Message1);
		return false;
	}
	/*
	if(UserName.length < 10)
	{
		alert(Message2);
		return false;
	}
	* /
	MakeSecure(true, "pg_Account.aspx");
	return true;
}
*/
/////////////////////DEFAULT.ASPX///////////////////////////////////////////////////
function OpenSecure(Page)
{
	//SetHiddenValue("_H_Action", Page);
	MakeSecure(true, Page);
	document.MainForm.submit();
	return false;
}

function OpenFromMenu(Page)
{
	//alert(Page);
	CloseAll(null);
	Open(Page);				
	return false;
}
/**
* Opens the <B>Page</B>
*/
/* 
function Open(Page)
{
	//alert(Page);
	//redirects to the management website
	if(Page == "management")
	{
		window.open("http://www.wwtworldphone.com/management","","width=830,height=500,status=yes,menubar=no,top=50,left=50,resizable=yes,scrollbars=yes");
		return false;
	}
	else if(Page == "technotes")
	{
		window.open("https://server.iad.liveperson.net/hc/s-4785396/cmd/kb/kbvisitorcontrol.jsp","","width=830,height=500,status=yes,menubar=no,top=50,left=50,resizable=yes,scrollbars=yes");
		return false;
	}
	else
	{
		parent.document.location.href = Page;
	}
	return false;		
}
*/
function Open(Page, Target)
{
	CloseAll(null);
	//alert(Page + " " + Target);
	
	if(Target != null && Target == "blank")
	{
		window.open(Page,"","width=830,height=500,status=yes,menubar=no,top=50,left=50,resizable=yes,scrollbars=yes");
	}
	else
	{
		parent.document.location.href = Page;
	}
	return false;		
}

///////////////UTILITIES////////////////////////////////////////////////
function GetHiddenValue(ID, DefaultValue)
{
	var OBJ = document.getElementById(ID);
	if(!OBJ)
		OBJ = parent.document.getElementById(ID);			
	return OBJ ? OBJ.value : DefaultValue;
}

function SetHiddenValue(ID, value)
{
	if(value == null)
		return;
	var OBJ = document.getElementById(ID);
	if(!OBJ)
		OBJ = parent.document.getElementById(ID);			
	if(OBJ && OBJ.tagName == "INPUT")
			OBJ.value = value;
}
function GetLang()
{
	return GetHiddenValue("_H_Language", "eng");
}
function MakeSecure(Secure, Page)
{
	SetHiddenValue("_H_Action", Page);
	document.MainForm.action = GetLocation(Secure);
}

function GetLocation(Secure)
{
	var Loc;
	var IsTest = parent.location.host.toString() == "localhost";
	Secure = (Secure == 'true' || Secure == true) && !IsTest;
	
	with(parent.location)
	{
		var Path = pathname.toString();
		//the case when the page is not specified
		if(Path.charAt(Path.length - 1) == '/')
			Path += "default.aspx";
		Loc = (Secure ? "https://": "http://")  + host.toString() + Path;
		return Loc;
	}
}
//--///////////////////////////CONTROL MENU SECTION ///////////////////////////--//
/**
	*   Closes the MenuPanel when mouse exites it
	*/
function MenuPanelOut()
{
	var DIV = window.event.srcElement;
	while(DIV.tagName != "DIV")
	{
		DIV = DIV.parentElement;
	}
	var sX = document.body.scrollLeft;
	var sY = document.body.scrollTop;
	var X =	 window.event.x + sX;
	var Y =	 window.event.y + sY;
	
	if(	X <= DIV.offsetLeft	|| 
		Y <= DIV.offsetTop	|| 
		X >= DIV.offsetLeft + DIV.offsetWidth || 
		Y >= DIV.offsetTop + DIV.offsetHeight)
	{
		CancelFadeIn = 1;
		DIV.style.display = "none";
	}
}

function MenuItemOver()
{		
	var TB = window.event.srcElement;
	TB.style.color = "#00FFF0";
		
	while(TB.tagName != "TD")
	{
		TB = TB.parentElement;
	}
	
	for (var i = 0; i < TB.children.length; i++)
	{
		TB.children[i].style.color = "#00FFF0";
	}
}

function MenuItemOut()
{		
	var TB = AA = window.event.srcElement;
	TB.style.color = "white";
    //TB.style.filter = "alpha(opacity=100,finishopacity=100,style=0)";
   
	while(TB.tagName != "TD")
	{
		TB = TB.parentElement;
	}
		
	for (var i = 0; i < TB.children.length; i++)
	{
		TB.children[i].style.color = "white";
	}
}

function MenuOver()
{		
	CancelFadeIn = 0;
	var TB = AA = window.event.srcElement;
	//TB.style.color = "#002569";
	
	while(TB.tagName != "TD")
	{
		TB = TB.parentElement;
	}
	//TB.style.background = "#D41010";
	TB.style.background = "#D10C0C";
	
	TB.style.border = "1 solid #B70B0B";
			
	var DIV;
	
	for (var i = 0; i < TB.children.length; i++)
	{
		if(TB.children[i].tagName == "DIV")
		{
			DIV = TB.children[i];
			break;
		}
	}
		
	if(DIV && DIV.style.display == "none" && CancelFadeIn == 0)
	{
		var X = GetOffsetX(TB);
		var Y = GetOffsetY(TB) + TB.offsetHeight;
		DIV.style.left	  = X;
		DIV.style.top	  = Y;
		DIV.style.display = "block";
		/*
		CancelFadeIn = 0;
		oc = 0;
		FadeObj = DIV;
		FadeIn();
		*/
		//setTimeout('FadeIn()',200);
	}
	CloseAll(DIV);
}
var FadeObj;
var oc=0;
var CancelFadeIn = 0;

function FadeIn() 
{
    if(!FadeObj || CancelFadeIn == 1 || oc >= 110)
    {
		return;
	}
	var FinishOpacity = (oc >= 100)? 95 : oc; 
    FadeObj.style.filter="Alpha(opacity="+oc+", finishopacity="+ FinishOpacity +", style=2)"
    setTimeout('oc = oc + 15;FadeIn()',((oc < 50)? 10: 50));
}

function MenuOut()
{	
	CancelFadeIn = 1;	
	//window.status = "MouseOut";
	var TB = window.event.srcElement;
	TB.style.color = "white";
	
	while(TB.tagName != "TD")
	{
		TB = TB.parentElement;
	}
	TB.style.background = "#B70B0B";
	TB.style.border = "1 solid #B70B0B";
	
	var sY = document.body.scrollTop;
	var Y =	 window.event.y + sY;
	var YY  = GetOffsetY(TB) + TB.offsetHeight - 1;
	
	//window.status = "Y = " + Y + " YY = " + YY + " sY=" + sY ;
	if(Y >= YY && Y - YY < 40/*IE bug*/)
	{
		return;
	}
	
	var DIV;
		
	for (var i = 0; i < TB.children.length; i++)
	{
		if(TB.children[i].tagName == "DIV")
		{
			DIV = TB.children[i];
			break;
		}
	}
	if(DIV)
		DIV.style.display = "none";
	
}
function RedirectFromMenu(Page) 
{
	parent.document.MainForm.action = Page;
	parent.document.MainForm.submit();
	return false;
}


function GetOffsetX(Tag)
{
	var X = 0;
	while(Tag.tagName != "FORM")
	{
		if(Tag.tagName != "TR")//returns the same with TD
		{
			X += Tag.offsetLeft;
		}
		Tag = Tag.parentElement;
	}
	return X;
}
function GetOffsetY(Tag)
{
	var Y = 0;
	while(Tag.tagName != "FORM")
	{
		if(Tag.tagName != "TR")//returns the same with TD
		{
			Y += Tag.offsetTop;
		}
		Tag = Tag.parentElement;
	}
	return Y;
}
/**
	*  closes all non-selected menus (except <DIV> element);
	**/
function CloseAll(DIV)
{
	
	for (var i = 0; i < document.getElementsByTagName("DIV").length; i++)
	{
		if(document.getElementsByTagName("DIV").item(i).type &&
			document.getElementsByTagName("DIV").item(i).type == "MenuPanel")
		{
			if(DIV && document.getElementsByTagName("DIV").item(i) == DIV)
				continue;
			document.getElementsByTagName("DIV").item(i).style.display = "none"; 
		}
	}
}
	
//////////////////////////////// CONTROL FORM SECTION////////////////////////////////////////
function Action(LinkName)
{
	if(LinkName == "_Link_TermsOfService")
	{
		var Lang = (document.getElementById("_Basic__Form__H_Lang") != null)
					? document.getElementById("_Basic__Form__H_Lang").value
					: "eng";
		var URL = "terms.aspx?lang=" + Lang + "&header=false&options=false";
		var Win = window.open(URL,"","width=680,status=yes,menubar=true,top=100,left=50,resizable=yes,scrollbars=yes");
		return false; 
	}
	
	if(document.getElementById("_Basic__Form__H_Action") != null)
	{
		document.getElementById("_Basic__Form__H_Action").value = LinkName;
	}
}
function PopUp(LinkName)
{
	
	//alert(LinkName);
	if(LinkName == "")
		return false;
	if(LinkName.substring(0, 1) == "#")
		LinkName = "page_help.html" + LinkName;	
	window.open(LinkName,"","width=660,height=400,status=no,menubar=no,top=50,left=50,resizable=false,scrollbars=yes");
	return false; 
	
}
function Redirect(LinkName)
{
	if(LinkName == "")
		return false;
	self.location = LinkName;	
}
function MouseOver()
{		
	var TB = window.event.srcElement;
	TB.style.textDecoration = "none";
	TB.style.color = "Red";
	return true;	
}
function MouseOut()
{		
	var TB = window.event.srcElement;
	TB.style.textDecoration = "underline";
	TB.style.color = "#840000";
	return true;	
}
////////////////////////////////////// CONTROL GRID SECTION	////////////////////////////////
function GridAction(Action, ID)
{
	DoSL();
	//alert("Action = " + Action + " ID = " + ID);
	if(Action != null)
	{
		document.getElementById("_Basic__Form__Grid__H_GridAction").value = Action;
	}
	if(ID != null)
	{
		document.getElementById("_Basic__Form__Grid__H_GridID").value = ID;
	}
	
	var len = document.forms[0].elements.length;
	
	// DELETE //
		
	if(Action == "delete")
	{
		//alert(Action);
		// check if there is at least one row selected //
		for (var i = 0; i < len; i++)
		{
			var Element = document.forms[0].elements[i];
			var sID = Element.id;
				
			if (Element.type != "checkbox")
				continue;
			
			//alert(sID);
			var ToBlock = true;
			if(	sID.indexOf("Grid") > 0		&& 
				sID.indexOf("_All") == -1	&&
				Element.checked)
			{
				ToBlock = false;
				break;
			}
		}
		
		if(ToBlock)
		{
			alert("There is no row selected. Please select the row and try again.");
			return false;
		}
		
		return window.confirm("Are you sure you want to delete?");
	}
	// ALL //
	else if(ID == "_All")
	{
		var Check = document.getElementById("_Basic__Form__Grid__All");
		
		for (var i = 0; i < len; i++)
		{
			var Element = document.forms[0].elements[i];
			
			if (Element.type == "checkbox" && Element.id.indexOf("Grid") > 0)
			{
				document.forms[0].elements[i].checked = Check.checked;
			}
		}
		DoSL();
	}
	
	else if(Action == "Remove")
	{
	   return window.confirm("Are you sure you want to delete?");
	}
	
	else if(document.getElementById("_Basic__Form__Grid__All") != null)
	{
		document.getElementById("_Basic__Form__Grid__All").checked = false;
	}
	return true;
}
function SelectRow(Row)
{
	//Row.style.background = "#ffffad";
	Row.style.background = "#eeeeee";
}
function UnselectRow(Row)
{
	Row.style.background = "#FFFFFF";
}

function DoSL()
{
	//alert("DoSL");
	var CH1 = document.getElementById("_Basic__Form__Grid__GridTable");
	
	if(CH1 == null || CH1.Highlight == "false")
		return;
	//alert(CH1.Highlight);	
	for (var i = 0; i < CH1.rows.length; i++)
	{ 
		var len = CH1.rows[i].all.length;
		for (var j = 0; j < len; j++)
		{
			var obj = CH1.rows[i].all[j];
			
			if(obj.tagName == "INPUT" && obj.type != "image")
			{
				if(obj.checked || obj.selected)
					SelectRow(CH1.rows[i]);
				else
					UnselectRow(CH1.rows[i]);	
			}
		}
	}
}
function OnLoad()
{
	//alert("OnLoad");
	RedirectOut();
	DisableRightClick();
	DoSL();//FOR CONTROL_GRID TO SELECT THE FIRST ROW
	AutoSubmit();
	//CheckLogin();
	SessionExpired();
	ShowPopupOnInit(); 
	window.scrollTo(0, 0);
}
function ShowPopupOnInit()
{
	var PopUrl = GetHiddenValue("_Basic__H_Popup");
	//alert(PopUrl);
	if(PopUrl && PopUrl.length > 0)
	{
		SetHiddenValue("_Basic__H_Popup", "");
		doModal2(PopUrl, "");
		//window.open(PopUrl,"","width=560,height=550,status=no,menubar=no,top=40,left=40,resizable=false,scrollbars=yes");
	}
	
}

function doModal2(url, dialogarg)
{
   var strFeatures = "dialogWidth:560px;dialogHeight:550px;" +
      "help:no;maximize:yes;minimize:yes;status:no;unadorned:yes";
   var cRetValue=showModalDialog(url,dialogarg,strFeatures);
   /*
   if (cRetValue == null)
   {
      alert('You clicked the cancel or close button');
   }
   else
   {
      alert(cRetValue);
   }
   */
}
 /*
function CheckLogin()
{
	alert("CHECK LOGIN");
	var SHOW = GetHiddenValue("_Header__Login__H_ShowWarning", "false");
	alert("SHOW = " + SHOW);
	SHOW = GetHiddenValue("_Login__H_ShowWarning", "false");
	alert("SHOW1 = " + SHOW);
	var M1	 = GetHiddenValue("_Header__Login__H_Warning_2");
	if(SHOW == "true")
	{
		alert(M1);
		//return false;
	}
	SetHiddenValue("_Header__Login__H_ShowWarning", "false");
}
*/
function keyDown()
{
	var code = window.event.keyCode;
	if (window.event.keyCode == 13)
	{
		if( document.getElementById("_Basic:_B_Continue") != null)
			document.getElementById("_Basic:_B_Continue").focus();
		else if( document.getElementById("_B_Send") != null)	
		{
			document.getElementById("_B_Send").focus();
		}
			
	}
	return true;
}
function pdf()
{
	window.open("PDF/X-PRO.pdf","","width=800,height=600,status=yes,menubar=yes,top=10,resizable=yes");
}
function down()
{
	//alert("Down!!!");
	window.open("download/WWTelcoPhone_Installer.exe", "", "width=1,height=1");
	Instructions();
	return false;
	
}

function Instructions()
{
	var Language = "EN";
	var Lang = document.getElementById("_H_Language");
	if(Lang != null)
		Language = Lang.value;
	//alert(Language);
	var Location = "help/" + Language + "/help_install.html";
	WinBIG = window.open(Location, "", "width=520,height=470,status=no,menubar=no,top=1,left=1,resizable=false,scrollbars=yes");
	return false; 
}	
	
////////////////////////////////////////////////////////////////////////
document.onkeydown   = keyDown;
document.oncontextmenu=new Function("return false");
//window.history.forward(1);
window.onload = OnLoad;
window.onunload = CloseAll;



