﻿// VARIABLES AND CONSTANTS
var destBrowser, destBrowserVer;
var BRW_MSIE = "MSIE";
var BRW_FIREFOX = "FireFox";
var BRW_SAFARI = "Safari", BRW_SAFARI_IPAD = "iPad", BRW_SAFARI_IPHONE = "iPhone";
var BRW_OPERA = "Opera";
var BRW_CHROME = "Chrome";

var offX, offY;

var AdsIdx = 0;
var MAXADSCOUNT = 3;

var CRMessage = "This article is copyright protected.\nBotanyVN Group 2007-2011.";

// VARIABLES AND CONSTANTS FOR ROLLING BANNERS
var bnnTmpInt = 0, bnnTmpTOut = 0;
var BNN_STEPSCOUNT = 0;
var bnnRoll = true;
var bnnCurrOpac = 0, bnnCurrStep = 0, bnnSlideId = 0;
var bnnContainEl, bnnStaticEl, bnnDynEl;
var bnnSlideArr = new Array();
var bnnFSId, bnnSSId;

// WEB LANGUAGE CONSTANTS
var pageLang

// -----------------------------------------

function currBrowser()
{
	var tmpAgentStr, startPos;

	tmpAgentStr = navigator.userAgent;
	
	if (tmpAgentStr.toUpperCase().indexOf(BRW_FIREFOX.toUpperCase()) > -1)
	{
		destBrowser = BRW_FIREFOX;
		destBrowserVer = tmpAgentStr.substr(tmpAgentStr.toUpperCase().indexOf(BRW_FIREFOX.toUpperCase()) + BRW_FIREFOX.length + 1);
	}
	else if (tmpAgentStr.toUpperCase().indexOf(BRW_MSIE.toUpperCase()) > -1)
	{
		destBrowser = BRW_MSIE;
		destBrowserVer = parseFloat(tmpAgentStr.substr(tmpAgentStr.toUpperCase().indexOf(BRW_MSIE.toUpperCase()) + BRW_MSIE.length + 1, 4)).toFixed(1);
	}
	else if (tmpAgentStr.toUpperCase().indexOf(BRW_CHROME.toUpperCase()) > -1)
	{
		destBrowser = BRW_CHROME;
		startPos = tmpAgentStr.toUpperCase().indexOf(BRW_CHROME.toUpperCase());
		destBrowserVer = tmpAgentStr.substr(startPos + BRW_CHROME.length + 1, tmpAgentStr.indexOf(" ", startPos) - (startPos + BRW_CHROME.length + 1));
	}
	else if (tmpAgentStr.toUpperCase().indexOf(BRW_SAFARI.toUpperCase()) > -1)
	{
		if(tmpAgentStr.toUpperCase().indexOf(BRW_SAFARI_IPAD) > -1)
			destBrowser = BRW_SAFARI_IPAD;
		else if (tmpAgentStr.toUpperCase().indexOf(BRW_SAFARI_IPHONE) > -1)
			destBrowser = BRW_SAFARI_IPHONE;
		else
			destBrowser = BRW_SAFARI;
		
		startPos = tmpAgentStr.toUpperCase().indexOf("VERSION");
		destBrowserVer = tmpAgentStr.substr(startPos + 8, tmpAgentStr.indexOf(" ", startPos) - (startPos + 8));
	}
	else if (tmpAgentStr.toUpperCase().indexOf(BRW_OPERA.toUpperCase()) > -1)
	{
		destBrowser = BRW_OPERA;
		destBrowserVer = tmpAgentStr.substr(tmpAgentStr.toUpperCase().indexOf("VERSION") + 8);
	}
	else
	{
		destBrowser = "Unknown";
		destBrowserVer = "1.0";
	}
	
	return true;
}

function isiPhoneiPad()
{
	var tmpAgentStr;

	tmpAgentStr = navigator.userAgent;
	if(tmpAgentStr.toUpperCase().indexOf(BRW_SAFARI.toUpperCase()) > 0 && tmpAgentStr.toUpperCase().indexOf("IPHONE") > 0 || tmpAgentStr.toUpperCase().indexOf("IPAD") > 0)
	{
		return true;
	}
}

