var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
var dialogWin = new Object()
var	ns4 = (document.layers)? true:false
var	ns6 = (navigator.userAgent.indexOf("Gecko")!=-1)?true:false
var	ie4 = (document.all)? true:false
var ns6old = (navigator.userAgent.indexOf("Gecko/2001")!=-1)?true:false;

function CheckedChange(radio, objid)
{
	for (i=0; i<document.forms[0].elements.length;i++)
	{
		if (document.forms[0].elements[i].type=="text")
			{
				isListName = document.forms[0].elements[i].id.toString();				
				k = isListName.lastIndexOf("listName");	//Hard coded: Search for conrol listname only
				if (k > 0)
				{					
					document.forms[0].elements[i].style.backgroundColor = "white";
					document.forms[0].elements[i].style.color = "black";
				}
			}
	}

	if (radio.checked) 
	{		
		document.getElementById(objid).style.backgroundColor = "khaki";
		document.getElementById(objid).style.color = "black"
	}
	else
	{
		document.getElementById(objid).style.backgroundColor = "white";
		document.getElementById(objid).style.color = "black"
	}
}

//divRoleList - Role Based Shortlist
//For the selected radiobutton, change the background colour of the parent div it resides within
function DivRoleListChange(radio,divID)
{
	//update all divRoleList, set to default color
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++)
	{   		
		var divname = divs[i].id; 		
		if(divname.indexOf("divRoleList") >= 0)
		{ 			
			divs[i].style.backgroundColor = "#dedfe1";
		}		
	}
		
		
	//update selected divRoleList, set new background color
	if (radio.checked) 
	{
		document.getElementById(divID).style.backgroundColor = "#c8c8c8";
	}	
}

function openDGDialog(url, width, height, returnFunc, args) 
{
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) 
	{
		// Initialize properties of the modal dialog object.
		dialogWin.dialogTarget = args
		dialogWin.returnFunc = returnFunc
		dialogWin.returnedValue = ""
		dialogWin.args = args
		dialogWin.url = url
		dialogWin.width = width
		dialogWin.height = height
		
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		dialogWin.name = (new Date()).getSeconds().toString()
		
		// Assemble window attributes and try to center the dialog.
		if (Nav4) {
			// Center on the main window.
			dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2)
			dialogWin.top = window.screenY +  ((window.outerHeight - dialogWin.height) / 2)
			
			var attr = "screenX=" + dialogWin.left + 
					",screenY=" + dialogWin.top + ",resizable=no,width=" + 
					dialogWin.width + ",height=" + dialogWin.height
		} 
		else 
		{
			// The best we can do is center in screen.
			dialogWin.left = (screen.width - dialogWin.width) / 2
			dialogWin.top = (screen.height - dialogWin.height) / 2
			var attr = "left=" + dialogWin.left + ",top=" + 
			   dialogWin.top + ",resizable=no,status=yes,width=" + dialogWin.width + 
			   ",height=" + dialogWin.height
		}
		
		// Generate the dialog and make sure it has focus.
		dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr)
		dialogWin.win.focus()

	} 
	else 
	{
		dialogWin.win.focus()
	}
	
}

// Event handler to inhibit Navigator form element 
// and IE link activity when dialog window is active.
function deadend() {
	if (dialogWin.win && !dialogWin.win.closed) {
		dialogWin.win.focus()
		return false
	}
}

// Since links in IE4 cannot be disabled, preserve 
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks

// Disable form elements and links in all frames for IE.
function disableForms() {
	IELinkClicks = new Array()
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = true
			}
		}
		IELinkClicks[h] = new Array()
		for (i = 0; i < frames[h].document.links.length; i++) {
			IELinkClicks[h][i] = frames[h].document.links[i].onclick
			frames[h].document.links[i].onclick = deadend
		}
		frames[h].window.onfocus = checkModal
    	frames[h].document.onclick = checkModal
	}
}

