////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function openEditor(returnControl, imageFolder, strUrl)
{
	window.open(strUrl + "?control=" + returnControl + "&folder=" + imageFolder,'AQContextHelp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=680,height=400').focus();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check All function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkAll(coltrolName, target)
{
	var iIndex = 1;
	for (i = 0; i < document.frmForm.elements.length; i++)
	{	
		e = document.frmForm.elements[i];
		if ((e.name == coltrolName) && (e.disabled == false))
		{
			e.checked = target.checked;
			var trRow = document.getElementById("trRow" + iIndex);
			if(target.checked)
			{
				trRow.bgColor = "#CEDAEF";
			}
			else
			{
				trRow.bgColor = "#FFFFFF";
			}
		}
		if ((e.name == coltrolName))
		{
			iIndex++;
		}
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check All function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function buyNow(coltrolName,strUrl)
{
	var iIndex = 1;
	for (i = 0; i < document.frmForm.elements.length; i++)
	{	
		e = document.frmForm.elements[i];
		if ((e.name == coltrolName) && (e.disabled == false))
		{
			strUrl = strUrl + "&pid[]=" + e.value;
		}
	}
	window.location.href=strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getObjectValue(objectName)
{
	var strReturnValue = "";
	if(document.getElementById(objectName) != null)
	{
		strReturnValue = document.getElementById(objectName).value;
	}
	return strReturnValue;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function moveMe(iCurrentID)
{
	document.frmForm.hCurrentID.value = iCurrentID;
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboBox(target, queryKey, queryValue, strUrl)
{
	//
	if(strUrl.indexOf("&" + queryKey + "=") > 0)
	{
		strUrl = strUrl.replace("&" + queryKey + "=" + queryValue, "&" + queryKey + "=" + target.value);
	}
	else
	{
		strUrl = strUrl + "&" + queryKey + "=" + target.value
	}
	window.location.href=strUrl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboAppend(target, queryKey, queryValue, strUrl)
{
	//
	strUrl = strUrl + "&" + queryKey + "=" + target.value
	window.location.href=strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkSelect(target, iIndex)
{
	var trRow = document.getElementById("trRow" + iIndex);
	if(target.checked)
	{
		trRow.bgColor = "#CEDAEF";
	}
	else
	{
		trRow.bgColor = "#FFFFFF";
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboBox(target, queryKey, queryValue, strUrl)
{
	//
	if(strUrl.indexOf("&" + queryKey + "=") > 0)
	{
		strUrl = strUrl.replace("&" + queryKey + "=" + queryValue, "&" + queryKey + "=" + target.value);
	}
	else
	{
		strUrl = strUrl + "&" + queryKey + "=" + target.value
	}
	window.location.href=strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function insertEcomotion(EmoticonsText,InsertControl)
{
	if(EmoticonsText != null)
	{
		var currentTextValue = document.getElementById(InsertControl).value;
		document.getElementById(InsertControl).value = currentTextValue + EmoticonsText;
		closeIFrameDialog();
		
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function URLEncode(str)
{
	var ms = "%25#23 20?3F<3C>3E{7B}7D[5B]5D|7C^5E~7E`60+2B"
	var msi = 0
	var i,c,rs,ts
	while (msi < ms.length)
	{
		c = ms.charAt(msi)
		rs = ms.substring(++msi, msi +2)
		msi += 2
		i = 0
		while (true)
		{
			i = str.indexOf(c, i)
			if (i == -1) break
			ts = str.substring(0, i)
			str = ts + "%" + rs + str.substring(++i, str.length)
		}
	}
	return str
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function confirmDeleteItem(strMessage,strRedirectUrl)
{
	if(confirm(strMessage))
	{
		window.location.href=strRedirectUrl;
		return true;
	}
	else
	{
		return false;	
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function actionMe(action, actionWho)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{
				count++;
			}
		}
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
				return confirm("You are about to " + action + " " + count + " selected " + actionWho + "(s). Do you wish to continue?")
			}
		else
		{
			alert("You must select at least one " + actionWho + " to " + action + "!");
			return false;
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function actionMeControl(controlName,action, actionWho)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == controlName && e.checked == true)
			{
				count++;
			}
		}
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
				return confirm("You are about to " + action + " " + count + " selected " + actionWho + "(s). Do you wish to continue?")
			}
		else
		{
			alert("You must select at least one " + actionWho + " to " + action + "!");
			return false;
		}
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function compareProduct(returnUrl, CategoryID)
	{
		var count = 0;
		var strAlert = "";
		var strUrl = "compare_product.php?";
		
		
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect" && e.checked == true)
			{
				strUrl = strUrl + "pid[]=" + e.value + "&";
				count++;
			}
		}
		
		if(parseInt(CategoryID,10) != 0)
		{
			strUrl = strUrl + "cid=" + CategoryID + "&";
		}
		strUrl = strUrl + "returnUrl=" + returnUrl + "";
		if (count > 1)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
				document.frmForm.action = strUrl;
				//document.frmForm.submit();
				window.location.href=strUrl;
				return true;
			}
		else
		{
			alert("You must select at least 2 product to compare!");
			return false;
		}
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function actionMeEx(action, actionWho, appendMessage)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{
				count++;
			}
		}
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
				return confirm("You are about to " + action + " " + count + " selected " + actionWho + "(s).\n" + appendMessage +".\n Do you wish to continue?")
			}
		else
		{
			alert("You must select at least one " + actionWho + " to " + action + "!");
			return false;
		}
	}	
	/////////////////////////////////////////////////////////////////////////////////////
	//
	/////////////////////////////////////////////////////////////////////////////////////
	function addNew()
	{
		if(document.frmForm.hTable.value == "")
		{
			document.frmForm.hTable.value = document.getElementById("tdTable").innerHTML;
		}
		var strTable = document.getElementById("tdTable").innerHTML;
		strTable = strTable + document.frmForm.hTable.value;
		document.getElementById("tdTable").innerHTML = strTable;
		
	}
	/////////////////////////////////////////////////////////////////////////////////////
	//
	/////////////////////////////////////////////////////////////////////////////////////
	function unDo()
	{
		var strTable = document.getElementById("tdTable").innerHTML;
		var arrTable = strTable.split("<!--BEGIN-->");
		var strNewTable = "";
		if(arrTable.length > 1)
		{
			for(i = 0; i < (arrTable.length -1); i++)
			{
				strNewTable = strNewTable + "<!--BEGIN-->" + arrTable[i];
			}
			document.getElementById("tdTable").innerHTML = strNewTable;
		}
		else
		{
			alert("Can not remove");
		}
	}	


//////////////////////////////////////////////////////////////////////////////////
//Get Offset left of object
//////////////////////////////////////////////////////////////////////////////////
function getOffsetLeft(obj)
{
	var offsetParent = obj.offsetParent;
	var offsetLeft = obj.offsetLeft
	var iMaxParentLevel = 40;
	var i = 0;
	//Try to get container offset
	while((offsetParent != null) && (i < iMaxParentLevel))
	{
		offsetLeft = parseInt(offsetParent.offsetLeft,10) + parseInt(offsetLeft,10);
		offsetParent = offsetParent.offsetParent;
		i++;
	}
	return offsetLeft;
}
//////////////////////////////////////////////////////////////////////////////////
//Get Offset top of object
//////////////////////////////////////////////////////////////////////////////////
function getOffsetTop(obj)
{
	var offsetParent = obj.offsetParent;
	var offsetTop = obj.offsetTop
	var iMaxParentLevel = 40;
	var i = 0;
	//Try to get container offset
	while((offsetParent != null) && (i < iMaxParentLevel))
	{
		offsetTop = parseInt(offsetParent.offsetTop,10) + parseInt(offsetTop,10);
		offsetParent = offsetParent.offsetParent;
		i++;
	}
	return offsetTop;
}