BROWSER = new Object();
BROWSER.isOpera = navigator.userAgent.indexOf("Opera") > -1;
BROWSER.isIE    = navigator.userAgent.indexOf("MSIE") > 1 && !BROWSER.isOpera;
BROWSER.isIE6   = navigator.userAgent.indexOf("MSIE 6") > 1 && !BROWSER.isOpera; 
BROWSER.isMoz   = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !BROWSER.isOpera;

if (typeof($) != "function") $ = function(ID){ return document.getElementById(ID); }

function redirect(id) {
   alert("This link works only in front-end site!")
}

function popupimg(img) {
    var d = new Date()
    var ID = d.getDate()+""+d.getMonth()+1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();

    var loc = "/enlarge.php?src="+img;
	var win = window.open(loc, "_new"+ID,"toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=200,height=200");
	win.location.href = loc;
	win.focus();
}

/* highlist elements onmouse over event
 */
function highlight(groupElements, classOver) {
   var i, j, Obj, groupObjects = [];
   for(j=1; j<100; j++) {
   	   for(i in groupElements) {
   	   	   Obj = $(groupElements[i]+j);
           if (Obj) {
               Obj.ind = j;
               groupObjects[groupObjects.length] = Obj;
           }
       }
   }
   
   for(i in groupObjects) {
      Obj = groupObjects[i];
      Obj.classDefault = Obj.className;
      Obj.classOver = classOver;
      Obj.groupObjects = groupObjects;
      
      Obj.onmouseover = function() {
      	  this.className = this.classOver;
      	  for(var i in this.groupObjects){
      	      var Obj = this.groupObjects[i]; 
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classOver;
      	  }
      }
      Obj.onmouseout = function() {
      	  this.className = this.classDefault;
      	  for(var i in this.groupObjects){
      	  	  var Obj = this.groupObjects[i];
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classDefault;
      	  }
      }
   }
}

function openLink(link) {
   location.href = link;
}

function changeCategory(E, path){
    location.href = path + "?cat_id=" + E.value;
}

function showLogin(rURL) {
    //alert("Please first login to see more");
    document.forms["loginForm"].redirectURL.value = rURL;
    scrollTo(0,0);
    setMaskSize(); 
}

function showGuests(eventID, langID){
    var Obj = document.getElementById('confirmedGuests');
    Obj.innerHTML = '<font color="green">Loading...</font>';
    $('#confirmedGuests').load('/event_guests.php?event_id='+eventID+'&lang_id='+langID);
}

function setEventStatus(eventID, userID, statusID, langID){
    $('#confirmedGuests').load('/event_guests.php?event_id='+eventID+'&user_id='+userID+'&status_id='+statusID+'&lang_id='+langID);
    return true;
}

function setLabel(objID, passDiv) {
    var Obj = document.getElementById(objID);
    if (!Obj) return;
    Obj.defaultText = Obj.value;
    Obj.onclick = Obj.onfocus = function(){
        if (this.value == Obj.defaultText) this.value = "";
        if (this.divObj) {
            this.divObj.style.display = "none";
        }
    }
    
    Obj.onblur = function(){
        if (this.value.match(/^\s*$/)) {
            this.value = this.defaultText;
            if (this.divObj){
                this.divObj.style.display = "inline";
            }
        }
    }
    
    if (passDiv) {
        var divObj = document.getElementById(passDiv);
        divObj.inputObj = Obj;
        Obj.divObj = divObj;
        divObj.onclick = function() {
           this.style.display = "none";
           this.inputObj.focus();
        }
        Obj.onfocus = function(){ 
           Obj.divObj.style.display = "none";
        }
    }
}

function addToFolder(pageHash, pageTitle){
    $('#folderInfo').load('/folder_items.php?addItem='+pageHash+'&title='+encodeURIComponent(pageTitle));
    var Obj = document.getElementById("folderLink");
    if (Obj) Obj.parentNode.removeChild(Obj);
}


