function doShowHideItemDetails(fdsName, tdElt, strParam)
{
	fdsElt = document.all(fdsName);
	if (fdsElt.style.display == "none")
	{
		fdsElt.style.display = "";
		doSubmitStat(strParam);
	} 
	else
	{
		fdsElt.style.display = "none";
	}

	doShowHideFieldsetDetails(tdElt.parentElement);	
}
//********************************************************************************//
function doSubmitStat(strParam)
{
		window.open("./ProductProjectSaveStat.aspx?"+strParam,
			"ifrmSaveStatURL", "", true);
}
//********************************************************************************//
function doShowHideFieldsetDetails(trElt)
{
	doShowPlusMinus(trElt.children(0).children(0));
	
	trElt.isOpen = (trElt.isOpen == "true")?"false":"true";
	trElt.className = (trElt.isOpen == "true")?"ROWExpandedDataList":"ROWCollapsedDataList";
}
//********************************************************************************//
function doHideDetails(expandedElts)
{
	var rows = expandedElts.getElementsByTagName("tr");
	for (var i = 0; i < rows.length; i ++)
	{
		if (rows[i].isOpen != null && rows[i].isOpen == "true")
		{
			doShowHideControls(rows[i]);
		}
	}
}
//********************************************************************************//
function doShowDetails(expandedElts)
{
	var rows = expandedElts.getElementsByTagName("tr");
	for (var i = 0; i < rows.length; i ++)
	{
		if (rows[i].isOpen != null && rows[i].isOpen == "false")
		{			
			doShowHideControls(rows[i]);
		}
	}
}
//********************************************************************************//
function doShowHideControls(trEltName)
{
	var trElt = (typeof(trEltName) == "string")?document.all(trEltName):trEltName;
	doShowPlusMinus(trElt.children(0).children(0));
	
	trElt.isOpen = (trElt.isOpen == "true")?"false":"true";
	
	if (trElt.className == "ROWReadOnlyData")
	{
		return;
	}
		
	trElt.className = (trElt.isOpen == "true")?"ROWExpandedDataList":"ROWCollapsedDataList";
	doShowHideListBox(trElt.children(2).children(0));
}
//********************************************************************************//
function doShowPlusMinus(img)
{
	if(img.isPlus == "true")
	{
		img.isPlus = "false";
		img.src = "./Image/btn_minus_section.gif";
	}
	else
	{
		img.isPlus = "true";
		img.src = "./Image/btn_plus_section.gif";
	}	
}
//********************************************************************************//
function doShowHideListBox(tblID)
{
	tblID.style.display = (tblID.style.display == "")?"none":"";
}	
//********************************************************************************//
var m_isShowMsg = false;
function showMsg(val)
{
	m_isShowMsg = val;			
}
function isShowConfirm()
{
	return m_isShowMsg;
}
//********************************************************************************//
function isDataChanged(doc)
{
	var inputElts = doc.getElementsByTagName("input");
	for (var i = 0; i < inputElts.length; i ++)
	{
		if(inputElts[i].type == "text" || inputElts[i].type == "file")
		{
			if(inputElts[i].defaultValue != inputElts[i].value)
				return true;
		}	
		
//		if(inputElts[i].type == "checkbox")
//		{
//			if(inputElts[i].defaultValue != inputElts[i].checked)
//				return true;
//		}	
	}
	var selectElts = doc.getElementsByTagName("select");	
	for (var i = 0; i < selectElts.length; i ++)
	{
		if(selectElts[i].defaultValue != selectElts[i].value)
			return true;
	}
		
	var textareaElts = doc.getElementsByTagName("textarea");
	for (var i = 0; i < textareaElts.length; i ++)
	{
		if(textareaElts[i].defaultValue != textareaElts[i].value)
			return true;
	}

	return false;	
}
//********************************************************************************//
// 1 - type=1 - onload
		// 2 - type=2 - onsave
