//====================================================================================================
//	Function Name	:	UploadImage_Change()
//----------------------------------------------------------------------------------------------------
function UploadImage_Change(obj, imgTag, defaultVal, defaultWidth)
{
	imgTag.width=120;

	if(obj.value == '')
		imgTag.src = defaultVal;
	else
	{
		imgTag.src = obj.value;
		
		if(defaultWidth != '')
			imgTag.width = defaultWidth;
	}
}

//====================================================================================================
//	Function Name	:	tab_Click
//----------------------------------------------------------------------------------------------------
function tab_Click(tabIndex)
{
	$('#divTab ul li').removeClass();
	$('#divTab ul li a').removeClass();
	$('#divTab ul li a span').removeClass();
	
	if (tabIndex>0)
		$('#li0 a').attr("class","firstlink");

	$('#li'+tabIndex).attr("class","active");
	$('#li'+tabIndex+' a span').attr("class","active");

	$('#li'+(tabIndex+1)+' a').attr("class","activenext");

	$('.hideTableBlock').attr("style","display:none;");
	$('#table'+(tabIndex)).attr("style","display:block;");
}
//====================================================================================================
//	Function Name	:	CheckUncheck_Click()
//----------------------------------------------------------------------------------------------------
function CheckUncheck_Click(fldname, status)
{
	fld = document.getElementsByName(fldname);
	if(fld)
	{
		if(fld.length)
			for(i=0; i < fld.length; i++)
				fld[i].checked = status;
		else
			fld.checked = status;
	}
}
//====================================================================================================
//	Function Name	:	ShowHide()
//----------------------------------------------------------------------------------------------------
function ShowHide(idShow, idHide)
{
	var blockIdShow = document.getElementById(idShow);
	var blockIdHide = document.getElementById(idHide);
	
	blockIdShow.style.visibility	= 'visible';
	blockIdShow.style.display		= 'block';

	blockIdHide.style.visibility 	= 'hidden';
	blockIdHide.style.display 		= 'none';
}
//====================================================================================================
//	Function Name	:	Block_ShowHide()
//----------------------------------------------------------------------------------------------------
function Block_ShowHide(id, idArrow, disp)
{
	var blockId = document.getElementById(id);
	if (idArrow!='')
		var imgId = document.getElementById(idArrow);
	
	if(blockId)
	{
		if(blockId.style.display == 'none')
		{
			if (idArrow!='')
				imgId.src = Templates_Image+"up_arrow.gif";
				
			blockId.style.visibility	= 'visible';

			if (disp!='')
				blockId.style.display		= disp;
			else
				blockId.style.display		= 'block';
		}
		else
		{
			if (idArrow!='')
				imgId.src = Templates_Image+"down_arrow.gif";
				
			blockId.style.visibility 	= 'hidden';
			blockId.style.display 		= 'none';
		}
	}
}
//====================================================================================================
//	Function Name	:	popupWindowURL
//----------------------------------------------------------------------------------------------------
function popupWindowURL(url, winname, w, h, menu, resize, scroll)
{
    var x = (screen.width-w)/2;
    var y = (screen.height-h)/3;

	if (winname == null)
		winname = "newWindow";
	
	if (w == null)
		w = 800;
	
	if (h == null)
		h = 600;
	
	if (resize == null)
		resize = 1;

	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	
	if (menu)
		menutype = "menubar";
	
	if (resize)
		resizetype = "resizable";
	
	if (scroll)
		scrolltype = "scrollbars";
	
    cwin = window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);

	if (!cwin.opener)
		cwin.opener = self;

	cwin.focus();

	return true;
}

function ToggleLoader(flg, msg)
{
	if(flg)
	{
		DisableBodyArea(true);

		var x = (truebody().clientWidth - 200)/2;
		var y = (truebody().clientHeight - 200)/2 + truebody().scrollTop;
		//var y = 475;
//		var y = 475+120;

		document.getElementById('stdLoader').style.left = x+"px";
		document.getElementById('stdLoader').style.top = y+"px";
		document.getElementById('stdLoader').style.display = '';
	}
	else
	{
		document.getElementById('stdLoader').style.display = 'none';
		DisableBodyArea(false)
	}
}
function DisableBodyArea(flg)
{
/*
	if(flg)
	{
		document.getElementById('stdDisableArea').style.width	= truebody().scrollWidth + 'px';
		document.getElementById('stdDisableArea').style.height	= truebody().scrollHeight + 'px';
		document.getElementById('stdDisableArea').style.display = '';
	}
	else
	{
		document.getElementById('stdDisableArea').style.display = 'none';
	}
*/
}

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var previewImageHeight;	// maximum image size.
var previewImageWidth;	// maximum image size.

var defaultImageHeight = 400;	// maximum image size.
var defaultImageWidth = 500;	// maximum image size.

