function ShowPicture(urlImage, iWidth, iHeight)
{
	var url = "view_image.aspx?img=" + urlImage;
	var width=iWidth-10;
	var height=iHeight-10;
	var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	if(iHeight<screen.height)
	{
		window.open(url,'ShowPicture','top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+'').focus();
	}
	else
	{
		window.open(url,'ShowPicture','top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+'').focus();
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toggleObject(objectName)
{
	var objObject = document.getElementById(objectName);
	if(objObject.style.display == "")
	{
			objObject.style.display = "none";
	}
	else
	{
			objObject.style.left = (parseInt(getOffsetLeft(document.getElementById("tdMenu"))) + 450)  + "px";
			objObject.style.display = "";
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function postionPlayer(objectName)
{
	var objObject = document.getElementById(objectName);
	var objPlayerObject = document.getElementById("playercontrol");
	if(objObject != null)
	{
		objObject.style.left = (parseInt(getOffsetLeft(document.getElementById("tdMenu"))) + 442)  + "px";
	}
	if(objPlayerObject != null)
	{
		objPlayerObject.style.left = (parseInt(getOffsetLeft(document.getElementById("tdMenu"))) + 442)  + "px";
	}
	//alert(objObject.style.left);
	objObject.style.display = "";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function postionTakeATest()
{
	var objTakeATest = document.getElementById("divTakeATest");
	var objMainTable = document.getElementById("tblMainTable");
	if((objTakeATest != null) && (objMainTable != null))
	{
		//alert(getOffsetLeft(objMainTable));
		objTakeATest.style.left = (parseInt(getOffsetLeft(objMainTable)) + 540)  + "px";
	}
	
	objTakeATest.style.display = "";
}


//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////
function uncheckAll(controlName, target)
{
	for (i = 0; i < document.aspnetForm.elements.length; i++)
	{	
		e = document.aspnetForm.elements[i];
		if (e.name == controlName && e.checked == true)
		{
			e.checked = false;;
		}
		
	}
	target.checked = true;
}
//////////////////////////////////////////////////////////////////////////////////
//Get Offset left of object
//////////////////////////////////////////////////////////////////////////////////
function getOffsetLeft(obj)
{
	var offsetParent = obj.offsetParent;
	var offsetLeft = obj.offsetLeft
	var iMaxParentLevel = 20;
	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 = 20;
	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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FormatNumber(num)
{
	if(!isNaN(num))
	{
		//Round the number
		num = Math.round(num*100)/100;
		return FormatNumberFull(num,2,false,false,true);
	}
	else
	{
		return "";
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function confirmAction(strMessage, strLink)
{
    if(confirm(strMessage))
    {
        window.location.href=strLink;
        return true;
    }
    else
    {
        return false;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function FormatNumberFull(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function printMe(trHideName)
{
    window.open(window.location.href+ "&print=yes");
    /*
    var trHide = document.getElementById(trHideName)
    if(trHide != null)
    {
        trHide.style.display = "none";
    }
    window.print();
    */
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetDayInMonth(year, month)
{
     year = parseInt(year,10);
    month = parseInt(month,10);
     return 32 - new Date(year, month - 1, 32).getDate();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showTable(strArrTable,tableName)
	{
		
		var arrTable = strArrTable.split("|");
		for(i = 0; i < arrTable.length;i++)
		{
			document.getElementById(arrTable[i]).style.display="none";
		}
		document.getElementById(tableName).style.display="";
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changePayTypeView(hideControl,displayControl)
{
	var arrControl = getElementsByTagNames('span');
	for (i = 0; i < arrControl.length; i++)
	{	
		e = arrControl[i];
		if (e.id == hideControl)
		{
			e.style.display="none";
		}
		if (e.id == displayControl)
		{
			e.style.display="";
		}
	}
	/*
	if(document.getElementById(hideControl) != null)
	{
		document.getElementById(hideControl).style.display="none";
	}
	if(document.getElementById(displayControl) != null)
	{
		document.getElementById(displayControl).style.display="";
	}
	*/
}
function getElementsByTagNames(list,obj)
{
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++)
	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++)
		{
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (testNode.sourceIndex)
	{
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition)
	{
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeHiddenID(ID)
{
	document.getElementById("hHiddenID").value = ID;
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function priceRangeCompare(strUrl, MenuID)
{
	var PriceFrom = document.getElementById("txtPriceFrom" + "_" + MenuID + "").value;
	var CurrencyFrom = document.getElementById("cbCurrencyFrom" + "_" + MenuID + "").value;
	var PriceTo = document.getElementById("txtPriceTo" + "_" + MenuID + "").value;
	var CurrencyTo = document.getElementById("cbCurrencyTo" + "_" + MenuID + "").value;
	strUrl = strUrl + "&pricefrom=" + PriceFrom;
	strUrl = strUrl + "&currencyfrom=" + CurrencyFrom;
	strUrl = strUrl + "&priceto=" + PriceTo;
	strUrl = strUrl + "&currencyto=" + CurrencyTo;
	window.location.href=strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function productAttributeFilter(strUrl, MenuID,ListProductAttributeDetailID,AppendUrl)
{
	
	var count = 0;
	var strAlert = "";
	var strQueryListProductAttributeID = "";
	var arrListProductAttributeDetailID = ListProductAttributeDetailID.split("|");
	for (i = 0; i < arrListProductAttributeDetailID.length; i++)
	{	
		if(arrListProductAttributeDetailID[i] != "")
		{
			var e = document.getElementById("ckProductAttribute_" + MenuID + "_" + arrListProductAttributeDetailID[i]);
			if (e.checked == true)
			{
				strQueryListProductAttributeID = strQueryListProductAttributeID + "&padid=" + e.value;
				count++;
			}
		}
	}
	if (count > 0)
	{
	}
	else
	{
		alert("You must select at least one  attribute to filter!");
		return false;
	}
	strUrl = strUrl + strQueryListProductAttributeID;
	strUrl = strUrl + AppendUrl;
	window.location.href=strUrl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function productAttributeFilterEx(strUrl, MenuID,ListProductAttributeDetailID,ListPriceRangeID)
{
	
	var count = 0;
	var strAlert = "";
	var strQueryListProductAttributeID = "";
	var arrListProductAttributeDetailID = ListProductAttributeDetailID.split("|");
	for (i = 0; i < arrListProductAttributeDetailID.length; i++)
	{	
		if(arrListProductAttributeDetailID[i] != "")
		{
			var e = document.getElementById("ckProductAttribute_" + MenuID + "_" + arrListProductAttributeDetailID[i]);
			if (e.checked == true)
			{
				strQueryListProductAttributeID = strQueryListProductAttributeID + "&padid=" + e.value;
				count++;
			}
		}
	}
	
	strUrl = strUrl + strQueryListProductAttributeID;
	//Append for price range
	
	var arrListPriceRangeID = ListPriceRangeID.split("|");
	//alert(strUrl);
	for (i = 0; i < arrListPriceRangeID.length; i++)
	{	
		if(arrListPriceRangeID[i] != "")
		{
			var e = document.getElementById("ckPriceRange_" + MenuID + "_" + arrListPriceRangeID[i]);
			if (e.checked == true)
			{
				strUrl = strUrl + e.value;
				count++;
			}
		}
	}
	
	if (count > 0)
	{
	}
	else
	{
		alert("You must select at least one condition to filter!");
		return false;
	}
	window.location.href=strUrl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function priceRangeFilter(strUrl, MenuID,ListPriceRangeID,AppendUrl)
{
	
	var count = 0;
	var strAlert = "";
	var strQueryListPriceRangeID = "";
	var arrListPriceRangeID = ListPriceRangeID.split("|");
	//alert(strUrl);
	for (i = 0; i < arrListPriceRangeID.length; i++)
	{	
		if(arrListPriceRangeID[i] != "")
		{
			var e = document.getElementById("ckPriceRange_" + MenuID + "_" + arrListPriceRangeID[i]);
			if (e.checked == true)
			{
				strUrl = strUrl + e.value;
				count++;
			}
		}
	}
	if (count > 0)
	{
	}
	else
	{
		alert("You must select at least one  to filter!");
		return false;
	}
	strUrl = strUrl + AppendUrl;
	//alert(strUrl);
	window.location.href=strUrl;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboBoxUrl(target)
{
	var strUrl = target.value
	window.location.href=strUrl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function changeComboBox(target, queryKey, queryValue, strUrl)
{
    var strType = "&";
    if(strUrl.indexOf("?") <= 0)
    {
        strType = "?";
    }
	if((strUrl.indexOf("?" + queryKey + "=") > 0) || (strUrl.indexOf("&" + queryKey + "=") > 0))
	{
		strUrl = strUrl.replace("?" + queryKey + "=" + queryValue, "?" + queryKey + "=" + target.value);
		strUrl = strUrl.replace("&" + queryKey + "=" + queryValue, "&" + queryKey + "=" + target.value);
	}
	else
	{
		strUrl = strUrl + strType + queryKey + "=" + target.value
	}
	window.location.href=strUrl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboAppend(target, queryKey, queryValue, strUrl)
{
	//
	strUrl = strUrl + "&" + queryKey + "=" + target.value
	window.location.href=strUrl;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function voteMe(ControlName, Type, SourceID, strReturnUrl)
{
	var VoteValue = document.getElementById(ControlName).value;
	var strUrl = GetWebsiteUrl() + "default.aspx?module=misc&content=vote&value=" + VoteValue + "&type=" + Type + "&sid=" + SourceID + "&returnUrl=" + strReturnUrl + "";
	window.location.href=strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doSimpleSearch(SimpleSearchComboID, SimpleSearchTextID)
{
	//
	//queryKey queryValue, 
	var SearchType = document.getElementById(SimpleSearchComboID).value.toLowerCase();
	var Keyword = document.getElementById(SimpleSearchTextID).value.toLowerCase();
	var strUrl = "";
	switch(SearchType)
	{
		case "album":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=show_album&action=searchresult&keyword=" + Keyword + "";
			break;
		case "music":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=mu&action=searchresult&keyword=" + Keyword + "";
			break;
		case "movie":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=mo&action=searchresult&keyword=" + Keyword + "";
			break;
		case "file":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=fi&action=searchresult&keyword=" + Keyword + "";
			break;
		case "diary":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=show_diary&action=searchresult&keyword=" + Keyword + "";
			break;
		case "product":
			strUrl = GetWebsiteUrl() + "default.aspx?module=product&content=list_product&action=searchresult&keyword=" + Keyword;
			break;
		case "news":
			strUrl = GetWebsiteUrl() + "default.aspx?module=news&content=list_news&action=searchresult&keyword=" + Keyword;
			break;
		case "product_news":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=search_result&action=searchresult&searchtype=product_news&keyword=" + Keyword + "";
			break;
		default:
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=search_result&action=searchresult&keyword=" + Keyword + "";
			break;
	}
	window.location.href=strUrl;
	return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doProductSearch(SimpleSearchTextID,ProvinceComboID,DistrictComboID)
{
	//
	//queryKey queryValue, 
	var Keyword = document.getElementById(SimpleSearchTextID).value.toLowerCase();
	var Province = document.getElementById(ProvinceComboID).value.toLowerCase();
	var District = document.getElementById(DistrictComboID).value.toLowerCase();
	var strUrl = "";
	strUrl = GetWebsiteUrl() + "default.aspx?module=product&content=list_product&action=searchresult&province=" + Province + "&district=" + District + "&keyword=" + Keyword;

	window.location.href=strUrl;
	return false;
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
function doSearchProduct()
{
	
		var UserControlPrefix = document.getElementById("hUserControlPrefix").value
		var PriceFrom = document.getElementById(UserControlPrefix + "_" + "PriceFrom").value.toLowerCase();
		var PriceTo = document.getElementById(UserControlPrefix + "_" + "PriceTo").value.toLowerCase();
		var cbCurrencyFrom = document.getElementById(UserControlPrefix + "_" + "cbCurrencyFrom").value.toLowerCase();
		var cbCurrencyTo = document.getElementById(UserControlPrefix + "_" + "cbCurrencyTo").value.toLowerCase();
		var CategoryID = document.getElementById("cbCategory").value.toLowerCase();
		var cbCurrencyTo = document.getElementById("cbCategory").value.toLowerCase();
					
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doAdvanceSearch(SimpleSearchComboID, AdvanceSearchKeyword,AdvanceSearchDateFrom,AdvanceSearchDateTo,AdvanceSearchViewCountFrom,AdvanceSearchViewCountTo)
{
	//
	//queryKey queryValue, 
	var UserControlPrefix = document.getElementById("hUserControlPrefix").value
	var SearchType = document.getElementById(UserControlPrefix + "_" + SimpleSearchComboID).value.toLowerCase();
	var AdvanceSearchKeyword = document.getElementById(AdvanceSearchKeyword).value.toLowerCase();
	var AdvanceSearchDateFrom = document.getElementById(AdvanceSearchDateFrom).value.toLowerCase();
	var AdvanceSearchDateTo = document.getElementById(AdvanceSearchDateTo).value.toLowerCase();
	var AdvanceSearchViewCountFrom = document.getElementById(AdvanceSearchViewCountFrom).value.toLowerCase();
	var AdvanceSearchViewCountTo = document.getElementById(AdvanceSearchViewCountTo).value.toLowerCase();
	var Param = "&keyword=" + AdvanceSearchKeyword + "&datefrom=" + AdvanceSearchDateFrom + "&dateto=" + AdvanceSearchDateTo + "&viewcountfrom=" + AdvanceSearchViewCountFrom + "&viewcountto=" + AdvanceSearchViewCountTo;
	var strUrl = "";
	
	switch(SearchType)
	{
		case "album":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=show_album&action=searchresult" + Param;
			break;
		case "music":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=mu&action=searchresult" + Param;
			break;
		case "movie":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=mo&action=searchresult" + Param;
			break;
		case "file":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=list_media&filetype=fi&action=searchresult" + Param;
			break;
		case "diary":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=show_diary&action=searchresult&keyword=" + Param;
			break;
		case "product":
			strUrl = GetWebsiteUrl() + "default.aspx?module=product&content=list_product&action=searchresult&keyword=" + Param;
			break;
		case "news":
			strUrl = GetWebsiteUrl() + "default.aspx?module=news&content=list_news&action=searchresult&keyword=" + Param;
			break;
		case "product_news":
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=search_result&action=searchresult&searchtype=product_news&keyword=" + Keyword + "";
			break;
		default:
			strUrl = GetWebsiteUrl() + "default.aspx?module=blogger&content=search_result&action=searchresult&keyword=" + Keyword + "";
			break;
	}
	
	window.location.href=strUrl;
	return false;
}

/////////////////////////////////////////////////////////////////////////////////////
			//
			/////////////////////////////////////////////////////////////////////////////////////
			function addMore()
			{
				if(document.aspnetForm.hTable.value == "")
				{
					document.aspnetForm.hTable.value = document.getElementById("tdTable").innerHTML;
				}
				var strTable = document.getElementById("tdTable").innerHTML;
				strTable = strTable + document.aspnetForm.hTable.value;
				document.getElementById("tdTable").innerHTML = strTable;
				
			}
			/////////////////////////////////////////////////////////////////////////////////////
			//
			/////////////////////////////////////////////////////////////////////////////////////
			function remove()
			{
				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");
				}
			}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function enableControl(target)
{
	target.readOnly = false;
	target.className = "exceltextboxdl";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function disableControl(target)
{
	target.readOnly = true;
	target.className = "exceltextbox";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function OpenWindow(urlImage, iWidth, iHeight)
{
	var url = urlImage;
	var width=iWidth-10;
	var height=iHeight-10;
	var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	if(iHeight<screen.height)
	{
		window.open(url,'Motivational_DNA','top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+'').focus();
	}
	else
	{
		window.open(url,'Motivational_DNA','top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+'').focus();
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function openEditor(formName, ImageFolder, strUrl)
{
	
	strUrl = strUrl + "?form=" + formName + "&folder=" + ImageFolder;
	var width=680;
	var height=400;
	var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	window.open(strUrl,'OnlineEditor','top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+'').focus();

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Get Website Url
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetWebsiteUrl()
{
	var strReturnValue = "";
	var strUrl = window.location.href.toLowerCase();
	strUrl = strUrl.replace("http://","");
	var iLastIndex = strUrl.lastIndexOf("/");
	//Prevent for infinite loop
	var iLoopIndex = 0; 
	while((iLastIndex > 0) && (iLoopIndex < 20))
	{
		strUrl = strUrl.substring(0,iLastIndex);
		iLastIndex = strUrl.lastIndexOf("/");
		iLoopIndex++;
	}
	strUrl = "http://" + strUrl + "/";
	return strUrl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkMemberLogin(target, strUrl)
{
	var objUsername = document.getElementById('txtLoginUserName');
	var objPassword = document.getElementById('txtLoginPassword');
	var strAlert = "";
	strAlert = strAlert + VKCheckRequireField(objUsername, "Please enter your username!\n");
	strAlert = strAlert + VKCheckRequireField(objPassword, "Please enter your password!\n");
	if(strAlert != "")
	{
		alert(strAlert);
		return false;
	}
	else
	{
		target.action = strUrl;
		target.method = "post";
		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function actionMe(action, actionWho)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.aspnetForm.elements.length; i++)
		{	
			e = document.aspnetForm.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 actionMeEx(action, actionWho, appendMessage)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.aspnetForm.elements.length; i++)
		{	
			e = document.aspnetForm.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 sortMe(strUrl, Sort, strQueryString, target)
	{
		if(strUrl.indexOf("order=") > 0)
		{
			strUrl = strUrl.replace("order=" + Sort,"order=" + target.value);
		}
		else
		{
			if(strQueryString == "")
			{
				strUrl = strUrl + "?" + "order=" + target.value;
			}
			else
			{
				strUrl = strUrl + "&" + "order=" + target.value;
			}
		}
		window.location.href=strUrl;
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function sortbyMe(strUrl, SortBy, strQueryString, target)
	{
		if(strUrl.indexOf("orderdirection=") > 0)
		{
			strUrl = strUrl.replace("orderdirection=" + SortBy,"orderdirection=" + target.value);
		}
		else
		{
			if(strQueryString == "")
			{
				strUrl = strUrl + "?" + "orderdirection=" + target.value;
			}
			else
			{
				strUrl = strUrl + "&" + "orderdirection=" + target.value;
			}
		}
		window.location.href=strUrl;
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doSearch()
{
	var objKeyword = document.getElementById('txtKeywordSearch');
	window.location.href="search.aspx?keyword=" + objKeyword.value;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check All function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkAll(coltrolName, target)
	{
		var iIndex = 1;
		for (i = 0; i < document.aspnetForm.elements.length; i++)
		{	
			e = document.aspnetForm.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 = "#EFEFEF";
				}
				*/
			}
			if ((e.name == coltrolName))
			{
				iIndex++;
			}
		}
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function checkSelect(target, iIndex)
	{
		var trRow = document.getElementById("trRow" + iIndex);
		if(target.checked)
		{
			trRow.bgColor = "#CEDAEF";
		}
		else
		{
			trRow.bgColor = "#EFEFEF";
		}
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeCountry(target,ProvinceComboboxName,ProvinceDivID,DistrictComboboxName,DistrictDivID)
		{
			var CountryCode = target.value;
			var iIndex = GetArrayIndex(arrCountryArray,CountryCode);
			var strProvinceControl = "";
			if(iIndex >= 0)
			{
				var strListProvinceCode = arrProvinceListArrayCode[iIndex]
				var strListProvinceName = arrProvinceListArrayName[iIndex]
				var arrProvinceCode = strListProvinceCode.split("|");
				var arrProvinceName = strListProvinceName.split("|");
				if(arrProvinceCode.length > 0)
				{
					strProvinceControl = strProvinceControl + "<select  class=\"TEXTBOX\" id=\"" + ProvinceComboboxName + "\" name=\"" + ProvinceComboboxName + "\" onchange=\"changeProvince(this,'" + DistrictComboboxName + "','" + DistrictDivID + "')\">";
					for(i = 0; i < arrProvinceCode.length;i++)
					{
						strProvinceControl = strProvinceControl + "<option value=\"" + arrProvinceCode[i] + "\">" + arrProvinceName[i] + "</option>";
					}
					strProvinceControl = strProvinceControl + "</select>";
				}
			}
			else
			{
				strProvinceControl = strProvinceControl + "<select  class=\"TEXTBOX\" id=\"" + ProvinceComboboxName + "\" name=\"" + ProvinceComboboxName + "\">";
				strProvinceControl = strProvinceControl + "<option value=\"\">---</option>";
				strProvinceControl = strProvinceControl + "</select>";
				document.getElementById(DistrictDivID).innerHTML = strProvinceControl;
			}
			document.getElementById(ProvinceDivID).innerHTML = strProvinceControl;
		}
		////////////////////////////////////////////////////////////////////////////////////
		//
		////////////////////////////////////////////////////////////////////////////////////
		function changeProvince(target,DistrictComboboxName,DistrictDivID)
		{
			var ProvinceCode = target.value;
			var iIndex = GetArrayIndex(arrProvinceArray,ProvinceCode);
			
			var strDistrictControl = "";
			if(iIndex >= 0)
			{
				var strListDistrictCode = arrDistrictListArrayCode[iIndex]
				var strListDistrictName = arrDistrictListArrayName[iIndex]
				var arrDistrictCode = strListDistrictCode.split("|");
				var arrDistrictName = strListDistrictName.split("|");
				if(arrDistrictCode.length > 0)
				{
					strDistrictControl = strDistrictControl + "<select class=\"TEXTBOX\" id=\"" + DistrictComboboxName + "\" name=\"" + DistrictComboboxName + "\" onchange=\"changeProvince(this,'" + DistrictComboboxName + "','" + DistrictDivID + "')\">";
					for(i = 0; i < arrDistrictCode.length;i++)
					{
						strDistrictControl = strDistrictControl + "<option value=\"" + arrDistrictCode[i] + "\">" + arrDistrictName[i] + "</option>";
					}
					strDistrictControl = strDistrictControl + "</select>";
				}
			}
			else
			{
				strDistrictControl = strDistrictControl + "<select class=\"TEXTBOX\" id=\"" + DistrictComboboxName + "\" name=\"" + DistrictComboboxName + "\">";
				strProvinceControl = strProvinceControl + "<option value=\"\">---</option>";
				strDistrictControl = strDistrictControl + "</select>";
			}
			document.getElementById(DistrictDivID).innerHTML = strDistrictControl;
			
		}
		////////////////////////////////////////////////////////////////////////////////////
		//
		////////////////////////////////////////////////////////////////////////////////////
		function GetArrayIndex(arrArray,value)
		{
			var iReturnValue = -1;
			for(i = 0; i < arrArray.length;i++)
			{
				if(arrArray[i] == value)
				{
					iReturnValue = i;
				}
			}
			return iReturnValue;
		}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function doEmailRegister(objEmailName)
	{
		var strUrl = "Email.aspx";
		var NewsLetterEmail = document.getElementById(objEmailName).value;
		strUrl = strUrl + "?Email=" + NewsLetterEmail;
		window.location.href = strUrl;
	}
	
	function doPropertySearch(objPropertyTypeName,objCounty,objZipName)
	{
		var strUrl = "ListProperty.aspx";
		var PropertyType = document.getElementById(objPropertyTypeName).value;
		var County = document.getElementById(objCounty).value;
		var Zip = document.getElementById(objZipName).value;
		if(Zip == "Enter Zip Code")
		{
			Zip = "";
		}
		if(County != "0")
		{
			Zip = "";
		}
		strUrl = strUrl + "?type=" + PropertyType + "&County=" + County + "&Zip=" + Zip
		window.location.href = strUrl;
	}
	
		function doAdvancePropertySearch(PropertyType,objCityName,objStateCode,objZipName,objFromPrice,objToPrice,objBed,objBath)
	{
		var strUrl = "ListProperty.aspx";
		var City = document.getElementById(objCityName).value;
		var StateCode = document.getElementById(objStateCode).value;
		var Zip = document.getElementById(objZipName).value;
		var FromPrice = document.getElementById(objFromPrice).value;
		var ToPrice = document.getElementById(objToPrice).value;
		var Bed = document.getElementById(objBed).value;
		var Bath = document.getElementById(objBath).value;
		if(City == "Enter City")
		{
			City = "";
		}
		if(City != "")
		{
			Zip = "";
		}
		if(Zip == "Enter Zip Code")
		{
			Zip = "";
		}
		
		
		strUrl = strUrl + "?type=" + PropertyType + "&City=" + City  + "&state=" + StateCode + "&Zip=" + Zip + "&FromPrice=" + FromPrice + "&ToPrice=" + ToPrice + "&Bed=" + Bed + "&Zip=" + Bath;
		window.location.href = strUrl;
	}
	
	function changeFeatureImage(fileName,PropertyID,Price ,Industry ,IndustrySegment ,PropertySpace ,Beds ,Baths ,Garage ,PropertyType,Type)
    {
        document.getElementById("divPrice").innerHTML = "<b>Price: </b>" + Price;
        document.getElementById("divIndustry").innerHTML = Industry;
        document.getElementById("divPropertySpace").innerHTML = "<b>Living Space: </b>" + PropertySpace;
        document.getElementById("divBeds").innerHTML = "<b>Beds: </b>" + Beds;
        document.getElementById("divBaths").innerHTML = "<b>Baths: </b>" + Baths;
        document.getElementById("divGarage").innerHTML = "<b>Car Garage: </b>" + Garage;
        document.getElementById("divType").innerHTML = "<b>Type: </b>" + Type;
        document.getElementById("divMoreInfo").innerHTML = "<a class=\"white_text\" href=\"ViewProperty.aspx?action=view&pid=" + PropertyID + "&type=" + PropertyType + "\">" + "More Info" + "</a>";
        
    }