function PageSel(SrcCatID, SrcLang, SrcObj)
{
	var CurrObj = SrcObj;
	var CurrPage = Number(CurrObj.options[CurrObj.selectedIndex].value);
	if (SrcLang == "en")
		document.location = "cnt.asp?param=news&catid=" + SrcCatID + "&pg=" + CurrPage + "&lg=en";
	else
		document.location = "cnt.asp?param=news&catid=" + SrcCatID + "&pg=" + CurrPage;
}

function ShowComment(SrcObj)
{
	var divComment = document.getElementById("divComment");
	
	if(divComment.style.display != "")
	{
		divComment.style.display = "";
		
		var newObj = document.getElementById("a_ShowComment");
		newObj.style.color = "#A0A0A0";
		newObj.style.cursor = "auto";
		
		var newObj = document.getElementById("img_ShowComment");
		newObj.style.cursor = "auto";
	}
}

function SubmitCmt(srcLang, srcLogged)
{
	if (srcLogged == 0)
	{
		var tmpEmail = document.forms["frmCmt"].elements["txtEmail"].value;
		var tmpContent = document.forms["frmCmt"].elements["txtContent"].value;
		
		if (trim(tmpEmail) == "")
		{
			if (srcLang == "en")
				alert("Please specify your Email address");
			else
				alert("Đề nghị nêu địa chỉ Email của bạn!");
			event.returnValue = false;
		}
		else if (tmpEmail.indexOf("@") == -1)
		{
			if (srcLang == "en")
				alert("It seems not to be a valid email address");
			else
				alert("Địa chỉ email không đúng định dạng");
			event.returnValue = false;
		}
		else if (trim(tmpContent) == "")
		{
			if (srcLang == "en")
				alert("Please write your comment!");
			else
				alert("Đề nghị nêu Nội dung phản hồi!");
			event.returnValue = false;
		}
		else
		{
			document.forms["frmCmt"].submit();
		}
	}
	else
	{
		var tmpContent = document.forms["frmCmt"].elements["txtContent"].value;
		
		if (trim(tmpContent) == "")
		{
			if (srcLang == "en")
				alert("Please write your comment!");
			else
				alert("Đề nghị nêu Nội dung phản hồi!");
			event.returnValue = false;
		}
		else
		{
			document.forms["frmCmt"].submit();
		}
	}
}

function trim(str)
{
	if (str.length == 0)
		return false;
	
	var start = 0;
	var end = str.length;
	while (start < str.length && str.charAt(start) == ' ') start++;
	while (end > 0 && str.charAt(end-1) == ' ') end--;
	return str.substr(start, end-start);
}

function EnterToSubmit(e, lg)
{
	if(e.keyCode == 13)
	{
		SubmitSearch(lg);
	}
}

function EnterToSubmiteDir(e, lg)
{
	if(e.keyCode == 13)
	{
		SubmiteDirSearch(lg);
	}
}

function SubmitSearch(lg)
{
	var txtSearchText = document.getElementById("txtSearchText");
	if(lg != null)
	{
		document.location = "cnt.asp?param=search&strsearch=" + txtSearchText.value + "&lg=en";
	}
	else
	{
		document.location = "cnt.asp?param=search&strsearch=" + txtSearchText.value;
	}
}

function SubmiteDirSearch(lg)
{
	var txtSearchText = document.getElementById("q");
	var selName = document.getElementById("namesel");
	if(lg != "")
	{
		document.location = "cnt.asp?param=edir&q=" + txtSearchText.value + "&t=" + selName.value + "&lg=en";
	}
	else
	{
		document.location = "cnt.asp?param=edir&q=" + txtSearchText.value + "&t=" + selName.value;
	}
}


function URLEncode(clearString)
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function StopMarquee(srcMrq)
{
	var tmpMarquee = document.getElementById(srcMrq);
	//alert(tmpMarquee.id);
	tmpMarquee.stop();
}

