function OverSearch(oImg){
   oImg.src="Images/BSearch2.gif";
   oImg.style.cursor = "pointer";
}

function OutSearch(oImg){
   oImg.src="Images/BSearch.gif";
   oImg.style.cursor = "";
}

function ScrollUp(){
}

function ScrollDown(){
}

function ScrollOver(oImg, sColor, sDirection){
	var sImgName;
	sImgName = (sDirection == "Up") ? "Btop" : "Bdown";
	oImg.src="Images/+sColor+/+sImgName+gif";
	oImg.style.cursor = "pointer";
}

function ScrollOut(oImg, sColor, sDirection){
	var sImgName;
	sImgName = (sDirection == "Up") ? "Btop" : "Bdown";
	oImg.src="Images/+sColor+/+sImgName+gif";
	oImg.style.cursor = "";
}

function PollOver(oPoll){
   oPoll.src="Images/PollCheckBox2.gif";
   oPoll.style.cursor = "";
}

function PollOut(oPoll){
   oPoll.src="Images/PollCheckBox.gif";
   oPoll.style.cursor = "";
}

function NewsLetters(){
	var arCheckboxes = document.getElementsByName("chkNewsletter[]");	
	var bAtLeastOneIsChecked = false;	
	for(var i = 0; i < arCheckboxes.length; i++){				
		if(arCheckboxes[i].checked){
			bAtLeastOneIsChecked = true;
			break;
		}
	}
	
	if(!bAtLeastOneIsChecked){
		alert("Моля, посочете желаният от Вас избор за абонамент!");
		return false;
	} 
	return true;		
}

function CheckAll(){
	var arCheckboxes = document.getElementsByName("chkNewsletter[]");	
	var oCheckAll = document.getElementById("checkall");
	for(var i = 0; i < 2; i++){	
		arCheckboxes[i].checked = (oCheckAll.checked == true) ? true : false;
		}
}

function FeedBackForm(oName, oEMail, oAbout, oMessage){
	if (oName.value == "" || oEMail.value == "" || oAbout.value == ""){
		alert("Попълнете коректно полетата!");
		return false;
	}
}

function TellAFriend(oName, oEMail, oReceiver, oMessage){
	if (oName.value == "" || oEMail.value == "" || oReceiver.value == "" || oMessage.value == ""){
		alert("Попълнете коректно полетата!");
		return false;
	}
}

function PollSubmit(oSubmit, nChoice){
	var PollValue = document.getElementById("PollValue");
	PollValue.value = nChoice;
	document.getElementById('ScreenResolution').value = screen.width + "x" + screen.height;
	oSubmit.submit();
	return false;
}

function ShowMultimediaPopUp(nRecordID){
	WinOpen("?Action=24&RecordID="+nRecordID, 700, 505);
	return false;
}

function ShowPhotogalleryPopUp(nRecordID, nGalleryId){
	WinOpen("?Action=32&RecordID="+nRecordID+"&nGalleryId="+nGalleryId, 700, 505);
	return false;
}

function WinOpen(url, width, height, name, top, left, scroll, status, resizable, menubar, fullscreen){
	if(!status) status = 0;
	if(!scroll) scroll = 'no';
	var sName = Math.round(Math.random() * 999999999);	
	if(!name) name = 'WinOpen'+ sName.toString();
	if(!width) width = '600';
	if(!height) height = '450';
	if(!resizable) resizable = 'no';
	if(!menubar) menubar = 'no';
	if(!top) top = (screen.height-height)/2 - 40;
	if(!left) left = (screen.width-width)/2;
	if(!fullscreen) fullscreen = 'yes';
	properties='history=no, toolbar=0, location=0, directories=0, scrollbars='+scroll+', status='+status+', menubar='+menubar+', width='+width+', height='+height+', top='+top+', left='+left+', resizable='+resizable+'';	
	var sLocation = new String(window.location);	
	window.open(url, name, properties);
}

