﻿//------: INI VARIABLES
var allbgs = new Number();

//------: CHECK BROWSER
var version = "";
var browser ="";
var isIE6 = false;

function getBrowser() {	
	if (navigator.appVersion.indexOf("MSIE")>0){
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);  
		browser = "MSIE";
	} else {
		browser = "not MSIE"
	}
}
getBrowser();

if(browser=="MSIE"){
	if(version<7){
		isIE6 = true;
	}
}

//------: EVENTS
window.onload = setBgAreaSize;

window.onresize = function(){
	setBgAreaSize();
}
window.onscroll = setAnastimaSize;


//------: SET HTML ELEMENTS SIZE

function checkSize(){
	var uniwin = {
		width: window.innerWidth || document.documentElement.clientWidth
			|| document.body.offsetWidth,
		height: window.innerHeight || document.documentElement.clientHeight
			|| document.body.offsetHeight
	};
	return uniwin
}
function setAnastimaSize() {
	if ($('#Anastima').length) {
		var flashMovie = getFlashMovieObject("AnastimaFlash");
		var Y = $('#Anastima').offset().top;
		var theDocSize = checkSize();
		HSize = theDocSize.height;
		var scrlPos = $(window).scrollTop()
		var dif = HSize - Y;
		if (dif > 0) {
			if (flashMovie) {
				flashMovie.style.height = dif + scrlPos + "px";
			} else {
				//window.setTimeout("flashMovie.style.height = dif + scrlPos + 'px';", 500);
			}
		}
	}
}

function setBgAreaSize(){
	var theDocSize = checkSize();
	HSize = theDocSize.height;
	WSize = theDocSize.width;


	var mainAreaTop = $(".mainArea").offset().top;

	var mainAreaHeight = $(".mainArea").outerHeight();

	var footerHeight = $(".footer").outerHeight();

	if(mainAreaTop + mainAreaHeight + footerHeight < HSize){
		$(".mainArea").css('height',HSize - mainAreaTop - footerHeight - 2 +'px');
	}


	setAnastimaSize();

	if($("#bgWrapper").length>0 && $("#allContents").length>0){		
		
		var bAnchor = $('#Anchor').offset();
		var setHeight;
		
		if(bAnchor.top>HSize){
			setHeight = bAnchor.top + 1;
		} else {
			setHeight = HSize;
		}		
		
		$("#bgWrapper").css('height',setHeight+'px');
		
		$("#bgMover").css('width',WSize * allbgs + 'px');
		
		$("#bgWrapper div.bgs").css('height',setHeight+'px');
		$("#bgWrapper div.bgs").css('width',WSize+'px');		
		
		//if content < HSize then
		$("#allContents").css('height',setHeight+'px');
	}
}

function setBg(num){	
  $('#bgMover').animate({
	left: -WSize * (num - 1),
	easing:'linear'
  }, 1000, function() {
	// Animation complete.
  });

	
}



/*-- ALL MENU SCRIPTS: START --*/
var isout=true;
var defaultMenu;
var t;
function showHide(thisItem, MenuWrapper, str){	
	hideAll(MenuWrapper);
	
	$("." + MenuWrapper).show();
	
	if(thisItem.className==""){
		thisItem.className = "active";	
	} else {
		thisItem.className += " active";	
	}
	if(str){
		$("#"+ str).show();
		hideSelect();
	} else {
		$("." + MenuWrapper).hide();
	}
}
function timersetMenuDefault(num) {	
	if(num==null)
		num = 1500;
	
    clearTimeout(t);
    t = setTimeout("if (isout){hideAll();}", num);
}
function hideAll(MenuWrapper){
	$(".SubMenuWrapper").hide();
	$(".SubMenu").hide();
	$(".active").toggleClass("active","");
	showSelect();
	clearTimeout(t);
}
function hideSelect() {
	if(isIE6)
		$("select").css("visibility","hidden");
}
function showSelect() {
    if(isIE6)
		$("select").css("visibility","visible");
}

/*-- ALL MENU SCRIPTS: END --*/


//------: GENERAL FUNCTIONS
function switchTab(obj, tabclass, tabtoShow, aSelectedName){
	$('.'+ tabclass).hide(); 
	$('#' + tabtoShow).show();	
	$('.'+ aSelectedName).toggleClass(aSelectedName,"");
	obj.className = aSelectedName;
}

function ChangeInput(obj, dValue, setValue){
	if(obj.value==dValue)
		obj.value = setValue;
}

function showObj(ojbStr){
	$('#' + ojbStr).show();
}
function hideObj(ojbStr){
	$('#' + ojbStr).hide();
}