function StartMarquee(srcMrq)
{
	var tmpMarquee = document.getElementById(srcMrq);
	//alert(tmpMarquee.id);
	tmpMarquee.start();
}

function LoadActualImage(e)
{
	currBrowser();
	closeImgDiv();
	if(destBrowser == BRW_MSIE)
	{
		var oSrcEl = event.srcElement;
		var colSpan = oSrcEl.getElementsByTagName("SPAN");
	}
	else
	{
		var oSrcEl = e.target;
		var colSpan = oSrcEl.getElementsByTagName("SPAN");
	}
	
	var oDiv = document.createElement("DIV");
	oDiv.id = "ImgDiv";
	oDiv.style.backgroundColor = "#D0FFD0";
	
	oDiv.style.width = "800px";
	oDiv.style.height = document.body.clientHeight - 40 + "px";
	oDiv.style.left = (document.body.clientWidth - 800) / 2 + "px";
	if(destBrowser == BRW_MSIE)
	{
		oDiv.style.top = document.body.scrollTop + 20 + "px";
		oDiv.style.position = "absolute";
	}
	else
	{
		oDiv.style.top = 20 + "px";
		oDiv.style.position = "fixed";
	}
	oDiv.style.zIndex = "1000000";
	oDiv.style.filter = "alpha(opacity=90)";
	oDiv.style.opacity = "0.90";
	oDiv.style.border = "1px outset green";
	oDiv.style.borderRadius = "10px";	oDiv.style.MozBorderRadius = "10px";
	document.body.appendChild(oDiv);

	var oTitle = document.createElement("DIV");
	oTitle.style.width = "100%";
	oTitle.style.height = "25px";
	oTitle.style.backgroundColor = "#40C040";
	oTitle.style.borderRadius = "10px";	oTitle.style.MozBorderRadius = "10px";
	if(pageLang == "EN")
	{
		oTitle.innerHTML = "<table height='100%' width='100%' align='left' cellspacing='0' cellpadding='0' border='0'><tr valign='middle'><td><b>&nbsp;&nbsp;View photo</b></td><td width='80' align='right'><span onclick='closeImgDiv();' style='cursor: pointer'><b>Close</b>&nbsp;</span></td><td width='20'><img src='Images/iconClose.gif' onclick='closeImgDiv();' style='cursor: pointer'></td></tr></table>";
	}
	else
	{
		oTitle.innerHTML = "<table height='100%' width='100%' align='left' cellspacing='0' cellpadding='0' border='0'><tr valign='middle'><td><b>&nbsp;&nbsp;Xem hình ảnh</b></td><td width='80' align='right'><span onclick='closeImgDiv();' style='cursor: pointer'><b>Đóng</b>&nbsp;</span></td><td width='20'><img src='Images/iconClose.gif' onclick='closeImgDiv();' style='cursor: pointer'></td></tr></table>";
	}
	oDiv.appendChild(oTitle);
	
	// Create a DIV with overflow = scroll to contain image/photo
	var oDiv2 = document.createElement("DIV");
	oDiv2.id = "ImgDiv2";
	oDiv2.style.textAlign = "center";
	oDiv2.style.backgroundColor = "white";
	oDiv2.style.width = "760px";
	if(destBrowser == BRW_MSIE) oDiv2.style.height = oDiv.style.pixelHeight - 60 + "px"; else oDiv2.style.height = oDiv.clientHeight - 60 + "px";
	oDiv2.style.left = parseInt(oDiv.style.left) + (parseInt(oDiv.style.width) - 760) / 2 + "px";
	oDiv2.style.border = "1px inset #40C040";
	if(destBrowser == BRW_MSIE)
	{
		
		oDiv2.style.top = document.body.scrollTop + 60 + "px";
		oDiv2.style.position = "absolute";
	}
	else
	{
		oDiv2.style.top = 60 + "px";
		oDiv2.style.position = "fixed";
	}
	oDiv2.style.zIndex = "1000001";
	oDiv2.style.overflow = "scroll";
	document.body.appendChild(oDiv2);
	var oImg = document.createElement("IMG");
	if(destBrowser == BRW_MSIE) oImg.src = colSpan[0].innerText; else oImg.src = colSpan[0].textContent;
	oDiv2.appendChild(oImg);
	document.body.scroll = "no";
}