function enableForms() {
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = false
			}
		}
		for (i = 0; i < frames[h].document.links.length; i++) {
			frames[h].document.links[i].onclick = IELinkClicks[h][i]
		}
	}
}

function blockEvents() {
	if (Nav4) {
		window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = deadend
	} else {
		disableForms()
	}
	window.onfocus = checkModal
}

function unblockEvents() {
	if (Nav4) {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = null
		window.onfocus = null
	} else {
		enableForms()
	}
}

function checkModal() {
	setTimeout("finishChecking()", 50)
	return true
}

function finishChecking() {
	if (dialogWin.win && !dialogWin.win.closed) {
		dialogWin.win.focus() 
	}
}


function setPrefs() 
{
		__doPostBack(dialogWin.dialogTarget, dialogWin.returnedValue);
}

function __closeDialog(dialogResult)
{
	//Used by : Page.RegisterCloseDialogStartupScript dynamically writing scripts.
	//			RegisterCloseDialogStartupScript used by e.g UserSMSSettings.buttonFinished_Click.
	//A parent browser-page (i.e opener) creates a popup-dialogue which returns a dialogResult to 
	//its parent page and do a postback.
	//If there is no parent browser-page involved then it simply closes itself.
	if (opener && !opener.closed) {

		opener.dialogWin.returnedValue = dialogResult;
		opener.setPrefs(); // call to post back function
	}
	window.close();
}


function __isSelectionOnText()
{
	var range = document.selection.createRange();
	if (range.text.length == 0)
	{
		range.expand("word");
		if (range.text.length != 0)
		{
			return true;
		}
	}
	return false;
}


function __openDialog(eventTarget, url, dialogHeight, dialogWidth)
{
	var eventArgument = window.showModalDialog(url, "", "dialogHeight:" + dialogHeight + ";dialogLeft:100px;dialogTop:100px;dialogWidth:" + dialogWidth + ";help:no;resizable:yes;scroll:no;status:no");
	if (eventArgument && __doPostBack)
	{
		__doPostBack(eventTarget, eventArgument);
	}
}

var rows = new Array();
var rows_nn = 0;

function swapon(id) {
	if (!ns4) 
	{
		document.getElementById(id).style.backgroundColor = '#E3D9C4';
		var _children = document.getElementById(id).children;
		for (i=0; i < _children.length; i++)
		{
			_children[i].style.backgroundColor = '#999999';
		}
	}
}

function swapoff(id) {
	if (!ns4) 
	{
		idnum = id.slice(4) - 1;
		document.getElementById(id).style.backgroundColor = rows[idnum];
		
		var _children = document.getElementById(id).children;
		
		for(i=0; i < _children.length; i++)
		{
			_children[i].style.backgroundColor = rows[idnum];
		}
	}
}

function check_all() {
	if (!ns4) 
	{
		ii = 0;
		while (ii < rows.length) {
			document.getElementById("check" + (ii+1)).checked = true;
			swapon('cell' + (ii+1));
			ii++;
		}
	} 
	else 
	{
		ii = 0;
		while (ii < rows_nn) {
			document.basic.elements["check" + (ii+1)].checked = true;
			ii++;
		}
	}
}

function uncheck_all() {
	if (!ns4) 
	{
		jj = 0;
		while (jj < rows.length) {
			document.getElementById("check" + (jj+1)).checked = false;
			swapoff('cell' + (jj+1));
			jj++;
		}
	} 
	else 
	{
		jj = 0;
		while (jj < rows_nn) {
			document.basic.elements["check" + (jj+1)].checked = false;
			jj++;
		}
	}
}

function table_init() {
	if (!ns4) 
	{
		i = 0;
		while (document.getElementById('cell' + (i+1)) != null) {
			j = i + 1;
			rows[i] = document.getElementById('cell' + (i+1)).style.backgroundColor;
			i++;
		}

		i = 0;
		while (i < rows.length) {
			j = i + 1;
			document.getElementById('cell' + j).style.backgroundColor = rows[i];
			i++;
		}
	} 
	else 
	{
		i = 0;
		while (i < document.basic.elements.length) {
			if (document.basic.elements[i].name.indexOf("check") != -1) rows_nn++ ;
			i++;
		}
		rows_nn--;
	}
}

