var browser=navigator.userAgent;

var availwidth=new Number(0);
var availheight=new Number(0);

var isIE=false;
var isIE7=false;
var isSafari=false;
var isFireFox=false;
var isOpera=false;
var isChrome = false;
if (browser.indexOf("Opera")>=0)
{
	isOpera=true;
	isIE=false;
	isSafari=false;
	isFireFox=false;
}
else if (browser.indexOf("MSIE")>=0)
{
	isIE=true;
	isOpera=false;
	isSafari=false;
	isFireFox=false;
	if (browser.indexOf("MSIE 7")>=0)
	{
	    isIE7=true;
	}
}
else if (browser.indexOf("Chrome") >= 0) {
    isChrome = true;
    isFireFox = false;
    isSafari = false;
    isIE = false;
    isOpera = false;
}
else if (browser.indexOf("Safari") >= 0)
{
	isSafari=true;
	isIE=false;
	isOpera=false;
	isFireFox=false;	
}
else if (browser.indexOf("Firefox")>=0)
{
	isFireFox=true;
	isSafari=false;
	isIE=false;
	isOpera=false;
}

if (isIE==true)
{
	availwidth=new Number(screen.width);
	availheight=new Number(screen.height);
}
else
{
	availwidth=new Number(screen.availWidth);
	availheight=new Number(screen.availHeight);
}

