///////////////////////////////////////////////////////

function isIE50() { // Private method
  return isIE5() && !isIE55();
}

function isIE55() { // Private method
  return navigator.userAgent.indexOf("MSIE 5.5") > -1;
}

function isIE5() { // Private method
  return navigator.userAgent.indexOf("MSIE 5") > -1;
}

function isIE6() { // Private method
  return navigator.userAgent.indexOf("MSIE 6") > -1 && navigator.userAgent.indexOf("Opera") == -1;
}

function isIE7() { // Private method
  return navigator.userAgent.indexOf("MSIE 7") > -1 && navigator.userAgent.indexOf("Opera") == -1;
}

function isIE8() { // Private method
  return navigator.userAgent.indexOf("MSIE 8") > -1 && navigator.userAgent.indexOf("Opera") == -1;
}

function isIE9() { // Private method
  return navigator.userAgent.indexOf("MSIE 9") > -1 && navigator.userAgent.indexOf("Opera") == -1;
}

function isOperaMini() { // Private method
  return navigator.userAgent.indexOf("Opera Mini") > -1;
}


function isIE() { // Private method
  return (isIE5() || isIE6() || isIE7() || isIE8() || isIE9());
}

///////////////////////////////////////////////////////

function switchLanguage(objLang) {
	var tempURL = new String();
	var searchURL = "";
	tempURL = document.location.href;
	
	if (tempURL.search(objLang) == -1)
	{
		var newURL = "";
		if (objLang == "hu-hu") {
			searchURL = "en-us";
		} else {
			searchURL = "hu-hu";
		}
		if (tempURL.search("/functions/functions") > -1 && objLang == "en-us") {
			tempURL = tempURL.replace("/functions/functions", "/product");
		}
		newURL = tempURL.replace(searchURL, objLang);
		window.location = newURL;
	}
}
function signin() {
	setLayersCenter("signin");
	$("overlay").style.height = document.body.scrollHeight + "px";
	$("overlay").show();
	$("signinProgress").hide();
	$("signinForm").show();
	$("signin").show();
	$("useremail").focus();
}
function closeSignin() {
	$("overlay").hide();
	$("signin").hide();
}
function setLayersCenter(obj) {
	$(obj).style.left = ( document.body.offsetWidth / 2 ) - ( $(obj).getWidth() / 2 )
}

///////////////////////////////////////////////////////
////////// FLASH INTERACT WITH JAVASCRIPT /////////////
///////////////////////////////////////////////////////
function getMenuNames() {
	return JSmenuItemNames;
}
function getMenuLinks() {
	return JSmenuItemLinks;
}
function getInnerFlashes() {
	return JSFlashSrc;
}
function getInnerFlashPictures() {
	return JSFlashTHMSrc;
}
function getInnerFlashPicturesOver() {
	return JSFlashTHMSrcOver;
}

///////////////////////////////////////////////////////
/////// Quick Links open and close function ///////////
///////////////////////////////////////////////////////

var opened = "enterprise";
var openedNews = "pressreleases";
var mitGlobalNeg = null;
var fromHGlobalNeg = 173
var toHGlobalNeg = 1

var mitGlobalPos = null;
var fromHGlobalPos = 1
var toHGlobalPos = 173

var moving = false;
var newsMoving = false;


function itemClick(obj) {
	var quickObjTitle = obj + "div";
	var openedQuickObjTitle = opened + "div";

	if (quickObjTitle != openedQuickObjTitle ) {
		$(quickObjTitle).className = "opened";
		$(openedQuickObjTitle).className = "";
	}
	if (obj != opened && moving == false) {
		moving = true;
		new Effect.Parallel([
			new Effect.SlideDown(obj, { sync: true }),
			new Effect.SlideUp(opened, { sync: true, afterFinishInternal: function(effect) { 
				element = $(opened).cleanWhitespace();
				var oldInnerBottom = element.down().getStyle('bottom');
				effect.element.hide().undoClipping().undoPositioned();
				effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
				moving = false;
			} })		
		], { 
			duration: 0.3
		});
		opened = obj;
	}
}