function showCalEvent(obj) {
	var pop = $("#PopUp").detach();
	pop.appendTo("#PopupContainer123");
	pop.css("z-index", "10000");
	pop.show();
	showObj(obj);
	var height = pop.height();
	var offset = $("#PopUpAnchorUnder").offset();
	if ($(document).height() - ($("#PopUpAnchorUnder").offset().top + height+3) > 0) {
		pop.css({ top: ($("#PopUpAnchorUnder").offset().top+3)+ "px", left: $("#PopUpAnchorUnder").offset().left + "px" });
	}
	else {
		pop.css({ top: ($("#PopUpAnchorOver").offset().top - height-3) + "px", left: $("#PopUpAnchorUnder").offset().left + "px" });
	}
}
function hideCalEvent(obj) {
	var pop = $("#PopUp").detach();
	pop.appendTo("#PopUpAnchorUnder");
	pop.css("z-index", "10000");
	pop.hide();
	hideObj(obj);
}

function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else{
		return document.getElementById(movieName);
	}
}


function doPopup(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs){
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1){
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	window.open(theURL, theWinName, paramstr);
}
function EnlargeImage(theImg, theAlt){
	theURL = "../Assets/EnlargeImage.asp?theImg=" + theImg + "&theAlt=" + theAlt
	theWidth = 400;
	theHeight = 400;
	theLeft = (screen.width - theWidth) / 2;
	theTop = (screen.height - theHeight) / 2;
	window.open(theURL, 'enlarge', "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=yes,scrollbars=no,statusbar=no,menubar=no,personalbar=no,toolbar=no,locationbar=no,directories=no");
}
function alertModal(theMessage,isError, wdt, hgt, pageRequested){
	var myObject = new Object();
	var lft, tp;
	lft = (screen.width - wdt) / 2;
	tp = (screen.height - hgt) / 2;
	myObject.bodys = theMessage;

	if (isError=="ERROR"){
		win = window.showModalDialog("assets/modalError.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:"+ hgt +"px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0;status:0;scroll:0;resizable:0");
	}
	else if (isError=="TERMS"){
		win = window.showModalDialog("assets/modalTerms.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:"+ hgt +"px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0; status:0 ");
	}
	else{
		win = window.showModalDialog("assets/modalInfo.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:" + hgt + "px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0; status:0 ");
	}
}


var nsstyle='display:""'
if (document.layers)
var scrolldoc=document.scroll1.document.scroll2

function up(){
	if (!document.layers) return
	if (scrolldoc.top<0)
	scrolldoc.top+=10
	temp2=setTimeout("up()",50)
}

function down(){
	if (!document.layers) return
	if (scrolldoc.top-150>=scrolldoc.document.height*-1)
	scrolldoc.top-=10
	temp=setTimeout("down()",50)
}

function clearup(){
	if (window.temp2)
	clearInterval(temp2)
}

function cleardown(){
	if (window.temp)
	clearInterval(temp)
}

function goToPage(thePage, showPageFrom, showPageTo, listPage){
	if (eval(thePage) > eval(showPageTo)){
		document.forms.mainForm.iBlockCurrent.value = eval(document.forms.mainForm.iBlockCurrent.value) + 1
	}
	if (eval(thePage) < eval(showPageFrom)){
		document.forms.mainForm.iBlockCurrent.value = eval(document.forms.mainForm.iBlockCurrent.value) - 1
	}
	document.forms.mainForm.action = listPage;
	document.forms.mainForm.iPageCurrent.value = thePage;
	document.forms.mainForm.submit();
}

function goToBlock(theBlock, thePage, listPage){
	document.forms.mainForm.action = listPage;
	document.forms.mainForm.iPageCurrent.value = thePage;
	document.forms.mainForm.iBlockCurrent.value = theBlock;
	document.forms.mainForm.submit();
}

function goToView(theArea, theRecord){
	document.forms.mainForm.action = theArea + "&a=" + theRecord;
	document.forms.mainForm.submit();
}


function goToBack(theArea){
	document.forms.mainForm.action = theArea;
	document.forms.mainForm.submit();
}

function changeSorting(newSorting, theArea){
	document.forms.mainForm.sorting.value = newSorting;
	document.forms.mainForm.action = theArea;
	document.forms.mainForm.submit();
}

