

 $(document).ready(function(){
 
 
 //var fotos = document.getElementById('fotos');
 
 //if(fotos){
	 	$('.fotoss a').lightBox(); 
	//}

});


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	var anchorsform = document.getElementsByTagName("form");
	
	
for (var i=0; i < anchors.length; i++) 
{
	if (anchors[i].getAttribute("href") &&

	anchors[i].getAttribute("rel") == "external") 
	{
		anchors[i].target = "_blank";
	}
}


for (var i=0; i < anchorsform.length; i++) 
{
	if (anchorsform[i].getAttribute("action") &&

	anchorsform[i].getAttribute("id") == "regform") 
	{
		anchorsform[i].target = "reg";
	}
}


}
window.onload = externalLinks;


  function open_win(_url, _name, x, y, dx, dy)   {
        window.open(_url, _name, "screenX="+x+",screenY="+y+",width="+dx+",height="+dy+",status=no,toolbar=no,menubar=no,scrollbars=yes");
      }
	  
function open_win2(_url, _name, x, y, dx, dy)   {
        window.open(_url, _name, "screenX="+x+",screenY="+y+",width="+dx+",height="+dy+",status=no,toolbar=no,menubar=no");
      }

	  
function Reg() {
 window.open("/mms/action.php","reg","scrollbars=no,status=no,resizable=no,toolbar=no,directories=no,menubar=no,width=500,height=300");
 return false;
 }

 function Entra() {
 document.getElementById("UMAIL").value=document.getElementById("uumail").value;
 return false;
 }

function hideLogin() {
	if(document.getElementById('login')) document.getElementById('login').style.display = 'none';
    document.getElementById('grid').style.display = 'none';
	return false;
    }

	


function slide() {
var b1=document.getElementById('rb1');
var b2=document.getElementById('rb2');

if(b1!=null && b2!=null){

	if(load_slide>2)load_slide=1;
	
var bn=document.getElementById('rb'+load_slide);
	
	  b1.style.display="none";
	  b2.style.display="none";
	  bn.style.display="";
	 load_slide++;
	 }
}

var load_slide = 1;
setInterval("slide()", 10000);


	
	
	
	
	
	
function showLogin()
   {
	document.getElementById('login').style.display = 'block';
	document.getElementById('system_login').focus();
	document.getElementById('grid').style.display = '';
    return false;
  }
  
  
  function hideLogin2()
    {
	if(document.getElementById('frend')) document.getElementById('frend').style.display = 'none';
    document.getElementById('grid').style.display = 'none';
	return false;
    }

function showLogin2()
   {
	document.getElementById('frend').style.display = 'block';
	document.getElementById('frend_mail').focus();
	document.getElementById('grid').style.display = '';
    return false;
  }
  
  
  
function _v(id) {
    return document.getElementById(id);
}
function SignIn(err_id, wait_id, login, pass) 
{
    _v( err_id ).style.display  = 'none';
	_v( wait_id ).style.display = 'block';
	
    var req = new JsHttpRequest();
	
    req.onreadystatechange = function() 
	 {
        if (req.readyState == 4) 
		 {
            
            if (req.responseJS.q) 
			  {
				if (1 == req.responseJS.q) 
				  {
                    //redirect to profile
					   document.location='/';
					
                }
                else 
				{
                    if (req.responseJS.eq) 
					{
                        _v( err_id ).style.display = 'block';
                        _v( err_id ).innerHTML = req.responseJS.eq;
                    }
                }
		
				_v( wait_id ).style.display = 'none';
            }
        }
    }
    
    req.open(null,'/mms/cbl.php', true);
    req.send( { action: "login", login: login, pass: pass} );  
}