function swap(id, val) 
{
	if (!ns4) 
	{
		var _parent = document.getElementById(id).parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
		
		if(_parent)
		{
			_parent.style.border = (val=="on")?'1px solid #000000': '1px solid #FFFFFF';
		}
	}
}

function style_load() {
	 if (ns4) {
  		 document.write("<link rel=stylesheet href=\"Resources/CSS/Global_NS.css\" type=\"text/css\">");
   	 } else {
  		 document.write("<link rel=stylesheet href=\"Resources/CSS/Global.css\" type=\"text/css\">");
   	 }
}




function popUpBuySMS() 
{
	var arr	= null;
	var args = new Array();

	var _width  = 940;
	var _height = 600;
	var	_top	= (window.screen.availHeight-_height)/2;
	var	_left	= (window.screen.availWidth-_width)/2;
	var _options = "toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + _width + ",height=" + _height + ",top="+_top+",left="+_left;
	var _newwindow = window.open("BuySMS.htm","SMSCreditsWindow",_options);
	_newwindow.focus();
}

function popUpAgencyContacts() 
{
	//from popUpContacts() used by MenuBar
	var arr	= null;
	var args = new Array();

	var _width = 940;
	var _height = 600;
	var	_top	= (window.screen.availHeight-_height)/2;
	var	_left	= (window.screen.availWidth-_width)/2;
	var _options = "toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + _width + ",height=" + _height + ",top="+_top+",left="+_left;
	var _newwindow = window.open("ActorAdminFrames.htm","AdminWindow",_options);
	_newwindow.focus();
}

function popNewWindow(width,height,url,windowName)
{
	var _width	= width;
	var _height = height;
	var	_top	= 20;
	var	_left	= (window.screen.availWidth-_width)/2;
	var _options = "location=0,toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1,width=" + _width + ",height=" + _height + ",top="+_top+",left="+_left;
	var _newwindow = window.open(url,windowName,_options);
	_newwindow.focus();
}

function exp(strTag ,strAttribute)
{ 
	//eg onclick="exp('TABLE','ShowHide')
	var hiddenMe = document.getElementById("ShortListsList1_ShowList"); //hidden input state
	var elem = document.getElementsByTagName(strTag); 
	var elem1 = window.event.srcElement; 

	elem1.innerText=="Hide List"?elem1.innerText="Show List":elem1.innerText="Hide List"; 
 
	for (var i=0; i<elem.length; i++) 
	{ 
		if ((elem[i].getAttribute(strAttribute)=="yes") || (elem[i].getAttribute(strAttribute)=="no")) 
		{ 
			if (elem[i].style.display=='none')
			{ 
				elem[i].style.display='block';
				hiddenMe.value = "yes";
			}
			else
			{
				elem[i].style.display='none';
				hiddenMe.value = "no";
			}
		} 
	} 
} 


function InitShowHideShorlist(strTag ,strAttribute)
{ 
	//InitShowHideShorlist('TABLE','ShowHide') called by ShortListsList.ascx, see datagrid prerender
	var hiddenMe = document.getElementById("ShortListsList1_ShowList"); //hidden input state
	
	var elem1 = document.getElementById("ShowHide"); //the link
	var elem = document.getElementsByTagName(strTag); 
	for (var i=0; i<elem.length; i++) 
	{ 
		if(elem[i].getAttribute(strAttribute)=="yes") 
		{ 
			elem1.innerText="Hide List";
			elem[i].style.display='block';
			hiddenMe.value = "yes";
			break;
		} 
		else if(elem[i].getAttribute(strAttribute)=="no") 
		{ 
			elem1.innerText="Show List";
			elem[i].style.display='none';
			hiddenMe.value = "no";
			break;
		}
	} 
} 

//style_load();