// Opens Modal dialog window
function OpenModalWindow(WinName,Url,iewidth,ieheight,nswidth,nsheight,scroll,status,resizable)
{
	if (isIE==true)
	{
		if (isIE7==true) {
		    ieheight=ieheight-30;
		}
		var objVal=window.showModalDialog("IFrameloader.aspx?url=" + Url + "&scroll=1&width=" + iewidth + "&height=" + ieheight + "","","scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";center:yes;" + "dialogWidth:" + iewidth + "px;dialogHeight:" + ieheight + "px;edge:sunken");
	}
	else {
		var ileft=(availwidth-nswidth)/2
		var itop = (availheight - nsheight) / 2

		var objVal=window.open(Url,WinName,"toolbars=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes," + "width=" + nswidth + ",height=" + nsheight + ",left=" + ileft + ",top=" + itop + "",true)
		if ((ileft + nswidth)>availwidth)
		{
			ileft=(ileft + nswidth)-(availwidth+5);
		}
		objVal.moveTo(ileft,itop-25);
	}
	return objVal;
}

function OpenModalWindowEx(WinName,Url,sArgs,nsArgsName,iewidth,ieheight,nswidth,nsheight,scroll,status,resizable)
{
	if (isIE==true)
	{
		if (isIE7==true)
		{
		    ieheight=ieheight-30;
		}
		var objVal=window.showModalDialog("IFrameloader.aspx?url=" + Url + "&scroll=1&width=" + iewidth + "&height=" + ieheight + "",sArgs,"scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";center:yes;" + "dialogWidth:" + iewidth + "px;dialogHeight:" + ieheight + "px;edge:sunken");
	}
	else
	{	
	
		var ileft=(availwidth-nswidth)/2
		var itop=(availheight-nsheight)/2
		var objVal=window.open(Url + "&" + nsArgsName + "=" + sArgs,WinName,"toolbars=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes,center=1," + "width=" + nswidth + ",height=" + nsheight + ",left=" + ileft + ",top=" + itop + "",true)
	}
	return objVal;
}

function OpenFLXCalendar(ctrl,imgName,e)
{					
	if (isIE==true)
	{
		var nleft=e.screenX;
		var ntop=e.screenY;
	}
	else
	{
		var nleft=e.screenX;
		var ntop=e.screenY;				
	}
	document.forms[0].txtDateControl.value=ctrl
	var sval='';
	eval('sval=document.forms[0].' + ctrl + '.value');
	objVal=OpenCalendarWindow("TAICalendar","TAICalendar.aspx?seldate=" + sval,240,235,235,205,0,0,0,nleft,ntop);
	if (isIE==true)
	{
		var sDate=new String(objVal)
		if (sDate!='undefined')
		{
			eval("document.forms[0]." + ctrl + ".value='" + objVal + "'");
		}
	}
}

function UpdateDateControl(strDate)
{
	if(isIE==false)
	{
		eval("document.forms[0]." + document.forms[0].txtDateControl.value + ".value='" + strDate + "'");
	}			
}

function OpenCalendarWindow(WinName,Url,iewidth,ieheight,nswidth,nsheight,scroll,status,resizable,ileft,itop)
{
	if (isIE==true)
	{
		if ((ileft + iewidth)>availwidth)
		{
			ileft=availwidth-(iewidth+10)
		}
		if ((itop + ieheight)>availheight)
		{
			itop=availheight-(ieheight+10)
		}
		if (isIE7==true)
		{
		    ieheight=ieheight-30;
		}
		var objVal=window.showModalDialog("IFrameloader.aspx?url=" + Url + "&scroll=" + scroll + "&width=" + iewidth + "&height=" + ieheight + ",left=" + ileft + ",top=" + itop + "","","scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";" + "dialogWidth:" + iewidth + "px;dialogHeight:" + ieheight + "px;edge:sunken;help:0;dialogHide:1;dialogLeft:" + ileft + "px;dialogTop:" + itop + "px" + "");
	}
	else
	{	
	
		if ((ileft + nswidth)>availwidth)
		{
			ileft=availwidth-(nswidth+10)
		}
		if ((itop + nsheight)>availheight)
		{
			itop=availheight-(nsheight+10)
		}
		var objVal=window.open(Url,WinName,"toolbars=no,help=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes," + "width=" + nswidth + ",height=" + nsheight + ",left=" + ileft + ",top=" + itop + "",true)
		
	}
	return objVal;
}

function OpenCalendarWindowEx(WinName,Url,iewidth,ieheight,nswidth,nsheight,scroll,status,resizable,ileft,itop,FrameUrl)
{
	if (isIE==true)
	{
		if ((ileft + iewidth)>availwidth)
		{
			ileft=availwidth-(iewidth+10)
		}
		if ((itop + ieheight)>availheight)
		{
			itop=availheight-(ieheight+10)
		}
		var objVal=window.showModalDialog(FrameUrl + "?url=" + Url + "&scroll=" + scroll + "&width=" + iewidth + "&height=" + ieheight + ",left=" + ileft + ",top=" + itop + "","","scroll:" + scroll + ";status:" + status + ";resizable:" + resizable + ";" + "dialogWidth:" + iewidth + "px;dialogHeight:" + ieheight + "px;edge:sunken;help:0;dialogHide:1;dialogLeft:" + ileft + "px;dialogTop:" + itop + "px" + "");
	}
	else
	{	
	
		if ((ileft + nswidth)>availwidth)
		{
			ileft=availwidth-(nswidth+10)
		}
		if ((itop + nsheight)>availheight)
		{
			itop=availheight-(nsheight+10)
		}
		var objVal=window.open(Url,WinName,"toolbars=no,help=no,scrollbars=" + scroll + ",resizable=" + resizable + ",modal=yes," + "width=" + nswidth + ",height=" + nsheight + ",left=" + ileft + ",top=" + itop + "",true)
		
	}
	return objVal;
}

function GetQueryString()
{
	var qs = location.search.substring(1).split("&");
	var Querystring = new Array()
	for(i=0;i<qs.length;i++)
	{
		t = qs[i].split("=")
		if(t[0] && t[1])
		{
			
			Querystring[t[0]] = unescape(t[1]);
		}
		
	}
}

function OpenWindow(surl,nwidth,nheight)
{
	var nleft=(availwidth-nwidth)/2;
	var ntop=(availheight-nheight)/2;
	window.open(surl,"endsession","toolbars=0,scrollbars=0,resizable=0,width=" + nwidth + ",height=" + nheight + ",left=" + nleft + ",top=" + ntop);
}

function OpenWindowSx(surl,nwidth,nheight)
{
	var nleft=(availwidth-nwidth)/2;
	var ntop=(availheight-nheight)/2;
	window.open(surl,"endsession","toolbars=1,scrollbars=1,resizable=1,location=1,width=" + nwidth + ",height=" + nheight + ",left=" + nleft + ",top=" + ntop);
}

function OpenWindowEx(surl,wname,nwidth,nheight,resizeable,scrollable,fullscreen,showtoolbars,showmenu,showaddresbar)
{
	var dwidth=parseInt(nwidth);
	var dheight=parseInt(nheight);
	if (dwidth<=0 || isNaN(dwidth))
	{
		dwidth=(availwidth * 65)/100;
		dwidth=parseInt(dwidth)
	}
	if (dheight<=0 || isNaN(dheight))
	{
		dheight=(availheight * 65)/100;
		dheight=parseInt(dheight)
	}
	
	var nleft=(availwidth/2-dwidth/2);
	var ntop=(availheight/2-dheight/2);
	nleft=parseInt(nleft);
	ntop=parseInt(ntop);
	if (showaddresbar==1 || showaddresbar=="yes" || showaddresbar=="true")
	{
		ntop=ntop-75;
		if (ntop<0)
		{
			ntop=0;
		}
	}
	var sfeatures="";
	if (isIE==true)
	{
		sfeatures="toolbar=" + showtoolbars + ",scrollbars=" + scrollable + ",resizable=" + resizeable + ",width=" + dwidth + ",height=" + dheight + ",left=" + nleft + ",top=" + ntop + ",menubar=" + showmenu + ",location=" + showaddresbar + ",fullscreen=" + fullscreen;
	}
	else
	{
		if (fullscreen=="1")
		{
			sfeatures="toolbar=" + ((showtoolbars=='1')?"yes":"no") + ",scrollbars=" + ((scrollable=='1')?"yes":"no") + ",resizable=" + resizeable + ((fullscreen=='1')?",fullscreen":"") + ",menubar=" + showmenu + ",location=" + ((showaddresbar=='1')?"yes":"no");
		}
		else
		{
			sfeatures="toolbar=" + ((showtoolbars=='1')?"yes":"no") + ",scrollbars=" + ((scrollable=='1')?"yes":"no") + ",resizable=" + resizeable + ",menubar=" + showmenu + ",location=" + ((showaddresbar=='1')?"yes":"no") + ",width=" + dwidth + ",height=" + dheight + ",left=" + nleft + ",top=" + ntop;
		}
	}
	window.open(surl,wname,sfeatures);
}

function OpenFullscreenWindow(surl,wname,resizeable,scrollable,showtoolbars,showmenu,showaddresbar,showstatus)
{
	if (isIE==true)
	{
		nleft=0;
		ntop=0;
		dwidth=availwidth-10;
		dheight=availheight-150;
		sfeatures="left=0;top=0;toolbar=" + showtoolbars + ",scrollbars=" + scrollable + ",resizable=" + resizeable + ",width=" + dwidth + ",height=" + dheight + ",left=" + nleft + ",top=" + ntop + ",menubar=" + showmenu + ",location=" + showaddresbar + ((showstatus=='1')?",status=yes":"");
	}
	else
	{
		sfeatures="left=0;top=0toolbar=" + ((showtoolbars=='1')?"yes":"no") + ",scrollbars=" + ((scrollable=='1')?"yes":"no") + ",resizable=" + resizeable + ",fullscreen,menubar=" + showmenu + ",location=" + ((showaddresbar=='1')?"yes":"no")  + ((showstatus=='1')?",status=yes":"");
	}
	window.open(surl,wname,sfeatures);
}

function validatesize(frm,sthis,nsize,sdesc)
{
	var sVal=new String(eval("document." + frm + "." + sthis + ".value"));
	if (sVal.length>nsize)
	{
		alert(sdesc + " length cannot exceed " + nsize + " characters.")
		eval("document." + frm + "." + sthis + ".focus()");
		return false;
	}
}

function validatesizeonkeypress(frm,sthis,nsize,sdesc,e) {
	if (e.ctrlKey==true)
	{
		return false;
	}

	if (isIE==false)
	{
		if (e.which<=0 || e.which==8)
		{
			return false;
		}
	}

	var sVal = new String(eval("document." + frm + "." + sthis + ".value"));
	if ((sVal.length+1)>nsize)
	{
		alert(sdesc + " length cannot exceed " + nsize + " characters.")
		if (isIE==true)
		{
			e.keyCode=0;
		}
		else
		{
			e.stopPropagation(); 
			e.preventDefault();					
		}
		return false;
	}
}

function CountChars(frm,svalue,sDest)
{
	var ilen=svalue.length;
	eval("document." + frm + "." + sDest + ".value=" + ilen.toString());
}

function round (n) {
	n = Math.round (n * 100) / 100;
	n = (n + 0.001) + '';
	return n.substring(0, n.indexOf('.') + 3);
}

function isDate(dateStr,fieldName) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) 
	{
		alert("Please enter " + fieldName + " date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
	}

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) 
	{ 
		// check month range
		alert("Month" + ((fieldName.length>0)?" of " + fieldName + " date ":" ") + "must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) 
	{
		alert("Day" + ((fieldName.length>0)?" of " + fieldName + " date ":" ") + "must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+ ((fieldName.length>0)?" of " + fieldName + " date ":"") + " doesn't have 31 days!")
		return false;
	}

	if (month == 2) 
	{ 
		// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) 
		{
			alert("February " + year + ((fieldName.length>0)?" of " + fieldName + " date ":"") + " doesn't have " + day + " days!");
			return false;
		}
	}
	return true; // date is valid
}

function IsScriptFound(sval)
{
	if (sval==null || sval=='undefined')
	{
		return false;
	}
	var bSF=false;
	if (sval.indexOf("&amp;lt;",0)>=0 || sval.indexOf("&amp;gt;",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("&lt;",0)>=0 || sval.indexOf("&gt;",0)>=0)
	{
		bSF=true;
	}				
	else if (sval.indexOf("<script",0)>=0 || sval.indexOf("<SCRIPT",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("&lt;script",0)>=0 || sval.indexOf("&lt;SCRIPT",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("&amp;lt;script",0)>=0 || sval.indexOf("&amp;lt;SCRIPT",0)>=0)
	{
		bSF=true;
	}				
	else if (sval.indexOf("/script",0)>=0 || sval.indexOf("/SCRIPT",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("script>",0)>=0 || sval.indexOf("SCRIPT>",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("script&gt;",0)>=0 || sval.indexOf("SCRIPT&gt;",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("script&amp;gt;",0)>=0 || sval.indexOf("SCRIPT&amp;gt;",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("<" + "%",0)>=0 || sval.indexOf("%" + ">",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("&lt;%",0)>=0 || sval.indexOf("%&gt;",0)>=0)
	{
		bSF=true;
	}
	else if (sval.indexOf("&amp;lt;%",0)>=0 || sval.indexOf("%&amp;gt;",0)>=0)
	{
		bSF=true;
	}
	return bSF;			
}

function enforcekeyinteger(e)
{
	if (e.keyCode)
	{
		if (!(e.keyCode==45 || (e.keyCode>=48 && e.keyCode<=57)))
		{
			e.keyCode=0
		}
	}
	else if (e.which)
	{
		if (!(e.which==45 || (e.which>=48 && e.which<=57)))
		{
			e.stopPropagation(); 
			e.preventDefault();
		}
	}
}

function enforcekeynumeric(e)
{
	if (e.keyCode)
	{
		if (!((e.keyCode==46) || (e.keyCode>=48 && e.keyCode<=57)))
		{
			e.keyCode=0
		}
	}
	else if (e.which)
	{
		if (!((e.which==46) || (e.which>=48 && e.which<=57)))
		{
			e.stopPropagation();
			e.preventDefault();
		}
	}
}

function enforcekeydate(e)
{
	if (e.keyCode)
	{
		if (!(e.keyCode==47 || (e.keyCode>=48 && e.keyCode<=57)))
		{
			e.keyCode=0
		}
	}
	else if (e.which)
	{
		if (!(e.which==47 || (e.which>=48 && e.which<=57)))
		{
			e.stopPropagation();
			e.preventDefault();
		}
	}
}

function GetDivElementForBrowser(divname)
{
	var divObject=new Object();
	
	if (document.layers)
	{
		divObject=eval("document." + divname);
	}
	else if (isIE==true)
	{
		divObject=eval("document.all." + divname);
	}
	else if (document.getElementById)
	{
		divObject=eval("document.getElementById('" + divname + "')");
	}
	return divObject
}


function IsValidEmail(emailstring)
{
	var Epattern = /(@.*@)|(\.\.)|(@\.)|(^\.)/
	var Epattern1 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/
	
	Epattern.IgnoreCase = true
	Epattern1.IgnoreCase = true
	
	var bResult = Epattern.exec(emailstring)
	var bResult1 = Epattern1.exec(emailstring)

	if ((bResult==null) && (bResult1!=null))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function URLEncode(texttoencode)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = texttoencode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function OpenHtmlDesigner()
{
	var nwidth=(availwidth*90)/100
	var nheight=(availheight*90)/100
	objWin=OpenWindowEx("HtmlDesigner.aspx","htmldesigner",nwidth,nheight,1,1,0,0,0,0);
}

function OpenHtmlEditor()
{
	var nwidth=(availwidth*90)/100
	var nheight=(availheight*90)/100
	objWin=OpenWindowEx("HtmlEditor.aspx","htmldesigner",nwidth,nheight,1,1,0,0,0,0);
}

function OpenItemsList(FormName,CtrlName,rtnfld,callMethod,title)
{
	var lwidth=(availwidth*((availwidth<1000)?99:95) )/100;
	var lheight=(availheight*85)/100
	var objVal=OpenModalWindow("ItemSearch","ItemSearch.aspx?FormName=" + FormName + "&CtrlName=" + CtrlName + "&rtnfld=" + rtnfld + "&callMethod=" + callMethod + "&title=" + title,lwidth,lheight,lwidth,lheight,1,0,0);
	return objVal;
}
function OpenItemsListWithFilter(FormName,CtrlName,rtnfld,callMethod,title,FilterType)
{
	
	var lwidth=(availwidth*((availwidth<1000)?99:95) )/100;
	var lheight=(availheight*85)/100
	var objVal=OpenModalWindow("ItemSearch","ItemSearch.aspx?FormName=" + FormName + "&CtrlName=" + CtrlName + "&rtnfld=" + rtnfld + "&callMethod=" + callMethod + "&title=" + title + "&FilterType=" + FilterType,lwidth,lheight,lwidth,lheight,1,0,0);
	return objVal;
}

function OpenDependencyItemsList(title,FilterType,DependencyID,IgnoreSelect)
{
	var lwidth=(availwidth*((availwidth<1000)?99:95) )/100;
	var lheight=(availheight*85)/100
	var objVal=OpenModalWindow("ShowDependency","ItemSearch.aspx?title=" + title + "&FilterType=" + FilterType + "&DependencyID=" + DependencyID + "&IgnoreSelect=" + IgnoreSelect + "&HideDepartmentsFilter=true",lwidth,lheight,lwidth,lheight,1,0,0);
	return objVal;
}

function OpenDependencyItemsListWithSelect(FormName,CtrlName,rtnfld,callMethod,title,FilterType,DependencyID)
{
	var lwidth=(availwidth*((availwidth<1000)?99:95) )/100;
	var lheight=(availheight*85)/100
	var objVal=OpenModalWindow("ShowDependency","ItemSearch.aspx?FormName=" + FormName + "&CtrlName=" + CtrlName + "&rtnfld=" + rtnfld + "&callMethod=" + callMethod + "&title=" + title + "&FilterType=" + FilterType + "&DependencyID=" + DependencyID + "&HideDepartmentsFilter=true",lwidth,lheight,lwidth,lheight,1,0,0);
	return objVal;
}

function OpenCustomTagsList()
{
	var lwidth=(availwidth*80)/100
	var lheight=(availheight*85)/100
	OpenWindowEx('CustomTagsList.htm?','CustomTagsList',lwidth,lheight,1,1,0,0,0,0);
}

function ConvertToInteger(StringToConvert)
{
	var intReturnValue=0;
	try
	{
		intReturnValue=parseInt(StringToConvert);
		intReturnValue=((isNaN(intReturnValue))?0:intReturnValue);
		return intReturnValue;
	}
	catch(GenEx)
	{
		return intReturnValue;
	}
}

function ConvertToDecimal(StringToConvert)
{
	var decReturnValue=0;
	try
	{
		decReturnValue=parseFloat(StringToConvert);
		decReturnValue=((isNaN(decReturnValue))?0:decReturnValue);
		return decReturnValue;
	}
	catch(GenEx)
	{
		return decReturnValue;
	}
}

// This Function will remove leading spaces from a given text
function deleteLeadingSpaces(theStr)
{
var cntr=0

    theStr += ''

	var leadingSpacesComplete=false
	var z = ''
	for (cntr=0;cntr<theStr.length;cntr++)
	{
	if (theStr.substring(cntr,cntr+1) != ' ')
		leadingSpacesComplete=true

	if (theStr.substring(cntr,cntr+1) != ' ' || leadingSpacesComplete)
		z+=theStr.substring(cntr,cntr+1)	  
	}	
	return z
}

// This Function will remove leading zeros from a given text
function deleteLeadingZeros(theStr)
{
	var leadingZeroesComplete=false
	var z = ''
	for (x=0;x<theStr.length;x++)
	{
	if (theStr.substring(x,x+1) != '0')
		leadingZeroesComplete=true

	if (theStr.substring(x,x+1) != '0' || leadingZeroesComplete)
		z+=theStr.substring(x,x+1)	  
	}	
	return z
}

// This Function will remove leading and trailing spaces from a given text
function trim(strString)
{
	var strLead=deleteLeadingSpaces(strString)
	var strTrail=delTrailingSpaces(strLead)
	return strTrail
}


// This Function will remove trailing zeroes 
function delTrailingZeros(theStr)
{
	var z = ''
	var trailingZeroesComplete=false
	for (var x=theStr.length; x>0;x--)
	{
	if (theStr.substring(x-1,x) != '0')
		trailingZeroesComplete=true

	if (theStr.substring(x-1,x) != '0' || trailingZeroesComplete)
		z = theStr.substring(x-1,x)	+ z  
	}	
	return z
}

// This Function will remove trailing spaces
function delTrailingSpaces(theStr)
{
	var z = ''
	var trailingSpacesComplete=false
	for (var x=theStr.length; x>0;x--)
	{
	if (theStr.substring(x-1,x) != ' ')
		trailingSpacesComplete=true

	if (theStr.substring(x-1,x) != ' ' || trailingSpacesComplete)
		z = theStr.substring(x-1,x)	+ z  
	}	
	return z
}

function PostBackOnEnter(targetControlName,e)
{
	if (isIE==true)
	{
		if (e.keyCode==13)
		{
			__doPostBack(targetControlName,'');
		}
	}
	else
	{
		if (e.which==13)
		{
			__doPostBack(targetControlName,'');
		}					
	}
}

function GetObjectParamTagString(fileurl)
{
    var strString='';
    try
    {
        strString='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="200" HEIGHT="200" id="construct" ALIGN="">';
        strString+='<PARAM NAME=movie VALUE="' + fileurl + '">';
        strString+='<PARAM NAME=quality VALUE=high>';
        strString+='<PARAM NAME=salign VALUE=LT>';
        strString+='<PARAM NAME="wmode" VALUE="opaque">';
        strString+='<PARAM NAME=bgcolor VALUE=#FFFFFF>';
        strString+='<EMBED src="' + fileurl + '" quality=high salign=LT bgcolor=#FFFFFF NAME="construct" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" wmode="opaque"></EMBED></OBJECT>';
    }
    catch(ex)
    {
        //Do nothing
    }
    finally
    {    
    }

    return strString;
}

function GoToLoginPage()
{
    window.location.href="GoToLogin.aspx";
}

function showMessageOnValidator(validatorName, messageText, messageClass, alertMode) 
{
    if (alertMode != 3) {
        var cvCtl = document.getElementById(validatorName);
        if (cvCtl != null) {
            cvCtl.style.visibility = "visible";
            cvCtl.style.display = "inline";
            cvCtl.innerHTML = messageText;
            if (messageClass.length > 1) {
                cvCtl.className = messageClass;
            }
        }
        cvCtl = null;
    }
    if (alertMode != 1) {
        alert(messageText);
    }
}

function htmlDecode(htmlText) 
{
    return unescape(htmlText);
}

function copytoClipboard(inElement) 
{
    if (inElement.createTextRange && isOpera==false) {
        var range = inElement.createTextRange();
        if (range)
            range.execCommand('Copy');
            
    } else {
        var flashcopier = 'flashcopier';
        if (!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="AppImages/_clipboard.swf" FlashVars="clipboard=' + encodeURIComponent(inElement.value) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
}

function pageEscape(e) {
    if (DataValidated == false) {
        if ((e.keyCode && e.keyCode == 27) || (e.which && e.which == 27)) {
            CloseWindow(1);
        }
    }
}

function resetTAWidth(taCtrl,subTractFactor) {
    if (taCtrl != null) {
        var ctrlWidth = availwidth - subTractFactor;
        if (isNaN(ctrlWidth) == false && ctrlWidth > 500) {
            taCtrl.style.width = ctrlWidth.toString() + "px";
        }
    }
}

function ResetPageWidth() 
{
    if (availwidth > 1000) 
    {
        var objliRight = document.getElementById("liRight");
        if (objliRight != null) 
        {
            objliRight.style.width = ((isIE == true) ? "830px" : "890px");
        }
    }
}

function IsValidURL(urlString) 
{
    var strMatch = /(ftp|http|https):\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i
    if (strMatch.test(urlString)) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}

function ParseDate(strDate) {
    var dtReturnValue = new Date(strDate);
    return dtReturnValue;
}