/****************************************************

	FUNCTIONS WEB SPORTSMARK
	Init 9-2007
	Last Update 1-2008
	
	Author: Daniel Segovia
	Company: SYNAPSIS DIGITAL 
			 www.synapsisdigital.com

*****************************************************/

<!-- Coments for explorers under 4 versions

/*####################################################################

	Functions for DIV Objects

#####################################################################*/

	/*-----------------------------------------------
		Function to determinate visibility on a div
	-----------------------------------------------*/

	var lastId;
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block'){
          e.style.display = 'none';
		  if(lastId!=undefined) lastId.style.display = 'none';
       }else{
	     e.style.display = 'block';
         if(lastId!=undefined){
			 if(lastId==e){lastId.style.display = 'block';}
			 else{lastId.style.display = 'none';}
		 }
	   }
	
	lastId=e;
    scrolea();
    }

	/*-----------------------------------------------
		Function to change an style in div
	-----------------------------------------------*/
	
	var lastId2;
	var classN1;
	var classN2;
  
    function toggle_style(id) {
       var x = document.getElementById(id);
       if(x.className == classN2){
          x.className = classN1;
		  if(lastId2!=undefined) lastId2.className = classN1;
       }else{
	     x.className = classN2;
         if(lastId2!=undefined){ 
		 	if(lastId2==x){lastId2.className = classN2;}
			else{lastId2.className = classN1;}
		 }
	   }
	lastId2=x;
    }
	
	/*-----------------------------------------------
		Function to change status on a DIV
	-----------------------------------------------*/
	stateDiv='close'
	function showAllDiv(arrDiv,arrDivStyle){
		for(i=0;i<arrDiv.length;i++){
			e = document.getElementById(arrDiv[i]);
			x = document.getElementById(arrDivStyle[i]);
			
			if(stateDiv=='close'){
					e.style.display = 'block';
					x.className=classN2;
			}else{
					e.style.display = 'none';
					x.className=classN1;
			}
		}
		if(stateDiv=='close')stateDiv='open';
		else stateDiv='close';
		
		scrolea();
	}
	
	/*-----------------------------------------------
		Function to determinate visibility on a div
	-----------------------------------------------*/

	var lastIdMG;
    function map_google(id,cuanto) {
       var e = document.getElementById(id);
       if(e.style.display == 'block'){
		  b=getScrollXY()[1];
		  window.scrollTo(0,b-cuanto);
          e.style.display = 'none';
		  if(lastIdMG!=undefined) lastIdMG.style.display = 'none';
       }else{
	     e.style.display = 'block';
	 	 b=getScrollXY()[1];
		 window.scrollTo(0,b+cuanto);
         if(lastIdMG!=undefined){
			 if(lastIdMG==e){lastIdMG.style.display = 'block';}
			 else{lastIdMG.style.display = 'none';}
		 }
	   }
	lastIdMG=e;
    }
	
	
/*####################################################################

	Functions for SCROLL Object

#####################################################################*/

	
	/*-----------------------------------------------
		Function to determinate windows dimension
	-----------------------------------------------*/
	
	function windimension(){
		if(window.innerHeight !==undefined)A= [window.innerWidth,window.innerHeight]; // most browsers
		else{ // IE varieties
		var D= (document.body.clientWidth)? document.body: document.documentElement;
		A= [D.clientWidth,D.clientHeight]; 
		}
		return A;
	}  
	/*-----------------------------------------------
		Function that return de X Y position of
		window scroll
	-----------------------------------------------*/
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	} 
	/*-----------------------------------------------
		Function to scoll down window with animation
	-----------------------------------------------*/
	var b=0;
	var currentpos=0
	var speed=25
	function scrolea(){
		currentpos=getScrollXY()[1] + speed;
		var dimensions = windimension();
		abajo=dimensions[1]
		b+=currentpos;
		window.scrollTo(0,b);
		a=setTimeout("scrolea()",50);
		if(b>=abajo){clearInterval(a);b=0}
	}
//-->

/*####################################################################

	Functions for Images Rollover

#####################################################################*/


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



/*####################################################################

	Functions for Flash

#####################################################################*/

function startVideo(){
	var myFlashM = document.getElementById("mymovie");
	if(myFlashM){
		myFlashM.ponVideos();
	}
}


/*####################################################################

	Functions for newsletter

#####################################################################*/

function send_newsletter(){
	var email=document.getElementById("newsletter_email");
	var passThis="newsletter_email="+email.value;
	recibeid("php/sendnewsletter.php","",passThis,"data_form");

}

function objetus(file) {
    xmlhttp=false;
    this.AjaxFailedAlert = "Please, setup your JavaScript configuration.\n";
    this.requestFile = file;
    this.encodeURIString = true;
    this.execute = false;
    if (window.XMLHttpRequest) { 
        this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType) {
            this.xmlhttp.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            this.xmlhttp = new XMLHttpRequest();
            if (!this.xmlhttp){
                this.failed = true; 
            }
        } 
    }
    return this.xmlhttp ;
}
function recibeid(_pagina,valorget,valorpost,capa){ 
    ajax=objetus(_pagina);
    if(valorpost!=""){
        ajax.open("POST", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    } else {
        ajax.open("GET", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);
    }
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1){
            document.getElementById(capa).innerHTML ="Please wait..";
        }
        if (ajax.readyState==4) {
            if(ajax.status==200) {
					//alert(ajax.responseText)
					document.getElementById(capa).innerHTML = "Thank you for your interest in SportsMark";
			}
            else if(ajax.status==404)
            {
                capa.innerHTML = ""; //The URL dosn't exist;
            }
            else
            {
                capa.innerHTML = "Error: ".ajax.status;
            }
        }
    }
    if(valorpost!=""){
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajax.send(valorpost);
    } else {
        ajax.send(null);
    }
} 