function newsClick(obj) {
	var objTitle = obj + "div";
	var openedObjTitle = openedNews + "div";
	
	if (objTitle != openedObjTitle) {
		$(objTitle).className = "opened";
		$(openedObjTitle).className = "";
	}
	if (obj != openedNews && newsMoving == false) {
		newsMoving = true;
		new Effect.Parallel([
			new Effect.SlideDown(obj, { sync: true }),
			new Effect.SlideUp(openedNews, { sync: true, afterFinishInternal: function(effect) { 
				element = $(openedNews).cleanWhitespace();
				var oldInnerBottom = element.down().getStyle('bottom');
				effect.element.hide().undoClipping().undoPositioned();
				effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
				newsMoving = false;
			} })		
		], { 
			duration: 0.3
		});

		openedNews = obj;
	}
}

function fillReviewsConteiner( targetObj, objNum )
{
	var actualNumber = objNum;
	var nextNumber = objNum + 1;
	if (nextNumber > (reviews.length - 1))
	{
		nextNumber = 0;
	}
	var reviewStr = "";
	reviewStr += "<p style='margin: 0px; padding: 0px;font-size:"+reviews[objNum][6]+"'>&quot;"+reviews[objNum][0]+"&quot;</p>";
	if (reviews[objNum][5] == "0")
	{
		reviewStr += "<div style='padding-top:5px;'>";
	}
	else
	{
		reviewStr += "<div style='padding-top:5px;'>";
	}
	reviewStr += "<span>/" + reviews[objNum][1] + "</span><br/>";
	if (reviews[objNum][2] != "")
	{
		reviewStr += "<span>" + reviews[objNum][2] + "</span><br/>";
	}
	if (reviews[objNum][3] != "")
	{
		reviewStr += "<span>" + reviews[objNum][3] + "</span><br/>";
	}
	if (reviews[objNum][4] != "")
	{
		reviewStr += "<span>" + reviews[objNum][4] + "</span><br/>";
	}
	reviewStr += "</div>";
	document.getElementById(targetObj).innerHTML = reviewStr;
	
	var myTime = setTimeout("fillReviewsConteiner('" + targetObj + "'," + nextNumber + ")",10000);
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function imgChange(imgID,pTodo,pMode) {
	if (pMode == 1) {
		if (document.images && imgID && pTodo && ( document.getElementById(imgID).src.search("_off") != -1 ||  document.getElementById(imgID).src.search("_on") != -1 ) ) {
			var imgStatus = "off";
			if (pTodo==1) imgStatus = "on";
			if (document.getElementById(imgID)) {
				var wsrc = document.getElementById(imgID).src;
				var w = wsrc.substr(0,wsrc.lastIndexOf("_")+1);
				var wExt = wsrc.substr(wsrc.lastIndexOf("."),4);
				document.getElementById(imgID).src = w + imgStatus + wExt;
			}
		}
	} else {
		if (document.images && imgID && pTodo && ( imgID.src.search("_off") != -1 ||  imgID.src.search("_on") != -1 ) ) {
			var imgStatus = "off";
			if (pTodo==1) imgStatus = "on";
			if (imgID) {
				var wsrc = imgID.src;
				var w = wsrc.substr(0,wsrc.lastIndexOf("_")+1);
				var wExt = wsrc.substr(wsrc.lastIndexOf("."),4);
				imgID.src = w + imgStatus + wExt;
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function sortDates() {
	for (var i = 0;i<dateArray.length;i++) {
		var tempArray = new Array();
		var newDateString = new Date();
		tempArray = dateArray[i].split("-");
		newDateString.setFullYear(parseFloat(tempArray[0]),(parseFloat(tempArray[1]) - 1),parseFloat(tempArray[2]));
		dateArray[i] = newDateString;
	}
	if ((dateArray[0] > dateArray[1]) && (dateArray[0] > dateArray[2])) {
		toggleNewsCategory2("pressreleases");
	}
	if ((dateArray[1] > dateArray[0]) && (dateArray[1] > dateArray[2])) {
		toggleNewsCategory2("generalnews");
	}
	if ((dateArray[2] > dateArray[0]) && (dateArray[2] > dateArray[1])) {
		toggleNewsCategory2("technicalnews");
	}
}

function toggleNewsCategory2( obj ) {
    new Effect.SlideDown(obj, { duration: 0.3 });
    $(obj + "div").className = "opened";
    openedNews = obj;
    $(opened + "div").className = "opened";
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function randomGenerate(maxNum) {
	return Math.floor(Math.random() * maxNum) + 1;
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function AJAXsignin() {
	$("signinForm").hide();
	$("signinProgress").show();
	new Ajax.Request('http://www.eagleeyeos.com/modules/wpcontrols/flash/signin.aspx', 
	  { 
	    method:'post',
	    parameters: {email: $("useremail").value, password: $("userpasswd").value},
	    onSuccess: function(transport){ 
	      var response = transport.responseText || "no response text"; 
	      responseProcess(response);
	    }, 
	    onFailure: function(){ /* alert('Something went wrong...') */ } 
	  });
}

function AJAXsignout() {
	new Ajax.Request('http://www.eagleeyeos.com/modules/wpcontrols/flash/signout.aspx', 
	  { 
	    onSuccess: function(transport){ 
	      var response = transport.responseText || "no response text"; 
	      if (response == "LoggedIn=no") {
	      	$("anonimUser").show();
			$("knownUser").hide();
	      }
	    }, 
	    onFailure: function(){ /* alert('Something went wrong...') */ } 
	  });
}

function AJAXlogincheck() {
	new Ajax.Request('http://www.eagleeyeos.com/modules/wpcontrols/flash/LoggedinUser.aspx', 
	  { 
	    onSuccess: function(transport){ 
	      var response = transport.responseText || "no response text"; 
	      displayLoggedinUser(response);
	    }, 
	    onFailure: function(){ /* alert('Something went wrong...') */ } 
	  });
}

function displayLoggedinUser(obj) {
	var tempArray = new Array();
	var responseArray = new Array();
	var key = new String();
	var value;
	tempArray = obj.split("&");
	for (var a=0;a<tempArray.length;a++) {
		key = tempArray[a].substr(0,tempArray[a].indexOf("="));
		value = tempArray[a].substr( tempArray[a].indexOf("=")+1,tempArray[a].length - tempArray[a].indexOf("=") );
		responseArray[key] = value;
	}
	if (responseArray["LoggedIn"] == "yes") {
		$("anonimUser").hide();
		$("userName").innerHTML = responseArray["UserName"];
		$("knownUser").show();
	} else {
		$("anonimUser").show();
		$("knownUser").hide();
	}
	$("initDiv").hide();
	closeSignin();
}

function responseProcess(obj) {
	// alert(obj);
	var tempArray = new Array();
	var responseArray = new Array();
	var key = new String();
	var value;
	tempArray = obj.split("&");
	for (var a=0;a<tempArray.length;a++) {
		key = tempArray[a].substr(0,tempArray[a].indexOf("="));
		value = tempArray[a].substr( tempArray[a].indexOf("=")+1,tempArray[a].length - tempArray[a].indexOf("=") );
		responseArray[key] = value;
	}
	if ( responseArray["Error"] == "yes" ) {
		// alert("Hibas formkitoltes es johet a valaszok feldolgozasa\n\n");
		$("noError").hide();
		$("isError").show();
		
		$("emailLabel").className = "formLabelError";
		$("emailInput").className = "formInputError";
		$("passwdLabel").className = "formLabelError";
		$("passwdInput").className = "formInputError";
		
		$("signinForm").show();
		$("signinProgress").hide();

	} else {
		$("noError").show();
		$("isError").hide();
		AJAXlogincheck();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function setSearchBoxEmpty( obj ) {
    if ( obj.value == "Search" || obj.value == "Keresés" ) {
        obj.value = "";
    }
}
function checkSearchBoxIsEmpty( obj ) {
	if (obj.value == "") {
		if (document.location.href.search("hu-hu") > -1) {
			obj.value = "Keresés";
		} else {
			obj.value = "Search";
		}
	}
}
function validateBtnPress(e) {
	var keycode;
	if (e.keyCode) {
		keycode = e.keyCode;
	} else {
		keycode = e.which;
	}
	if (keycode == 13) {
		searchRedirect();
	}
}

function searchRedirect() {
    var searchText = document.getElementById("txtSearchBox").value;
    document.location.href = "http://www.eagleeyeos.com/en-us/search.aspx?Search=" + searchText + "&SWhere=0&PageSize=10";
}


function openMainbanner()
{
	buildBannerTHM();
	$("bannerPagerBck").setOpacity(0);
	$("pictures").setOpacity(0);
	$("pictures").show();
	$("pagerContainer").setOpacity(0);
	$("bckpictures").setOpacity(0);
	new Effect.SlideDown('mainBanner', { duration: 0.5, transition: Effect.Transitions.sinoidal } );
	new Effect.Parallel([
			new Effect.Move("bannerPagerBck", { sync: true, x: 0, y: -66, mode: 'relative' }),
			new Effect.Scale("bannerPagerBck", 100, { sync: true, scaleFrom: 0.0, scaleX: false, scaleMode: { originalHeight: 66 } }), 
			new Effect.Opacity("bannerPagerBck", { sync: true, from: 0, to: 1 })
		], { 
		duration: 0.5,
		delay: 0.35
	});
	new Effect.Opacity("pagerContainer", { from: 0, to: 1, duration: 0.5, delay: 0.8, afterFinish: function() { showBigBanner(0); } });	
}

var itemContainer1Pos = 0;
var inRotating = false;
function rotateBannerItems(num)
{
	if (!inRotating) {
		inRotating = true;
		itemContainer1Pos += num;
		if (itemContainer1Pos < 0 && parseInt($("bannerItems2").style.left)<0)
		{
			new Effect.Move("bannerItems2", { x: (parseInt($("bannerItems1").style.width) * 2), y: 0, mode: 'relative', duration: 0.0 });
		}
		new Effect.Parallel([
				new Effect.Move("bannerItems1", { sync: true, x: num, y: 0, mode: 'relative' }),
				new Effect.Move("bannerItems2", { sync: true, x: num, y: 0, mode: 'relative' })
			] ,{ 
			duration: 0.5,
			transition: Effect.Transitions.sinoidal,
			afterFinish: function() {
				if (parseInt($("bannerItems2").style.left) == 0 || parseInt($("bannerItems1").style.left) == 0) {
					$("bannerItems2").style.left = (parseInt($("bannerItems2").style.width) * -1) + "px";
					$("bannerItems1").style.left = "0px";
					itemContainer1Pos = 0;
				}
				inRotating = false;
			}
		});
	}
}


var tempNormalURL = "";
var displayedFlashIndex = null;
var overURL = "";
var imgURL = "";
var landingURL = "";
var inMotion = false;

function showBigBanner(flashIndex)
{
	if (displayedFlashIndex != flashIndex && !inMotion)
	{
		inMotion = true;
		// Resets the position of pictures DIV
		if (!isOperaMini())
		{
			if (parseInt($("pictures").style.top) == (parseInt($("pictures").style.height) * -1))
			{
				$("pictures").style.top = "0px";
				$("pictures").setOpacity(0);
			}
		}
		
		if (displayedFlashIndex != null)
		{
			$("bannerItems1").childNodes[displayedFlashIndex].firstChild.src = JSFlashTHMSrc[displayedFlashIndex];
			$("bannerItems2").childNodes[displayedFlashIndex].firstChild.src = JSFlashTHMSrc[displayedFlashIndex];
		}
		$("bannerItems1").childNodes[flashIndex].firstChild.src = JSFlashTHMSrcOver[flashIndex];
		$("bannerItems2").childNodes[flashIndex].firstChild.src = JSFlashTHMSrcOver[flashIndex];
		
		// Queries parameters from arrays
		overURL = JSFlashTHMSrcOver[flashIndex];
		imgURL = JSFlashSrc[flashIndex];
		
		// Sets parameters of big Banner like as image, links and others
		$("picItem").src = imgURL;
		
		// Animates image container 
		if (!isOperaMini())
		{
			new Effect.Parallel([
				new Effect.Move("pictures", { sync: true, x: 0, y: (parseInt($("pictures").style.height) * -1), mode: 'relative' }),
				new Effect.Opacity("pictures", { sync: true, from: 0, to: 1 }), 
				], { 
					transition: Effect.Transitions.sinoidal,
					duration: 0.8,
					afterFinish: function()
					{
						$("bckpictures").setOpacity(100);
						$("picItemBck").src = $("picItem").src;
						inMotion = false;
					}
			});
		}
		else
		{
			$("pictures").style.top = (parseInt($("pictures").style.height) * -1) + "px";
			inMotion = false;
		}
		displayedFlashIndex = flashIndex;
	}
}

function navigateURL()
{
	window.location = JSFlashLandingURL[displayedFlashIndex];
}

function buildBannerTHM()
{
	var containerWidth = (174 + 32) * JSFlashSrc.length;
	var pagerContainer1 = Builder.node('div', { id: 'bannerItems1', style: 'width: ' + containerWidth + 'px;' });
	var pagerContainer2 = Builder.node('div', { id: 'bannerItems2', style: 'width: ' + containerWidth + 'px; position: relative; top: -54px; left: ' + ( containerWidth * -1 ) + ';' });
	var maxTHMNum = JSFlashTHMSrc.length;
	if (isOperaMini())
	{
		// maxTHMNum = 4;
	}

	for (var i = 0; i < maxTHMNum; i++)
	{
		if (isOperaMini())
		{
			var pagerItem1 = Builder.node('div', { className:'pagerItem', onclick:'showBigBanner(' + i + ');' }, [
				Builder.node('img', { alt: '', src: JSFlashTHMSrc[i] })
			]);
			$(pagerContainer1).appendChild(pagerItem1);
			
			var pagerItem2 = Builder.node('div', { className:'pagerItem', onclick:'showBigBanner(' + i + ');' }, [
				Builder.node('img', { alt: '', src: JSFlashTHMSrc[i] })
			]);
			$(pagerContainer2).appendChild(pagerItem2);
		}
		else
		{
			var pagerItem1 = Builder.node('div', { className:'pagerItem', onMouseOver:'this.className="pagerItemOver";showBigBanner(' + i + ');', onMouseOut:'this.className="pagerItem"' }, [
				Builder.node('img', { alt: '', src: JSFlashTHMSrc[i] })
			]);
			$(pagerContainer1).appendChild(pagerItem1);
			
			var pagerItem2 = Builder.node('div', { className:'pagerItem', onMouseOver:'this.className=\'pagerItemOver\';showBigBanner('+i+');', onMouseOut:'this.className=\'pagerItem\'' }, [
				Builder.node('img', { alt: '', src: JSFlashTHMSrc[i] })
			]);
			$(pagerContainer2).appendChild(pagerItem2);
		}
	}

	$("pagerItemContainer").appendChild(pagerContainer1);
	$("pagerItemContainer").appendChild(pagerContainer2);
}

function showDateString(inputdateStr)
{
	return inputdateStr.split("T")[0];
}