function FitImage(ImgWidthResizedTo, srcLang)
{
	var TipString;
	var TipStringHTML;
	var ImgWidth;
	var ImgHeight;
	
	pageLang = srcLang
	
	if(srcLang == "EN")
	{
		TipString = "This photo has higher resolution and has been resized to fit the screen.\nClick here to view the actual image size";
		TipStringHTML = "This photo has higher resolution and has been resized to fit the screen. Click here to view the actual image size";
	}
	else
	{
		TipString = "Ảnh dưới đây có kích thước lớn và đã được thu nhỏ vừa màn hình của bạn.\nBạn có thể nhấn vào đây để xem hình có kích thước thật";
		TipStringHTML = "Ảnh dưới đây có kích thước lớn và đã được thu nhỏ vừa màn hình của bạn. Bạn có thể nhấn vào đây để xem hình có kích thước thật";
	}
	
	if(!document.getElementById("divPresent")) return false; 	//Quit the process in case of there is not any divPresent
	
	var theDiv = document.getElementById("divPresent");
	var colImg = theDiv.getElementsByTagName("IMG");
	currBrowser();
	
	for (Seed = 0; Seed < colImg.length; Seed++)
	{
		while(!colImg[Seed].complete)
		{
			break;
		}

		ImgWidth = getImgWidth(colImg[Seed]);
		ImgHeight = getImgHeight(colImg[Seed]);
		
		if (parseInt(ImgWidth) > ImgWidthResizedTo)
		{
			colImg[Seed].style.width = ImgWidthResizedTo;
			//alert("Non-auto: " + parseInt(ImgHeight));
			colImg[Seed].style.height = ImgWidthResizedTo / parseInt(ImgWidth) * parseInt(ImgHeight);
			var oTip = document.createElement("DIV");
			if(destBrowser == BRW_MSIE)
			{
				colImg[Seed].insertAdjacentElement("beforeBegin", oTip);
				oTip.innerText = TipString;
				oTip.attachEvent("onclick", LoadActualImage);
			}
			else
			{
				colImg[Seed].parentNode.insertBefore(oTip, colImg[Seed]);
				oTip.textContent = TipStringHTML;
				oTip.addEventListener("click", LoadActualImage, false);
			}
			oTip.style.fontSize = "8pt";
			oTip.style.fontWeight = "normal";
			oTip.style.fontStyle = "normal";
			oTip.style.color = "green";
			oTip.style.border = "1px solid gold";
			oTip.style.backgroundColor = "lightyellow";
			oTip.style.cursor = "pointer";
			oTip.width = ImgWidthResizedTo;
			
			var oHRef = document.createElement("SPAN");
			oHRef.innerHTML = colImg[Seed].src;
			oHRef.style.display ="none";
			oTip.appendChild(oHRef);
		}
		else if(ImgWidth == "auto")
		{
			if (colImg[Seed].width > ImgWidthResizedTo)
			{
				colImg[Seed].style.width = ImgWidthResizedTo;
				//alert("Auto: " + parseInt(ImgHeight));
				colImg[Seed].style.height = ImgWidthResizedTo / parseInt(ImgWidth) * parseInt(ImgHeight);
				var oTip = document.createElement("DIV");
				if(destBrowser == BRW_MSIE)
				{
					colImg[Seed].insertAdjacentElement("beforeBegin", oTip);
					oTip.innerText = TipString;
					oTip.attachEvent("onclick", LoadActualImage);
				}
				else
				{
					colImg[Seed].parentNode.insertBefore(oTip, colImg[Seed]);
					oTip.textContent = TipStringHTML;
					oTip.addEventListener("click", LoadActualImage, false);
				}
				oTip.style.fontSize = "8pt";
				oTip.style.fontWeight = "normal";
				oTip.style.fontStyle = "normal";
				oTip.style.border = "1px solid gold";
				oTip.style.color = "green";
				oTip.style.backgroundColor = "lightyellow";
				oTip.style.cursor = "pointer";
				oTip.width = ImgWidthResizedTo;
				
				var oHRef = document.createElement("SPAN");
				oHRef.innerHTML = colImg[Seed].src;
				oHRef.style.display ="none";
				oTip.appendChild(oHRef);
			}
		}
		else
		{
			
		}
	}
}