function calcCheckSum(Type)
{
PageSum = 0;
FieldStr=""
for(i=0;i<document.forms[0].length;i++)
{	
	FieldStr = document.forms[0].elements[i].value;
	if (FieldStr != "")
	{
		fieldLength =FieldStr.length;
		PageSum += fieldLength
	}
}
	if(type=1)
	{
		LoadedPageSum = PageSum;
	}
	if(type=2)
	{
		SavedPageSum = PageSum
	}

}
//********************************************************************************//		
function checkSum()
{
	if(LoadedPageSum != SavedPageSum)
	{
			return false;
	}
	else
	{
			return true;
	}	 
}
//********************************************************************************//
function setDefaultValue()
{
	var inputElts = document.getElementsByTagName("input");
	for (var i = 0; i < inputElts.length; i ++)
	{
		if(inputElts[i].type == "checkbox")
			inputElts[i].defaultValue = new Boolean(inputElts[i].checked);
	}
	
	var selectElts = document.getElementsByTagName("select");
	for (var i = 0; i < selectElts.length; i ++)
	{	
		if(selectElts[i].defaultValue == null)
			selectElts[i].defaultValue = selectElts[i].value;
	}
	
	var textareaElts = document.getElementsByTagName("textarea");
	for (var i = 0; i < textareaElts.length; i ++)
	{	
		if(textareaElts[i].defaultValue == null)
			textareaElts[i].defaultValue = textareaElts[i].value;
	}	
}
//********************************************************************************//
function doLogoutWindow(loginURL, appURL)
{
	if (window.opener != void(0) && window.opener != null
		&& window.opener.doLogoutWindow != void(0))
	{
		window.opener.doLogoutWindow(loginURL, appURL);
		window.close();
		return;
	}
	if (window.parent != void(0) && window.parent != null
		&& window.parent != window && window.parent.doLogoutWindow != void(0))
	{
		window.parent.doLogoutWindow(loginURL, appURL);
		return;
	}
	if (document.location.href.indexOf(loginURL) == -1  && document.location.href != appURL)
	{
		document.location.href = loginURL;
	}
}
//********************************************************************************//
function doShowWindow(url, windowName, width, height, btnCaller, options)
{
	var defaultOptions = "scrollbars=no, location=no, menubar=no, status=no, resizable=no, toolbar=no";
	var windowOptions = "";
	var left;
	var top;
	if (btnCaller != void(0) && btnCaller != null)
	{
		left = getLeftWin(width, btnCaller, true);
		//!!! check vertical auto adjust 
		top = getTopWin(height, btnCaller, true, false);
	}
	// set up window options
	if (btnCaller != void(0) && btnCaller != null)
	{
		windowOptions = defaultOptions;
	}
	if (options != void(0) && options != null)
	{
		switch (options)
		{
			case 1:
				windowOptions = defaultOptions;
				left = (screen.availWidth - width)/2;
				top = (screen.availHeight - height)/2;
				break;
			default:
				windowOptions = options;
				break;
		}
	}
	// set window initial height and width
	if (height != null && width != null)
	{
		windowOptions += ", height=" + height + ", width=" + width;
	}
	// set window initial position
	if (left != null && top != null)
	{
		windowOptions += ",left=" + left + ",top=" + top;
	}
	if (windowName == void(0) || windowName == null)
	{
		windowName = "_blank";
	}
	var win = window.open(url, windowName, windowOptions);
	// for properly window reuse
	if (width != void(0) && width != null &&  height != void(0) && height != null)
	{
		win.resizeTo(width, height);
	}
	if (left != null && top != null)
	{
		win.moveTo(left, top);
	}
	win.focus();
	return win;
}
//********************************************************************************//
function doCloseWindow(win)
{
	if (win != void(0) && win != null && !win.closed)
		win.close();
}
//********************************************************************************//
function doExternalSelect(id,name)
{
	window._varCurrentFrame.hdnElt.value = id ;
	window._varCurrentFrame.edtElt.value = name ;
}
//********************************************************************************//
function doExternalClose()
{
	window._varCurrentFrame.style.display = "none" ;
	window._varCurrentFrame = null;
}
//********************************************************************************//
var varMarkedColor="selectedrow";
var varUnMarkedColor="valuerow";
var varOldTrElt=null;

