﻿// JScript File
//add intellisense for jquery.
/// <reference path="jquery-vsdoc.js" />



function popUpCenter(name, filename, height, width)
{
	var l;
	var t;
	var settings;
	var maxHt = screen.availHeight - 50;
	var maxWt = screen.availWidth - 10;
	var oldHt = screen.height;
	var oldWt = screen.width;
	
	name = "XXX_" + name;
	
	l = (screen.width) ? (maxWt-width)/2 : 0;
	t = (screen.height) ? (maxHt-height)/2 : 0;
	settings = "height=" + height + ",width=" + width + ",top=" + t + ",left=" + l + ",scrollbars=1,menubar=0,resizable=1,status=1,location=0";

		if ( (typeof popupwindow == "object") && (popupwindow.closed != true) )
		{
			popupwindow.close();
		}
		
	popupwindow = window.open(filename, name, settings);
	popupwindow.focus();
	void(0);
	//return popupwindow;
}

function popUpRelative(name, filename, height, width)
{
	var settings, l, t;
	var screenY = document.body.offsetHeight;
	var screenX = window.screen.availWidth;
	var cursorX = event.screenX;
	var cursorY = event.screenY;
	var padAmtX = 0;
	var padAmtY = 7;
	
	name = "XXX_" + name;
	
		if((cursorY + height + padAmtY) > screenY) 
		{
		// make sizes a negative number to move left/up
		padAmtY = (-30) + (height * -1);
		// if up or to left, make 30 as padding amount
		}
		
		if((cursorX + width + padAmtX) > screenX)	
		{
		padAmtX = (-30) + (width * -1);	
		// if up or to left, make 30 as padding amount
		}	

	l = cursorX + padAmtX;
	t = cursorY + padAmtY;

	settings = "height=" + height + ",width=" + width + ",top=" + t + ",left=" + l + ",scrollbars=0,menubar=0,resizable=0,status=0,location=0,titlebar=0,toolbar=0";

		if ( (typeof popupwindow == "object") && (popupwindow.closed != true) )
		{
			popupwindow.close();
		}
		
	popupwindow = window.open(filename, name, settings);
	popupwindow.focus();
	void(0);
	return;
}

function popUpDialog_Relative(PopUpFilePathURL, height, width, ControlArrayToUpdate, DialogArgs)
{
	var settings, l, t;
	var screenY = document.body.offsetHeight;
	var screenX = window.screen.availWidth;
	var cursorX = event.screenX;
	var cursorY = event.screenY;
	var padAmtX = 0;
	var padAmtY = 7;

		if((cursorY + height + padAmtY) > screenY) 
		{
		// make sizes a negative number to move left/up
		padAmtY = (-30) + (height * -1);
		// if up or to left, make 30 as padding amount
		}
		
		if((cursorX + width + padAmtX) > screenX)	
		{
		padAmtX = (-30) + (width * -1);	
		// if up or to left, make 30 as padding amount
		}	

	l = cursorX + padAmtX;
	t = cursorY + padAmtY;

	settings = "dialogHeight:" + height + "px;dialogWidth:" + width + "px;dialogTop:" + t + "px;dialogLeft:" + l + "px;scroll:1;resizable:1;status:0;unadorned:0;center:0;dialogHide:0;edge:raised;help:0";
	//alert(settings);

	return popUpDialog(PopUpFilePathURL, settings, ControlArrayToUpdate, DialogArgs);;
}

function popUpDialog_Center(PopUpFilePathURL, height, width, ControlArrayToUpdate, DialogArgs)
{
	var l;
	var t;
	var settings;
	var maxHt = screen.availHeight - 50;
	var maxWt = screen.availWidth - 10;
	var oldHt = screen.height;
	var oldWt = screen.width;
	
	name = "XXX_" + name;
	
	l = (screen.width) ? (maxWt-width)/2 : 0;
	t = (screen.height) ? (maxHt-height)/2 : 0;
	//settings = "dialogHeight:" + height + "px;dialogWidth:" + width + "px;dialogTop:" + t + "px;dialogLeft:" + l + "px;scroll:1;resizable:1;status:0;unadorned:0;center:1;dialogHide:0;edge:raised;help:0";
	settings = "dialogHeight:" + height + "px;dialogWidth:" + width + "px;scroll:1;resizable:1;status:0;unadorned:0;center:1;dialogHide:0;edge:raised;help:0";

	return popUpDialog(PopUpFilePathURL, settings, ControlArrayToUpdate, DialogArgs);;
}