function getImgWidth(srcObj)
{
	var s;
	var imgWidth;
		
	if (destBrowser == BRW_MSIE)
	{
		while(1 == 2)
		{
			if(srcObj.complete) break;
		}
		return srcObj.width;
	}
	else
	{
		s = document.defaultView.getComputedStyle(srcObj, null);
		imgWidth = s.getPropertyValue("width");
		return imgWidth;
	}
}

function getImgHeight(srcObj)
{
	var s;
	var imgHeight;
		
	if (destBrowser == BRW_MSIE)
	{
		while(1 == 2)
		{
			if(srcObj.complete) break;
		}
		return srcObj.height;
	}
	else
	{
		s = document.defaultView.getComputedStyle(srcObj, null);
		imgWidth = s.getPropertyValue("height");
		return imgWidth;
	}
}

function closeImgDiv()
{
	if(document.getElementById("ImgDiv"))
	{
		var oDiv = document.getElementById("ImgDiv");
		oDiv.parentNode.removeChild(oDiv);
		var oDiv = document.getElementById("ImgDiv2");
		oDiv.parentNode.removeChild(oDiv);
	}
	document.body.scroll = "yes";
}

function SlidePage(SrcObj, SrcPage, SrcArr)
{
	var i
	if(SrcPage < 0)
		SrcPage = 0;
	if(SrcPage > SrcArr.length)
		SrcPage = SrcArr.length;
	obj = document.getElementById(SrcObj);
	currBrowser();

	if(destBrowser == BRW_MSIE)
	{
		obj.filters(0).apply();
		obj.innerHTML = SrcArr[SrcPage - 1];
		obj.filters(0).play();
	}
	else
	{
		obj.innerHTML = SrcArr[SrcPage - 1];
	}
	FindSelectOption("selPageTop", SrcPage);
	FindSelectOption("selPageBottom", SrcPage);

	FitImage();
}

function ScrollToPage(SrcObj, Direction, SrcArr)
{
	switch(Direction.toUpperCase())
	{
		case "FIRST":
			if(CurrPage > 1)
			{
				CurrPage = 1;
				SlidePage(SrcObj, CurrPage, SrcArr);
			}
			break;
			
		case "PREV":
			if (CurrPage > 1)
			{
				CurrPage = CurrPage - 1;
				SlidePage(SrcObj, CurrPage, SrcArr);
			}
			break;
			
		case "NEXT":
			if (CurrPage < SrcArr.length)
			{
				CurrPage = CurrPage + 1;
				SlidePage(SrcObj, CurrPage, SrcArr);
			}
			break;
			
		case "LAST":
			if(CurrPage < SrcArr.length)
			{
				CurrPage = SrcArr.length;
				SlidePage(SrcObj, CurrPage, SrcArr);
			}
			break;
			
		default:
			break;
	}
	FitImage(550, "");
}

function ScrollToSelPage(SrcObj, SrcArr, SrcEl)
{
	var currDropdown = SrcEl;
	CurrPage = currDropdown.options[currDropdown.selectedIndex].value
	if(!isNaN(CurrPage)) { CurrPage = Number(CurrPage); }
	if(CurrPage > SrcArr.length || CurrPage <= 0)
	{
		CurrPage = 1;
		SlidePage(SrcObj, CurrPage, SrcArr);
	}
	else
	{
		SlidePage(SrcObj, CurrPage, SrcArr);
	}
	FitImage(550, "");
}

