var viewportwidth;
var viewportheight;
var newwindow = null;

/*// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
} */

if (window.innerWidth) {
    viewportwidth = window.innerWidth;
    viewportheight = window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
    viewportwidth = document.documentElement.clientWidth;
    viewportheight = document.documentElement.clientHeight;
}
else if (document.body) {
    viewportwidth = document.body.clientWidth;
    viewportheight = document.body.clientHeight;
}

function MyOnChangeFnc(pTBId, pDate)
{
	var vTBFld = PDP_GetById(pTBId);
	PDP_SetAtt(vTBFld, "Changed", true);
}

// set the selected tab and resset the TimeOfDay text box spin controls so they do not 
// appear when selecting between tabs
function afterSelectEvent(owner, tabItem, evnt)
{ 
    //debugger;
	try
	{
		var text = tabItem.getText();
		var tab = document.getElementById("BaseQueryControlTab1_UltraWebTab1");
		if(tab !== null)
		{
			tab.setAttribute("SELECTEDTAB",text);
		}
		TMTB_Resize();
	}
	catch(e)
	{}
} 

function ValidateMoney(objSource, objArgs)
{
	var intNumber = objArgs.Value;
	objArgs.IsValid = false;
	if (intNumber >= 0 && intNumber <= 1000000) {
		objArgs.IsValid = true;
	}
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function EnableLoadingWithTab(label, grid, label2, label3, tabcontrol)
{
	if (document.getElementById) {
		var input = document.getElementById(label);
		if (input !== null) {
	//		if (input.style.visibility == 'hidden') {
				input.style.visibility = 'visible';
				input.style.display = 'block'; //}
		}
		input = document.getElementById(grid);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
		input = document.getElementById(label2);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
		input = document.getElementById(label3);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
		var tabObject = igtab_getTabById(tabcontrol);
		if (tabObject !== null) {
		var Tab = null;
		for (i=1; i<tabObject.Tabs.length;i++)
         {
			Tab = tabObject.Tabs[i];
			if (Tab !== null) {
			  if (Tab.Key == 'tab_results') {
				Tab.setEnabled(false);
			  }
			  else {
				Tab.setVisible(false);
			  }
			}
         }
		}
	}

	return true;
}

function EnableLoading(label, grid, label2, label3)
{
	if (document.getElementById) {
		var input = document.getElementById(label);
		if (input !== null) {
	//		if (input.style.visibility == 'hidden') {
				input.style.visibility = 'visible';
				input.style.display = 'block'; //}
		}
		input = document.getElementById(grid);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
		input = document.getElementById(label2);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
		input = document.getElementById(label3);
		if (input !== null) {
				input.style.visibility = 'hidden';
				input.style.display = 'none'; //}
		}
	}

	return true;
}

function fnTrapKD(e,btn)
{
	if (navigator.appName== 'Netscape') {
		if (e.which == 13) {
			if (document.createEvent) {
				var evt = document.createEvent('MouseEvents');
				evt.initEvent ('click', true, true);
				btn.dispatchEvent(evt); 
			}
			else 
			if (btn.click) {
				bth.click();
			}
			return true;
		}
	}
	else {
		if (event.keyCode == 13) { 
		    event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
   } 
}


function deleteUserPrompt(label) {
	var input = document.getElementById(label);
	if (input != null) {

	    var text = "Do you want to delete the '"+input.innerText+"' User?";
		if(window.confirm(text))   
		{  
		}
		else
		{    
			event.returnValue = false;
		}
	}

//  window.event.returnValue = false;
//  window.showModalDialog('/Ameriweb/Administration/DeleteUser.aspx', '', 'dialogHeight: 250px;')
	
//   WinId = window.open('/Ameriweb/Administration/DeleteUser.aspx','newwin','width=300,height=300,status');
//   if (!WinId.opener) WinId.opener = self;
}

function deleteCodePrompt(label) {
	var input = document.getElementById(label);
	if (input != null) {
	    var index = input.selectedIndex;
	    var text = "Do you want to delete code '"+input.options[index].text+"' ?";
		if(window.confirm(text))   
		{  
		}
		else
		{    
			event.returnValue = false;
		}
	}
}

function dropdown(mySel)
{
var myWin, myVal, myText;
var input = document.getElementById(mySel);
if (input != null)
{
	
	myVal = input.options[input.selectedIndex].value;
	myText = input.options[input.selectedIndex].text;
	//window.confirm(myVal);
	//window.confirm(myText);
	if(myVal)
	{
	//if(mySel.form.target)myWin = parent[mySel.form.target];
	//else  myWin = window;
	// if (! myWin) return true;
	// myWin.location = myVal;
		myWin = window.open(myVal,myText);
	   // if (window.foucs) {myWin.foucs()}
	}
}
return false;
}

function dropdownbyobject(mySel)
{
var myWin, myVal, myText;
var input = mySel;
if (input != null)
{
	
	myVal = input.options[input.selectedIndex].value;
	myText = input.options[input.selectedIndex].text;
//	window.confirm(myVal);
//	window.confirm(myText);
	if(myVal)
	{
	//if(mySel.form.target)myWin = parent[mySel.form.target];
	//else  myWin = window;
	// if (! myWin) return true;
	// myWin.location = myVal;
		myWin = window.open(myVal,'a');
	   // if (window.foucs) {myWin.foucs()}
	}
}
return false;
}

function PrintReport(s, e) {
    var value = s.GetValue();
    //open in new window
    if (value != '') {
        newwindow = window.open(value, 'PrintReport', 'scrollbars=no,menubar=no,resizable=yes,toolbar=no,location=no,status=no');
        if ((window.focus) && (newwindow != null)) {
            setTimeout('newwindow.focus()', 100);
        }
        return false;
    }
}

function PrintReportByID(ClientID) {
    // debugger;
    
    //if (navigator.appName != 'Microsoft Internet Explorer') {
    //    alert('AmeriWeb requires Internet Explorer for all reports.');
    //    return;
    //}
    var ddlReports = document.getElementById(ClientID);
    if (ddlReports == null) return;
    var value = ddlReports[ddlReports.selectedIndex].value; 
    //open in new window
    if (value != '') {
        newwindow = window.open(value, 'PrintReport', 'scrollbars=no,menubar=no,resizable=yes,toolbar=no,location=no,status=no');
        if ((window.focus) && (newwindow != null)) {
            setTimeout('newwindow.focus()', 100);
        }
        return false;
    }
}

function ResizeReport(reportviewer) {
   // debugger;
    var rptViewer = document.getElementById(reportviewer);
    if (rptViewer == null) return;
    var rptwidth = rptViewer.offsetWidth + rptViewer.offsetLeft;
    var rptheight = rptViewer.offsetHeight + rptViewer.offsetTop;
    var scrnx = (screen.width - rptwidth) / 2;
    var scrny = (screen.height - rptheight) / 2;
    window.resizeTo(rptwidth, rptheight);
    window.moveTo(scrnx, scrny)
    window.focus();
}

function doPostBackAsync(eventName, eventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }

    __doPostBack(eventName, eventArgs);
}

function Lookup(key) {
    return (this[key]);
}


function Delete() {
    for (c = 0; c < Delete.arguments.length; c++) {
        this[Delete.arguments[c]] = null;
    }
    // Adjust the keys (not terribly efficient)
    var keys = new Array()
    for (var i = 0; i < this.Keys.length; i++) {
        if (this[this.Keys[i]] != null)
            keys[keys.length] = this.Keys[i];
    }
    this.Keys = keys;
}

function Add() {
    for (c = 0; c < Add.arguments.length; c += 2) {
        // Add the property
        this[Add.arguments[c]] = Add.arguments[c + 1];
        // And add it to the keys array
        this.Keys[this.Keys.length] = Add.arguments[c];
    }
}

function Dictionary() {
    this.Add = Add;
    this.Lookup = Lookup;
    this.Delete = Delete;
    this.Keys = new Array();
}