function popUpDialog(PopUpFilePathURL, settings, ControlArrayToUpdate, DialogArgs)
{
	//alert(settings);
	var ret = new Array();
	ret = window.showModalDialog(PopUpFilePathURL, DialogArgs, settings);

	if ((ret != null) && (ControlArrayToUpdate != null))
		{
			for (var i = 0; i < ret.length; i ++)
			{
			ControlArrayToUpdate[i].value = ret[i];
			}
		/*
			if ((DisplayTextBox) && (ret.length == 1))
				{DisplayTextBox.value = strRetVal[0];}
			if ((HiddenTextBox) && (ret.length == 2))
				{HiddenTextBox.value = strRetVal[1];}
		*/
		}
	
	return ret;
}

function FindControlByID(ID)
{
	var ctlRet = null;
    
    if (document.all)
    {
	    for (var i=0; i<document.all.length; i ++)
	    {
		    if (document.all[i].id)
		    {
			    if (document.all[i].id.indexOf(ID) > -1)
			    {
				    ctlRet = document.all[i];
				    break;
			    }
		    }
	    }
	}
	
	return ctlRet;
	
}

function disableEnterKey()
{

//alert(event.keyCode);

	if ( (window.event.keyCode == 13)  && (event.srcElement.type != 'textarea') && (event.srcElement.type != 'submit') )
	{
		event.returnValue=false; 
		event.cancel = true;
	}

}

function disableEnterKeyReplaceWithTab()
{

//alert(event.keyCode);
	
	if ( (window.event.keyCode == 13)  && (event.srcElement.type != 'textarea') && (event.srcElement.type != 'submit') )
	{
		//event.returnValue=false; 
		//event.cancel = true;
		event.keyCode = 9;
		//alert(event.keyCode);
	}
}



function captureControlS()
{
//- s = 83.

var SKey = "83";
var key = new String(window.event.keyCode);


	if ( ( (event.ctrlKey) ) && (key == SKey) ) 
	//if ((event.ctrlKey) && (key == SKey)) 
	{
		//alert(" CTL S was Pressed!");
		//CHAR_CODE = SKey;
	}
	else
	{
	//CHAR_CODE = -1;
	}

}	

function CheckFieldLength(ctl,iMaxLen)
{
	var val = ctl.value;

		if (val)
			{
				if (val.length > iMaxLen)
					{
						alert('Maximum number of characters allowed is ' + iMaxLen + '.  The content entered has been shortened to meet this requirement.');
						val = val.substr(0,iMaxLen);
						ctl.value=val;
					}
			}
}

function TrimString(sInString) {
sInString = sInString.replace(/^\s+/g, "");
return sInString.replace(/\s+$/g, "");
}

function ReplaceAll(Source, stringToFind, stringToReplace)
{
    var temp = Source;
    var index = temp.indexOf(stringToFind);

    while (index != -1)
    {
        temp = temp.replace(stringToFind, stringToReplace);
        index = temp.indexOf(stringToFind);
    }

    return temp;
}

//var CHAR_CODE = -1;

	function FormatEntry(source, eventArgs) {

		var target = source.get_completionList();
		var children = target.childNodes;
		for (var i = 0; i < children.length; i++) {

		    //var parent_LI = children[i].parentElement;
			var child = children[i];           //this is an LI.
			var value = child._value;
			var text = child.innerHTML;
			// Bold the searchText part of the value
			//child.innerHTML = eval("<span style='color: " + value + "'>" + child.innerHTML + "</span>");
			//child.innerHTML = "<span><div style=\"height: 5px; width: 5px; display: inline-block; border: solid 1px #000; background-color:" + value + "\";></div>&nbsp;&nbsp;" + text + "</span>";
			
			//add div to bottom of LI element.
			var div = document.createElement("div");
			div.innerHTML = "<div style=\"height: 5px; width: 75%; display: inline-block; overflow: hidden; border: solid 1px #000; background-color:" + value + "\";>&nbsp;</div>";
			child.appendChild(div);
			
		}
}

function isNull(o)
{
    if (typeof (o) != "undefined" && typeof (o) != "unknown" && o != "undefined" && o != null && o)
        return false;
    else
        return true;
}

function __doExternalPost(targetUrl, newWindow) {
    theForm.__VIEWSTATE.value = "";
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    if (newWindow)
        theForm.target = "_blank";
    else
        theForm.target = "";

    theForm.submit();
}

function renameBadIDs()
{

    //$("#submit").attr("id", "submit1");

}