function FindSelectOption(SrcObj, NewVal)
{
	var obj = document.getElementById(SrcObj);
	for(i = 0; i <= obj.options.length; i++)
	{
		if(obj.options[i].value == NewVal)
		{
			obj.options[i].selected = true;
			break;
		}
	}
}

/*function getImgWidth(srcObj)
{
	var s;
	var imgWidth;
		
	if (srcObj.currentStyle != null)
	{
		s = srcObj.currentStyle;
		imgWidth = s.width;
		alert(srcObj.offsetWidth);
	}
	else
	{
		s = document.defaultView.getComputedStyle(srcObj, null);
		imgWidth = s.getPropertyValue("width");
	}
	return imgWidth;
}
*/

function buildBanners(srcContainId, srcFSId, srcSSId, srcSlideName)
{
	var collDiv = document.getElementsByTagName("DIV");
	for(i=0; i < collDiv.length; i++)
	{
		if(collDiv[i].getAttribute("name") != null)
		{
			if(collDiv[i].getAttribute("name") == srcSlideName) bnnSlideArr.push(collDiv[i].innerHTML);
		}
	}
	
	bnnFSId = srcFSId; bnnSSId = srcSSId;
	
	var tmpFirstSlide = document.getElementById(bnnFSId);
	tmpFirstSlide.innerHTML = bnnSlideArr[0];
	bnnContainEl = document.getElementById(srcContainId);
	setTimeout(playBanner, 6000);
	
	var defImg = document.getElementById("defImg");
	defImg.style.display = "none";
}

function playBanner()
{
	BNN_STEPSCOUNT = 25;
	bnnCurrOpac = 100; bnnCurrStep = 1;
	if(bnnTmpTOut != 0) clearTimeout(bnnTmpTOut);
	bnnSlideId = bnnSlideId + 1; if(bnnSlideId > (bnnSlideArr.length - 1)) bnnSlideId = 0;
	
	if(bnnRoll)
	{
		bnnStaticEl = document.getElementById("FirstSlide");
		bnnDynEl = document.getElementById("SecondSlide");
	}
	else
	{
		bnnStaticEl = document.getElementById("SecondSlide");
		bnnDynEl = document.getElementById("FirstSlide");
	}
	bnnStaticEl.style.left = 0;
	bnnStaticEl.style.display = "";
	bnnStaticEl.style.zIndex = 0;
	bnnDynEl.style.left = parseInt(bnnContainEl.style.width);
	bnnDynEl.style.display = "";
	bnnDynEl.style.zIndex = 1;	
	//alert(bnnSlideArr[bnnSlideId]);
	bnnDynEl.innerHTML = bnnSlideArr[bnnSlideId];
	
	if(navigator.appName.toLowerCase().indexOf("internet explorer") != -1)
	{
		bnnDynEl.filters.alpha.opacity = bnnCurrOpac;
	}
	else
	{
		bnnDynEl.style.opacity = bnnCurrOpac / 100;
	}
	
	bnnTmpInt = setInterval(rollSlice, 15);
		
	bnnRoll = !bnnRoll;
	bnnTmpTOut = setTimeout(playBanner, 6000);
}

function rollSlice()
{
	bnnDynEl.style.left = (BNN_STEPSCOUNT - bnnCurrStep) * (parseInt(bnnContainEl.style.width) / BNN_STEPSCOUNT);

	bnnCurrOpac = bnnCurrOpac - (100 / BNN_STEPSCOUNT);	
	if(navigator.appName.toLowerCase().indexOf("internet explorer") != -1)
	{
		bnnStaticEl.filters.alpha.opacity = bnnCurrOpac;
	}
	else
	{
		bnnStaticEl.style.opacity = bnnCurrOpac / 100;
	}
	bnnCurrStep = bnnCurrStep + 1;
	
	if(bnnCurrStep > BNN_STEPSCOUNT) clearInterval(bnnTmpInt);
}

