BROWSER = new Object();
BROWSER.isOpera = navigator.userAgent.indexOf("Opera") > -1;
BROWSER.isIE    = navigator.userAgent.indexOf("MSIE") > 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 showPaypalRedirect(label){
    var E = document.getElementById('paymentForm');
    var R = document.getElementById('redirectMessage');
    if (E && R) {
        E.style.display = "none"
        R.innerHTML = label;
    }
}

function in_array(el, arr) {
    for(var i=0; i<arr.length; i++) if (arr[i] == el) return true;
    for(var i in arr) if (arr[i] == el) return true;
    return false;
}

function checkOtherField(E) {
    var Obj = document.getElementById("reg_prof_other");
    if (E.value == 27) {
        Obj.style.display = "block";
    } else {
        Obj.style.display = "none";
        document.getElementById("reg_prof_input").value = "";
    }
    
}
                               
$(document).ready(function() {    
    var counter = 1;
    $('#AddMoreSendToFriend').click(function(){    
        if(counter >= 10)
            return false;
        $('#SendToFriendsList').append($('#SendToFriendSource').html()); 
        counter++;   
        return false;
    });
    
    $('#SendToFriendButton, #SendToFriendCloseButton').click(function(){  
        if($('#SendToFriend').css('display') == 'none'){
            $('html, body').animate({scrollTop:0}, 'normal');  
            
            $('#SendToFriend input[type=text], #SendToFriend textarea').val('');  
            $('#SendToFriendResultBox').html('');
            $('#SendToFriendCloseButton').show();
            $('#SendToFriendSubmitButton').show(); 
            $('#AddMoreSendToFriend').show(); 
            $('#SendToFriendForm').show();  
            $('#SendToFriend').fadeIn();
        } else {                   
            $('#SendToFriend').fadeOut();                         
        }                           
    });
    
    // Form submition
    $('#SendToFriendSubmitButton').click(function(){
        
        var form = $('#SendToFriendForm');
                                                 
        $('#SendToFriendCloseButton').hide();
        $('#SendToFriendSubmitButton').hide(); 
        $('#AddMoreSendToFriend').hide();
        $('#SendToFriendResultBox').html('Loading...');
        
        $.post("send_to_friend.php", 
                form.serialize(),
                function(data){                  
                    var res = eval('('+data+')');  
                    if(res.status == 0) { 
                        $('#SendToFriendCloseButton').show();
                        $('#SendToFriendSubmitButton').show();  
                        $('#AddMoreSendToFriend').show(); 
                    }else{
                        $('#SendToFriendForm').hide();
                        $('#SendToFriendCloseButton').show();
                    }
                    $('#SendToFriendResultBox').html(res.msg);
                });
        return false;
    });
    
})