function doMarkTR(trElt)
{
	if(varOldTrElt!=trElt)
	{ // mark
		if(varOldTrElt!=null)
			varOldTrElt.className=varUnMarkedColor; //unmark old
		else
			varUnMarkedColor=trElt.className;
		trElt.className=varMarkedColor;
		varOldTrElt=trElt;
	}
}
function doUnMarkTR()
{
	if(varOldTrElt!=null)
	{
		varOldTrElt.className=varUnMarkedColor; //unmark old
		varOldTrElt=null;
	}
}

function checkSelectedTR(errMsg)
{
	if(varOldTrElt==null)
	{
		alert(errMsg);
		return false;
	}
	return true;
}

function getSelectedTR()
{
	return varOldTrElt;
}
//********************************************************************************//
function showError(errorOnPage,errorMessage)
{
	var strErrorOnPage = new String(errorOnPage);			
	if (strErrorOnPage.toLowerCase() == "true")
	{
		alert(errorMessage);
		return true;
	}
/*	if (document.body.onkeydown != null && document.body.onkeydown != void(0))
		varPrevKeyDownHandler = document.body.onkeydown;
	document.body.onkeydown = onKeyDownBody;*/
	return false;
}
//********************************************************************************//
function getLeftWin(width, btnElt, bOppositeDir)
{
	var bDir = document.body.dir != "rtl";
	if(bOppositeDir)
		bDir  = !bDir;
		
	if(!isIFrame)
	{
		var left1 = parent.window.screenLeft - getStylePx(width) + getOffsetLeft(btnElt) + getStylePx(btnElt.offsetWidth) + 4;
		var left2 = parent.window.screenLeft + getOffsetLeft(btnElt) + 2;
	}
	else
	{
		var left1 = parent.window.screenLeft - getStylePx(width) + 4;
		var left2 = parent.window.screenLeft + 2;
		
	}
	
	if(left1 < 0)
		left1 = left2;	
	if(left2 + getStylePx(width) > screen.availWidth)
		left2 = left1;
	
	if(bDir)
		return left1;
	else
		return left2;

}
//********************************************************************************//
function getTopWin(height, btnElt, bOppositeDir, bShowBelow)
{
	var bDir = document.body.dir == "rtl";
	if (bOppositeDir)
		bDir = !bDir;
	
	if(!isIFrame)
	{
		var top1 = parent.window.screenTop + getOffsetTop(btnElt) + getStylePx(btnElt.offsetHeight) + 2;
		var top2 = parent.window.screenTop + getOffsetTop(btnElt) - getStylePx(height) + 3;
	}
	else
	{
		var top1 = parent.window.screenTop + 2;
		var top2 = parent.window.screenTop - getStylePx(height) + 3;
		
	}
	
	if(top1 + getStylePx(height) > screen.availHeight )
		top1 = top2;
	if(top2 < 0)
		top2 = top1;
	
	if(bShowBelow)
	    return top1;
    else
        return top2;

}
//********************************************************************************//
function getOffsetLeft (el) 
{
	var ol = el.offsetLeft - el.scrollLeft;
	while ((el = el.offsetParent) != null)
		ol += el.offsetLeft - el.scrollLeft;
	return ol;
}
//********************************************************************************//
function getOffsetTop (el) 
{
	var ot = el.offsetTop - el.scrollTop;
	while((el = el.offsetParent) != null)
		ot += el.offsetTop - el.scrollTop;
	return ot;
}
//********************************************************************************//
function getStylePx(pxStr)
{
	var s = new String(pxStr);
	var i = s.indexOf("px");
	try
	{
		if( i == -1 )
			return parseInt(s) ;
		return parseInt(s.substr(0,s.length-2));
	}
	catch(e)
	{
		return 0 ;
	}
}
//********************************************************************************//
function doCheckPaste(elt,maxTextAreaLength)
{
	event.returnValue=false;
	var sel = document.selection;
		if (sel!=null)
		{
			var rng = sel.createRange();
			if (rng!=null)
			{
				rng.text=window.clipboardData.getData("Text");
				elt.value=elt.value.substring(0,maxTextAreaLength);
			}
		}
}
//********************************************************************************//
function doCheckLength(elt,maxTextAreaLength)
{
	if(elt.value.length>=maxTextAreaLength && event.keyCode!=8 && event.keyCode!=9
		&& event.keyCode!=35 && event.keyCode!=36 && event.keyCode!=46
			&& event.keyCode!=16 && event.keyCode!=45
			&& (event.keyCode<35 || event.keyCode>40))
		{
			return false;
		}
	return true;
}
//********************************************************************************//
// used to add to URL strings to make sure URLs not cached
function getRefreshKey()
{
  	var dt = new Date();
  	return "&dt=" + dt.valueOf();
}
//********************************************************************************//
function ShowTip(txtTip,x,y)
{
	//BaseY = parent.window.document.getElementById('tdInFocus').offsetTop
	//BaseX = parent.window.document.getElementById('tdInFocus').offsetLeft
	parent.window.document.getElementById('TTip').style.top=y;
	parent.window.document.getElementById('TTip').style.left=x;
	parent.window.document.getElementById('TTip').innerHTML=txtTip;
	parent.window.document.getElementById('TTip').style.visibility = 'visible';
}
//********************************************************************************//		   
function HideTip()
{
	TCode = "parent.window.document.getElementById('TTip').innerHTML='';" + " parent.window.document.getElementById('TTip').style.visibility ='hidden';"
	eval(TCode);
}  	
//********************************************************************************//
function doFocusWindow(windowHandle)
{
	if (windowHandle != void(0) && windowHandle != null)
	{
		try
		{
			windowHandle.focus();
		}
		catch (e) {}
	}
}
//********************************************************************************//
function doSetRequireContact(idName)
{
	//document.all("tdContactEmail").innerText="";
	document.all("tdContactPhone").innerText="";
	document.all("tdContactFax").innerText="";
	document.all(idName).innerText="*";				
}
//********************************************************************************//
function ShowCategoryTree()
{
	window.location.href = "../SearchWindows/SearchCategoryTree.aspx?IsIFrame=false&ShowCategoryTree=true ";
}
function doHideCategoryTree()
{
	window.location.href = "../SearchWindows/SearchCategoryTree.aspx?IsIFrame=false&ShowCategoryTree=false";
}
//********************************************************************************//
function createAsterisk()
{
	eval("document.all('tdLocalName').innerText=\"\"");
	eval("document.all('tdEnglishName').innerText=\"\"");
		
	if(document.all("txtLocalName").value.length>0 
		|| document.all("txtLocalName").value.length==0 && document.all("txtEnglishName").value.length==0)
		eval("document.all('tdLocalName').innerText=\"*\"");
		
	if(document.all("txtLocalName").value.length==0 && document.all("txtEnglishName").value.length>0)
		eval("document.all('tdEnglishName').innerText=\"*\"");
}
//********************************************************************************//
function ShowCategoryTreeAndShowPleaseWait()
{
	document.all("txtLabelPleaseWait").style.display = "";
	ShowCategoryTree();
}
//********************************************************************************//
function CheckTextArea(Elmnt)
{
	var FieldText  = Elmnt.value;
	var FieldLengh = FieldText.length;
	if (FieldLengh > Elmnt.maxLength)
	{
		Elmnt.value = FieldText.substring(0,parseInt(Elmnt.maxLength));
		alert (msgTextAreaOverFlow+Elmnt.maxLength+msgTextAreaOverFlowEnd);
		return false;
	}
	
	
}