function fillDaylist(destComboName, mIdx)
{
	var destCombo = document.getElementById(destComboName);
	var monthIdx = mIdx + 1;
	var tmpIdx, maxDay;
	//
	tmpIdx = destCombo.selectedIndex;
	if(tmpIdx == -1) tmpIdx = 0;
	destCombo.options.length = 0;
	currBrowser();

	switch(monthIdx)
	{
		case 1: case 3: case 5: case 7: case 8: case 10: case 12:
			maxDay = 30;
			break;
		case 2:
			maxDay = 28;
			break;
		default:
			maxDay = 29;
	}
	for(i=0; i <= maxDay; i++)
	{
		var oOpt = document.createElement("OPTION");
		oOpt.value = i;
		oOpt.text = i + 1;
		if(destBrowser == BRW_MSIE)
			destCombo.add(oOpt);
		else
			destCombo.add(oOpt, null);
	}
	if(tmpIdx > maxDay)
		destCombo.selectedIndex = maxDay;
	else
		destCombo.selectedIndex = tmpIdx;
}

function refreshCaptcha()
{
	var imgCaptcha = document.getElementById("imgCaptcha");
	if(imgCaptcha!=null)
		imgCaptcha.src = "\LoadCaptcha.asp?r=" + Math.floor(Math.random()*10) + Math.floor(Math.random()*20);
}

function eDirBrowse(e, srcList, srcLangString)
{
	var elSelect, itemName;
	elSelect = (e.target) ? e.target : window.event.srcElement;
	itemName = elSelect.options[elSelect.selectedIndex].value;
	window.location = "cnt.asp?param=edir&v=" + itemName + "&list=" + srcList + srcLangString;
}

function setfocusQ(e)
{
	if(document.getElementById("q"))
	{
		//alert("here!");
		document.getElementById("q").focus();
	}
}

function getOffsetCoord(srcObj)
{
	var currObj, oldObj;
	var oLeft = 0, oTop = 0;
	//
	currObj = srcObj;
	
	while(currObj.tagName != "BODY" && currObj.tagName != "HTML")
	{
		
		oLeft = oLeft + parseInt(currObj.offsetLeft);
		oTop = oTop + parseInt(currObj.offsetTop);
		//alert(currObj.tagName + oLeft);
		oldObj = currObj;
		currObj = oldObj.offsetParent;
	}
	
	offX = oLeft;
	offY = oTop;
}

function showTopHead(srcOffsetIndent)
{
	var objTopHead = document.getElementById("divTopHead");
	var objTdTopHead = document.getElementById("tdTopHead");
	getOffsetCoord(objTdTopHead);
	
	objTopHead.style.position = "absolute";
	objTopHead.style.left = offX + srcOffsetIndent + "px";
	objTopHead.style.top = "14px";
	objTopHead.style.width = "600px";
	objTopHead.style.height = "53px";
	objTopHead.style.display = "";
}

function clickIE4()
{
	if(event.button == 2)
	{
		alert(CRMessage);
		return false;
	}
}
	
function clickNS4(e)
{
	if(document.layers || document.getElementById && !document.all)
	{
		if(e.which == 2 || e.which == 3)
		{
			alert(CRMessage);
			return false;
		}
	}
}

function disright()
{
	if(document.layers)
	{
		document.getElementById("divPresent").captureEvents(Event.MOUSEDOWN);
		document.getElementById("divPresent").onmousedown = clickNS4;
	}
	else if(document.all && !document.getElementById)
	{
		document.getElementById("divPresent").onmousedown = clickIE4;
	}
	
	document.getElementById("divPresent").oncontextmenu = new Function("alert(CRMessage); return false")
}

function disableSelection(target)
{
	if(typeof target.onselectstart != "undefined") //IE route
		target.onselectstart = function(){return false;}
	else if(typeof target.style.MozUserSelect != "undefined") //Firefox route
		target.style.MozUserSelect = "none"
	else //All other route (ie: Opera)
		target.onmousedown = function(){return false;}
	
	target.style.cursor = "default"
}