function isDate(strDate,DateFormat){
	 DateFormat=DateFormat.toLowerCase()

	 if (DateFormat=='dd/mm/yyyy'){var DatePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;}
	 else if (DateFormat=='mm/dd/yyyy'){var DatePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;}
	 else if (DateFormat=='yyyy/mm/dd'){var DatePattern = /^(\d{2}|\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/;}

	 var matchArray = strDate.match(DatePattern);
	 if (matchArray == null) return false;

	 if (DateFormat=='dd/mm/yyyy'){var day = matchArray[1];var month = matchArray[3];var year = matchArray[4];}
	 else if (DateFormat=='mm/dd/yyyy'){var day = matchArray[3];var month = matchArray[1];var year = matchArray[4];}
	 else if (DateFormat=='yyyy/mm/dd'){var day = matchArray[4];var month = matchArray[3];var year = matchArray[1];}
	 else{return false;}

	 if (month < 1 || month > 12) return false;
	 if (day < 1 || day > 31) return false;
	 if (year < 1900) return false;
	 if ((month == 4 || month == 6 || month==9 || month == 11) && day == 31) return false;
	 if (day>=29 && month == 2 && parseInt(year) % 4 !== 0) {return false;}
	 if (day>=30 && month == 2 && parseInt(year) % 4 == 0) {return false;}
	 return true;
}

function isInteger(theData){ return (theData.search(/^\d+$/) != -1); }

function isEmpty(s){ return ((s == null) || (s.length == 0) || s=="");}

function isMail(sString){
	var emailEXP = /^[a-z_0-9\.]+@[a-z_0-9\-\_\.]+\.[a-z]{2,3}$/i
	if (!sString.match(emailEXP)){
		return false;
	}
	else{
		return true;
	}
}

function isDecimal(theData){ return (theData.search(/\d*\.\d+/) != -1); }

function isChecked(theData){
	var len, found
	len = theData.length;
	found = true
	for(var i=0;i<len;i++){
		if (theData[i].checked) found=false;
	}
	return found;
}

function hasMaxLength(theString, theLen){
	if (theString.length > theLen) {
		return false
	}
	else {
		return true
	}
}

function RepositionLayer(ReferenceObject, ObjectToMove, OffsetX, OffsetY){
	var RefObj, MoveObj
	var RefObjLeftPos, RefObjTopPos
	RefObj = document.getElementById(ReferenceObject);
	MoveObj = document.getElementById(ObjectToMove);
	
	RefObjLeftPos = findPosX(RefObj);
	RefObjTopPos = findPosY(RefObj);

	MoveObj.style.left = (RefObjLeftPos + OffsetX);
	MoveObj.style.top = (RefObjTopPos + OffsetY);
	MoveObj.style.visibility = "visible";
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function SwapImage(ImageId,NewSrc){
	document.getElementById(ImageId).src = NewSrc;
}

function ChangeOpacity(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}


function findParentNode(parentName, childObj) {
    var testObj = childObj.parentNode;
    var count = 1;
    while(testObj.getAttribute('name') != parentName) {
        alert('My name is ' + testObj.getAttribute('name') + '. Let\'s try moving up one level to see what we get.');
        testObj = testObj.parentNode;
        count++;
    }
    // now you have the object you are looking for - do something with it
    alert('Finally found ' + testObj.getAttribute('name') + ' after going up ' + count + ' level(s) through the DOM tree');
}


//------: JQUERY FUNCTIONS
function setStyleByClass(cssName, property, value){
	$("."+cssName).css(property,value);
}

function getItemsByClass(cssName){
	var allItems = new Array();
	allItems = $("." + cssName);
	return allItems;
}

function getItemsByClasswithException(cssName, NotcssName){
	var allItems = new Array();
	allItems = $("." + cssName + ":not(." + NotcssName + ")");
	return allItems;
}

function DoPopup(TheURL) {
	DoPopupAdvanced(TheURL, 'oPopup', -1, -1, 700, 600, 'yes', 'yes', 'no', 'no', 'no', 'no', 'no');
}

function DoPopupAdvanced(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs) {
	if (theLeft == -1 && theTop == -1) {
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	newwindow = window.open(theURL, theWinName, paramstr);
	if (window.focus) { newwindow.focus() }
	return false;
}

function ViewImage(TheImg, TheAlt) {
	TheURL = "/Content/Assets/ViewImage.aspx?Img=" + TheImg + "&Alt=" + TheAlt
	DoPopupAdvanced(TheURL, 'oEnlarge', -1, -1, 700, 600, 'yes', 'yes', 'no', 'no', 'no', 'no', 'no');
}

function showHideOptions(elm)
{
	if ($(elm).is(":checked"))  
		$('div[id$="NLCategories"]').show();
	else
		$('div[id$="NLCategories"]').hide();
}


//------: CONTROL FLASH
function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		  return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			return document.embeds[movieName];
		}
	} else {// if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	   return document.getElementById(movieName);
	   
	}
	return document.getElementById(movieName);
}

function StopFlashAutoPlay(){
	var flashMovie = getFlashMovieObject("HomeFlashNews");
	if (flashMovie)
	{
		flashMovie.StopAutoPlay();
	}
}