var timer;

var previewImg;

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//====================================================================================================
//	Function Name	:	popupWin
//----------------------------------------------------------------------------------------------------
//var divPopup = 0;

function popupWin(title, content, w, h) {

    var x = (truebody().clientWidth-w)/2;
    var y = (truebody().clientHeight-h)/2;

	if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
		y = 250;
	}

	var divWindow 	= document.createElement('div');

	divWindow.setAttribute('id', 'divPopup');
//	divWindow.innerHTML 		= '<table cellpadding=0 cellspacing=1 width=100% height=' + h + ' border=0 class=popupTable><tr><td width=99% class=popupTitle><div id=divPopupTitle>' + title + '</div></td><td class=popupTitle width=5 style="cursor:pointer;" onClick=JavaScript:document.body.removeChild(document.getElementById("divPopup"));DisableBodyArea(false);>&nbsp;X&nbsp;</td></tr><tr><td colspan=2 valign=top class=popupBody><div id=divPopupContent style="height:'+ (h-10) +'px;overflow:auto;">' + content + '</div></td></tr></table>';


	divStr			= '';
	divStr = divStr + '<div style="position:absolute;">';
		divStr = divStr + '<iframe frameborder="0" width="100%" style="position:absolute;"></iframe>';
		divStr = divStr + '<div style="position:relative; width:'+ w + 'px' +'; " class=popupTable>';
		//divStr = divStr + '<div style="position:relative; width:100%; height:' + h + ';" class=popupTable>';
			divStr = divStr + '<table cellpadding=0 cellspacing=1 width=100% height=' + h + ' border=0>';
				divStr = divStr + '<tr>';
					divStr = divStr + '<td width=99% class=popupTitle>';
						divStr = divStr + '<div id=divPopupTitle>' + title + '</div>';
					divStr = divStr + '</td>';
					divStr = divStr + '<td class=popupTitle width=5 style="cursor:pointer;" onClick=JavaScript:document.body.removeChild(document.getElementById("divPopup"));DisableBodyArea(false);>&nbsp;X&nbsp;</td>';
				divStr = divStr + '</tr>';
				divStr = divStr + '<tr>';
					divStr = divStr + '<td colspan=2 valign=top class=popupBody>';
						divStr = divStr + '<div id=divPopupContent style="height:'+ (h+50) +'px;overflow:auto;">' + content + '</div>';
						//divStr = divStr + '<div id=divPopupContent style="height:'+ (h-10) +'px;overflow:auto;">' + content + '</div>';
					divStr = divStr + '</td>';
				divStr = divStr + '</tr>';
			divStr = divStr + '</table>';
		divStr = divStr + '</div>';
	divStr = divStr + '</div>';

	divWindow.innerHTML	= divStr;

//	divWindow.innerHTML 		= '<div id=divPopupTitle><div class=floatLeft>' + title + '</div><div class=floatRight width=5 style="cursor:pointer;" onClick=JavaScript:document.body.removeChild(document.getElementById("divPopup"));DisableBodyArea(false);>&nbsp;X&nbsp;</div></div><div class=popupBody><div id=divPopupContent style="height:'+ (h-10) +'px;overflow:auto;">' + content + '</div>';
//	divWindow.innerHTML			= '';
//	divWindow.innerHTML 		= divWindow.innerHTML + '<div id=popupTable>';
//	divWindow.innerHTML 		= divWindow.innerHTML + '<div id=divPopupTitle>'+ title + '</div>';
//	divWindow.innerHTML 		= divWindow.innerHTML + '</div>';

//	divWindow.innerHTML 		= '<div class=floatLeft>' <div class=floatRight width=5 style="cursor:pointer;" onClick=JavaScript:document.body.removeChild(document.getElementById("divPopup"));DisableBodyArea(false);>&nbsp;X&nbsp;</div></div><div class=popupBody><div id=divPopupContent style="height:'+ (h-10) +'px;overflow:auto;">' + content + '</div>';

//	divWindow.style.overflow 	= 'auto';
	divWindow.style.display		= 'none';
	divWindow.style.position 	= navigator.appVersion.indexOf("MSIE")!=-1 ? 'absolute' : 'fixed';
	divWindow.style.zIndex		= 1005;
	divWindow.style.left		= x + 'px';
	divWindow.style.top			= (y-50) + 'px';
	divWindow.style.width		= w + 'px';
	divWindow.style.height		= h + 'px';

	document.body.appendChild(divWindow);

	return true;
}

function popupWinShow() {

	DisableBodyArea(true);
	document.getElementById('divPopup').style.display = '';	
}

function popupWinClose() {
	document.body.removeChild(document.getElementById("divPopup"));
	DisableBodyArea(false);
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