function initcnt(pagelang, isProtected)
{
	FitImage(550, pagelang);
	refreshCaptcha();
	setfocusQ();
	showTopHead(155);
	if(isProtected)
	{
		disright();
		disableSelection(document.getElementById("divPresent"));
		if(isiPhoneiPad()) document.body.style.webkitUserSelect = "none";
	}

	// If not exist a marquee then exit function
	if(document.getElementById("mrqShortListNewest")) createFadingLinesMarquee("mrqShortListNewest");
	if(document.getElementById("mrqShortListMostViewed")) createFadingLinesMarquee("mrqShortListMostViewed");
	
	var elStatistics = document.getElementById("elStatistics");
	elStatistics.src = "Includes/ifrStatistics.asp";

	
}

function initdefault()
{
	createFadingLinesMarquee("mrqShortNews");
	
	var elStatistics = document.getElementById("elStatistics");
	elStatistics.src = "Includes/ifrStatistics.asp";
	
	buildBanners("FrameAds", "FirstSlide", "SecondSlide", "slide");
	showTopHead(20);
	
}

function createFadingLinesMarquee(srcMarqueeId)
{
	var mrqPosX, mrqPosY;
	
	// Create fading lines on top of the marquee
	mrqPosX = findPosX(document.getElementById(srcMarqueeId));
	mrqPosY = findPosY(document.getElementById(srcMarqueeId));
	
	// MSIE does not return right ElementsByName so:
	currBrowser();
	if(destBrowser == BRW_MSIE)
		var colDiv = getElementsByName_iefix("DIV", "divOpac" + srcMarqueeId);
	else
		var colDiv = document.getElementsByName("divOpac" + srcMarqueeId);
	
	if(colDiv.length > 0)
	{
		//alert("On resize of window, move LEFT <-> RIGHT " + colDiv.length + " divs arranged to fade marquees!");
		for(i=0; i < colDiv.length; i++)
		{
			colDiv[i].style.left = mrqPosX;
		}
		return false;
	}
	else
	{
		for(i=1; i <= 10; i++)
		{
			var objDiv = document.createElement("DIV");
			objDiv.setAttribute("name", "divOpac" + srcMarqueeId);
			objDiv.style.position = "absolute";
			objDiv.style.left = mrqPosX; objDiv.style.top = mrqPosY + (i - 1) * 2;
			objDiv.style.width = document.getElementById(srcMarqueeId).offsetWidth; objDiv.style.height = "2px";
			objDiv.style.overflow = "hidden";
			objDiv.style.backgroundColor = "white";
			objDiv.style.opacity = 1 - ((i - 1) * 0.1); objDiv.style.filter = "alpha(opacity=" +  (100 - ((i - 1) * 10)) + ")";
			document.body.appendChild(objDiv);
		}
		
		// Create fading lines on bottom of the marquee
		mrqPosX = findPosX(document.getElementById(srcMarqueeId));
		mrqPosY = findPosY(document.getElementById(srcMarqueeId)) + document.getElementById(srcMarqueeId).offsetHeight;
		for(i=1; i <= 10; i++)
		{
			var objDiv = document.createElement("DIV");
			objDiv.setAttribute("name", "divOpac" + srcMarqueeId);
			objDiv.style.position = "absolute";
			objDiv.style.left = mrqPosX; objDiv.style.top = mrqPosY - (i - 1) * 2;
			objDiv.style.width = document.getElementById(srcMarqueeId).offsetWidth; objDiv.style.height = "2px";
			objDiv.style.overflow = "hidden";
			objDiv.style.backgroundColor = "white";
			objDiv.style.opacity = 1 - ((i - 1) * 0.1); objDiv.style.filter = "alpha(opacity=" +  (100 - ((i - 1) * 10)) + ")";
			document.body.appendChild(objDiv);
		}
		
		return false;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function getElementsByName_iefix(tag, srcName)
{
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	var iarr = 0;
	
	for(i = 0; i < elem.length; i++)
	{
		att = elem[i].getAttribute("name");
		if(att == srcName)
		{
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}