// Show shadow mask
function setMaskSize() {
   gPopupMask = document.getElementById("popupMask");
   var MaskObj = document.getElementById("Mask");

   if (!gPopupMask) {
       var popMask = document.createElement('div');
       popMask.id = "popupMask";
       popMask = MaskObj.appendChild(popMask);
       popMask.style.display = "none";
       popMask.style.position = "absolute";
       popMask.style.top = "0px";
       popMask.style.left = "0px";
       popMask.style.zIndex = 20;
       if (BROWSER.isIE6) hideObjects();
       popMask.onclick = function(E) {
          this.style.display = "none";
          var box = document.getElementById('loginBox');
          box.style.zIndex = 50;
          setLabel('auth_user'); setLabel('auth_pass','flyPassword');
          if (BROWSER.isIE6) displayObjects();
       }
       gPopupMask = document.getElementById("popupMask");
   }
   
   gPopupMask.style.display = "block";
   var box = document.getElementById('loginBox');
   box.style.zIndex = 50;
   setLabel('auth_user'); setLabel('auth_pass','flyPassword');
   document.forms["loginForm"].auth_user.focus();

   var fullHeight = getViewportHeight();
   var fullWidth = getViewportWidth();

   if (BROWSER.isIE6){
     // Determine what's bigger, scrollHeight or fullHeight / width
     popHeight = (fullHeight > document.documentElement.scrollHeight ? fullHeight : document.documentElement.scrollHeight);
     popWidth = (fullWidth > document.documentElement.scrollWidth ? fullWidth : document.documentElement.scrollWidth);

     gPopupMask.style.height = popHeight + "px";
     gPopupMask.style.width = popWidth + "px";
     window.onresize = function(){
       var fullWidth = getViewportWidth();
       gPopupMask.style.width = (fullWidth > document.documentElement.scrollWidth ? fullWidth : document.documentElement.scrollWidth) + "px"; 
     }
   }

}

function getViewportHeight() {
    if (window.innerHeight!=window.undefined) return window.innerHeight;
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
    if (document.body) return document.body.clientHeight; 

    return window.undefined; 
}
function getViewportWidth() {
    var offset = 17;
    var width = null;
    if (window.innerWidth!=window.undefined) return window.innerWidth; 
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
    if (document.body) return document.body.clientWidth; 
}

function hideObjects() {
   var x = document.getElementsByTagName("SELECT");
   var level = 10;
   for (i=0;x && i < x.length; i++) {
      x[i].style.visibility = "hidden";
   }
   x = document.getElementsByTagName("OBJECT");
   for (i=0;x && i < x.length; i++) {
      x[i].style.visibility = "hidden";
   }
}

function displayObjects() {
   var x = document.getElementsByTagName("SELECT");
   for(i=0;x && i < x.length; i++){
      x[i].style.visibility = "visible";
   }
   x = document.getElementsByTagName("OBJECT");
   for(i=0;x && i < x.length; i++){
      x[i].style.visibility = "visible";
   }
}

function openGoogleMap(loc, winName, winWidth, winHeight, winParams){
   var wName = window.open(loc, winName, "width="+winWidth+",height="+winHeight+","+winParams);
   wName.location.href = loc;
   wName.focus();
} 

function createVideo(videoID, videoFile){
    var so = new SWFObject("/flash/mediaplayer.swf?file="+videoFile, "mymovie", "352", "288", "8");
    so.addParam("allowfullscreen","true");
    so.addParam("bgcolor","#557722");
    so.addVariable('linkfromdisplay','true');
    so.addVariable('lightcolor','0x557722');
    so.addVariable('searchbar','false');
    so.addVariable('shuffle','true');
    so.addVariable('overstretch','true');
    so.addVariable("width","352");
    so.addVariable("height","288");
    so.addVariable("autostart", true); 
    so.addVariable("controlbar", "bottom");
    so.addParam("wmode", "transparent");
    so.write("video_clip"+videoID);
}