function PrintWindowContent(){
	window.parent.window.document.getElementById('PrintFrame').contentWindow.focus(); 
	window.parent.window.document.getElementById('PrintFrame').contentWindow.print();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ExtendObject(ExtensionObject, Object){
	for (var sVariableName in Object) {
		if(typeof(Object[sVariableName]) == 'string')
			eval("ExtensionObject."+ sVariableName +" = '"+ Object[sVariableName] +"';");
		else
			eval("ExtensionObject."+ sVariableName +" = "+ Object[sVariableName] +";");
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CheckObject(oObject){
	if(oObject != null && typeof(oObject) != "undefined"){
		return true;
	}else{
		return false;
	}
}

function MeasureText(sText, oStyle, nFixedWidth, nFixedHeight){
	if(typeof(window._MeasurementLayer) == 'undefined'){
		window._MeasurementLayer = document.createElement("div");
		window._MeasurementLayer.style.position = "absolute";
		//window._MeasurementLayer.style.backgroundColor = '#FF0000';
		//window._MeasurementLayer.style.color = '#FFFFFF';
		window._MeasurementLayer.style.left = '0px';
		window._MeasurementLayer.style.top = '0px';
		window._MeasurementLayer.style.visibility = "hidden";
		//window._MeasurementLayer.style.fontSize = '1px';
		if(typeof(ExtendObject) == 'undefined')
			alert("ExtendObject required in MeasureText");
		ExtendObject(window._MeasurementLayer.style, oStyle);
		window._MeasurementLayer = document.body.appendChild(window._MeasurementLayer);
	}
	if(nFixedWidth)
		window._MeasurementLayer.style.width = nFixedWidth;	
	else if(nFixedHeight)
		window._MeasurementLayer.style.height = nFixedHeight;	

	window._MeasurementLayer.innerHTML = sText;
	//alert(window._MeasurementLayer.outerHTML);
	return new Array(window._MeasurementLayer.offsetWidth, window._MeasurementLayer.offsetHeight);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Find(sId){
	if (document.all) return document.all[sId];
	if (document.getElementById) return document.getElementById(sId);
	return false;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CreateImage(sSrc, nWidth, nHeight){
	var oImage;
	oImage = document.createElement("img");
	oImage.src = sSrc;
	if(nHeight) oImage.height = nHeight;
	if(nWidth) oImage.width = nWidth;
	return oImage;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PlaceLayers(sParent, sLayer){
	var oParent = Find(sParent);
	var oLayer = Find(sLayer);
	if(!oParent || !sLayer) return;
	var arCoordinates = GetCoordinates(oParent);
	if(oLayer.offsetWidth < oParent.offsetWidth) 
		oLayer.style.width = oParent.offsetWidth;
	oLayer.style.top = arCoordinates[1] + oParent.offsetHeight;
	oLayer.style.left = arCoordinates[0];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetBrowserName(){
	if(navigator.userAgent.toLowerCase().indexOf("opera") != -1){
		return "Opera";
	}else if(navigator.userAgent.toLowerCase().indexOf("gecko") != -1){
		return "Mozilla";
	}else if(navigator.userAgent.toLowerCase().indexOf("msie") != -1){
		return "IE";
	}
}
//////////////////// SEARCH VALIDATOR /////////////////////////////////////////////////////
function ValidateSearch(sText, sErrMessage){
	var oSearchText = document.getElementById("search");
	var sStringText = oSearchText.value;
	if(sStringText.length > 2 && sStringText != sText){
		document.getElementById('SearchForm').submit();
	}else{
		alert(sErrMessage);
		return false;
	}
}
//////////////////// DICTIONARY VALIDATOR /////////////////////////////////////////////////////
function ValidateDictionarySearch(sText, sErrMessage){
	var oSearchText = document.getElementById("txt_DictionarySearchString");
	var sStringText = oSearchText.value;
	if(sStringText.length > 2 && sStringText != sText){
		document.getElementById('DictionaryForm').submit();
	}else{
		alert(sErrMessage);
		return false;
	}
}
//////////////////// CHECK FORM BEFORE SUBMIT /////////////////////////////////////////////////////
function CheckAndSubmit(FormID){
	return (NewsLetters() && CheckSubmit(Find(FormID)));
}

//////////////////// CHECK POLLS FORM BEFORE SUBMIT /////////////////////////////////////////////////////
function PollCheckRadioForm(){
	
	var sRadioButtonValue = oPollRadioGroup.GetSelectedValue();
	var oForm = Find('frmPolls');
	if(sRadioButtonValue == null){
		alert(oForm.EmptyRadioFieldErrorMessage);
	}else{
		oForm.submit();
	}
}

// function GetCoordinates(oElement){
//     var X, Y, oParent;
//     X = oElement.offsetLeft;
//     Y = oElement.offsetTop;
//     oParent = oElement;
//     while(oParent = oParent.offsetParent){
//     if(oParent.style.position == 'absolute' || oParent.style.position == 'relative') break;
//         X += oParent.offsetLeft;
//         Y += oParent.offsetTop;
//     }
//     return new Array(X, Y);
// }

function ClearATags(oCurrentTag){
    //document.getElementById("OnPrintHide").display = "none";
	var oATag = oCurrentTag.getElementsByTagName("a");
	for(var i = 0; i < oATag.length; i++){
		oATag[i].href = "javascript: void(0);";
		oATag[i].onclick = "";
		oATag[i].onmouseover = "";
		oATag[i].style.cursor = "default";
		oATag[i].target = "_self";
	}
	
	var oSelectTag = oCurrentTag.getElementsByTagName("select");
	for(var i = 0; i < oSelectTag.length; i++){
		oSelectTag[i].disabled = "true";
		oSelectTag[i].style.cursor = "default";
	}
	
	var oSpanTag = oCurrentTag.getElementsByTagName("span");
	for(var i = 0; i < oSpanTag.length; i++){
		oSpanTag[i].onclick = "";
		oSpanTag[i].onmouseover = "";
		oSpanTag[i].style.cursor = "default";
		if(oSpanTag[i].name == "OnPrintHide"){
		    oSpanTag[i].style.display = "none";
	    }
	}
	
	var oDivTag = oCurrentTag.getElementsByTagName("div");
	for(var i = 0; i < oDivTag.length; i++){
		oDivTag[i].onclick = "";
		oDivTag[i].onmouseover = "";
		oDivTag[i].style.cursor = "default";
		//oDivTag[i].style.color = "#000000";
	}
	
	var oImgTag = oCurrentTag.getElementsByTagName("img");
	for(var i = 0; i < oImgTag.length; i++){
	    if(oImgTag[i].style.position == "absolute") {
	        oImgTag[i].style.display = "none";
	    }
	    oImgTag[i].onclick = "";
		oImgTag[i].onmouseover = "";
		oImgTag[i].style.cursor = "default";
	}
	
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ChangeFontSize(Element, nSize){
    for(var nCount = 0; nCount < Element.childNodes.length; nCount++)
    {

//        alert(Element.childNodes[nCount].style.fontSize);
        if(Element.childNodes[nCount].innerHTML != undefined)
                Element.childNodes[nCount].style.fontSize= nSize + "px";
        ChangeFontSize(Element.childNodes[nCount], nSize);
    } 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SubmitArchive(sCaller){
    document.getElementById(sCaller);
    
}


var oOpened;
var oOpenedLink;
function ShowHide(Object, sName, bHideOthers){
   // Hide all others
   if(bHideOthers){
	if(oOpened != undefined){
		oOpened.style.display = "none";
		oOpenedLink.style.color = "#304c4f";
	}
      var nCount = 0
		while(true){
            if(document.getElementById(sName + nCount)){
                 if(Object.id != sName + nCount)
                    document.getElementById(sName + nCount).style.display = "none";
            }else{
                break;          
            } 
            nCount++;       
       }
    }
   var Link = document.getElementById(sName + "_Link");
   if(Object.style.display == "none"){
        Object.style.display = "";
        Link.style.color =  "#fe705c";
   }else{
        Object.style.display = "none";
        Link.style.color =  "#fe705c";
   } 

	window.scrollTo(0,400);
	oOpened = Object; 
	oOpenedLink = Link; 
}

function ClearSearchField(sText){
	var oSearch = document.getElementById("search");
	if(oSearch.value == sText)
		oSearch.value = "";
}

function ShowBigger(oImage){
    var sImagePath = oImage.replace('Small', 'Big', oImage);
    WinOpen(BaseSitePath+"/index.php?Action=37&ImagePath="+sImagePath, 840, 700); 
    //WinOpen(oImage, 760, 505); 
}

function GetShadowHeight(nHeight){
    var MainContainerHeight = document.getElementById('MainContent').offsetHeight;
    var LeftShadow = document.getElementById('LeftShadow');
    var RightShadow = document.getElementById('RightShadow');
    if(nHeight == ""){
        if(MainContainerHeight > 600){
            MainContainerHeight += 50;
        }
        LeftShadow.style.height = parseInt(MainContainerHeight - 156)-nHeight;
        RightShadow.style.height = parseInt(MainContainerHeight - 156)-nHeight;
    }else{
        LeftShadow.style.height = parseInt(MainContainerHeight - 156)+parseInt(nHeight);
        RightShadow.style.height = parseInt(MainContainerHeight - 156)+parseInt(nHeight);
    }
}

var button = {};
button.LastItem = null;
function ShowPicture(oPicture, picture, Object){

    if(button.LastItem != null){
        button.LastItem.style.backgroundColor = "#284448";
        button.LastItem.style.color = "#ffffff";
    } 

    if(typeof(Object) != "undefined"){
        Object.style.backgroundColor = "#416267";
        Object.style.color = "#fe705c"; 
        button.LastItem = Object;
    }

    picture.src = oPicture;
}

function ShowHideFeedBackForm(obj){
   nContainerHeight = obj.style.height;
   if(obj.style.display == "none"){
       GetShadowHeight(nContainerHeight);  
       obj.style.display = "";
   }else{
       GetShadowHeight("-"+nContainerHeight); 
       obj.style.display = "none"; 
   }
}

function BackToTop(){
    window.scrollTo(0, 0);
}

function CheckConatainerHeight(){
	var oContentContainerHeight = document.getElementById('MainContent').offsetHeight;
	if(oContentContainerHeight > 700)
		document.getElementById("BackToTop").style.display = "";
		
}