function frendIn(err_id, wait_id, fmail, fname,fsname,fmessage) 
{
    _v( err_id ).style.display  = 'none';
	_v( wait_id ).style.display = 'block';
	
    var req = new JsHttpRequest();
	
    req.onreadystatechange = function() 
	 {
        if (req.readyState == 4) 
		 {
            
            if (req.responseJS.q) 
			  {
				if (1 == req.responseJS.q) 
				  {
                    _v("frend_mail").value="";
					_v("frend_name").value="";
					_v("frend_sname").value="";
					_v("frend_message").value="";
					//redirect to profile
					//   document.location='/';
					_v( err_id ).style.display = 'block';
					_v( err_id ).innerHTML = req.responseJS.eq;
                }
                else 
				{
                    if (req.responseJS.eq) 
					{
                        _v( err_id ).style.display = 'block';
                        _v( err_id ).innerHTML = req.responseJS.eq;
                    }
                }
		
				_v( wait_id ).style.display = 'none';
            }
        }
    }
    
    req.open(null,'/mms/invite.php', true);
    req.send( { action: "invite", fmail:fmail, fname:fname,fsname:fsname,fmessage:fmessage} );  
}



  // Function is called when we need to calculate MD5.
    function bspec_show_shop(sid) {
        JsHttpRequest.query(
            '/mms/cbl.php', // backend
            {
                // pass a text value 
                'rsid': sid
            },
            // Function is called when an answer arrives. 
			
            function(result, errors) {
                // Write errors to the debug div.
                // document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
                    document.getElementById("bspec").innerHTML =  result["rsid"] ;
                }
            },
            false  // do not disable caching
        );
    }
	
	
	   // Function is called when we need to calculate MD5.
    function bspec_show_tc(sid) {
        JsHttpRequest.query(
            '/mms/cbl.php', // backend
            {
                // pass a text value 
                'trsid': sid
            },
            // Function is called when an answer arrives. 
			
            function(result, errors) {
                // Write errors to the debug div.
                // document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
                    document.getElementById("bspec").innerHTML =  result["trsid"] ;
                }
            },
            false  // do not disable caching
        );
    }
	


  function objser(sid) {
  
  
  	
        JsHttpRequest.query(
            '/mms/objser.php', // backend
            {
                // pass a text value 
                'rsid': sid
            },
            // Function is called when an answer arrives. 
			
            function(result, errors) {
                // Write errors to the debug div.
                // document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
                    document.getElementById("result").innerHTML =  result["rsid"] ;
                }
            },
            false  // do not disable caching
        );
    }
	
	  function objser2(sid) {
  
  
  	
        JsHttpRequest.query(
            '/mms/objser.php', // backend
            {
                // pass a text value 
                'rsid': sid,
				'admin': 1,
				
            },
            // Function is called when an answer arrives. 
			
            function(result, errors) {
                // Write errors to the debug div.
                // document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
                    document.getElementById("result").innerHTML =  result["rsid"] ;
                }
            },
            false  // do not disable caching
        );
    }

	


////////////////////////////////


function showElement(e, x, y)
{
	var x, y;
	
	var $wnd = $(e)
	var $body = $('body')
	
	var w = $wnd.outerWidth()
	var h = $wnd.outerHeight()

	var sz = getPageSize();
	var sw = sz[2]
	var sh = sz[3]

	var sx = $(window).scrollLeft()
	var sy = $(window).scrollTop()

	if (typeof(x) == 'undefined' || x == 'center'){
  	x = (sw - w)/2 + sx
	}

	if (typeof(y) == 'undefined' || y == 'center'){
  	y = (sh - h)/2 + sy
	}

	$wnd.css('left', x)
	$wnd.css('top', y)

	$wnd.animate({'opacity':'show'}, 150);
}

function hideElement(e, speed)
{
	var $wnd = $(e)
	$wnd.animate({'opacity':'hide'}, (hideElement.arguments.length>1)?speed:150);
}

function messageBox(message, onok)
{
	var Window = document.getElementById('messageBox')
	//var $content = $(Window).find('.textcontaner:first')
	//$content.html(message)

	showElement(Window, "center")

	
	var grid = document.getElementById('grid')

	if (grid){
		var sz = getPageSize()
		$(grid).width(sz[0]-17)
		$(grid).height(sz[1])
	
		showElement(grid, 0, 0)
	}

	$(Window).unbind()
	if (onok) $(Window).click(onok)

	return false;
}
  
function messageBoxHide()
{
	var login = document.getElementById('messageBox')
	hideElement(login)

	var grid = document.getElementById('grid')
	if (grid) hideElement(grid)

	return false;
}

  
/* My Utils */

function  getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}



function confirm_interface(spec,adr) 
{
   var EditFieldHeader=adr;
	
  if (confirm(EditFieldHeader)) 
    {
		
		$('#buycont').load('/mms/buy.php?bykupon='+spec, 
		function() {  
		
		   return true;
		
		 });
		
		//alert('ok');
    
	}   
  else  
    {
	//alert('no');
     return false;
	}
}

