// JavaScript Document

function setVideo(idvideo) {

	var vswf = new SWFObject('flvplayer.swf','player','300','250','7');

	vswf.addParam("allowfullscreen","true");

	vswf.addVariable("type","flv");

	vswf.addVariable("file","http://cache.googlevideo.com/get_video?video_id="+idvideo);

	vswf.addVariable("image","http://img.youtube.com/vi/"+idvideo+"/2.jpg");

	vswf.addVariable("autostart", "true");

	vswf.write('swfvideo');

}

function getId(nameid) {

	return document.getElementById(nameid);

}

function getData() {

	getId('loadData').style.visibility = "visible";

	dsYouTube.setURL(varurl+"?tag="+vartag+"&pag="+varpag);

	dsYouTube.loadData();

}

function setText(varId, varText) {

	getId(varId).innerText = varText;

	getId(varId).textContent = varText;

}

function getVideo() {

	varpag = 1;

	vartag = getId("criterio").value;

	window.location = "search.php?query="+vartag+"&page="+varpag;

}

function download() {

	window.location = "download.php?v="+getId("codigo").value;

}

function pagVideo(pagStep) {

	if (varpag > 1 || pagStep > 0) {

		varpag = Number(varpag) + Number(pagStep);

		window.location = "index.php?query="+vartag+"&page="+varpag;

	}

}
function isIE() {
	return document.all;
}

function showSummary(object, e, text) {
	myLayer = document.getElementById(object);
	myLayer.innerHTML = text;
	
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

    if (e != '') {
        if (isIE()) {
            x = e.clientX;
            y = e.clientY;
            browserX = document.body.offsetWidth + 0;
			x += (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;			// Adjust for scrolling on IE
    		y += (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
        }
        if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
            browserX = window.innerWidth + 0;
        }
    }
	
	x1 = x ;		// Move out of mouse pointer
	y1 = y ;
	
	// Keep box from going off screen
	if (x1 + w > browserX)
		x1 = x - w -20;
    
    myLayer.style.left = parseInt(x1)+ "px";
    myLayer.style.top = parseInt(y1) + "px";
	myLayer.style.visibility = "visible";
}

function moveSummary(object, e) {

	myLayer = document.getElementById(object);
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

    if (e != '') {
        if (isIE()) {
            x = e.clientX;
            y = e.clientY;
			browserX = document.body.offsetWidth -25;
			x += (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;			// Adjust for scrolling on IE
    		y += (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
        }
        if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
			browserX = window.innerWidth - 30;
        }
    }

	x1 = x + 20;	// Move out of mouse pointer	
	y1 = y - 20;
	
	// Keep box from going off screen
	if (x1 + w > browserX)
		x1 = x - w -20;

    myLayer.style.left = parseInt(x1) + "px";
    myLayer.style.top = parseInt(y1) + "px";
}

function hideSummary(object) {
	myLayer = document.getElementById(object);
	myLayer.style.visibility = 'hidden';
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn() {
	var xmlhttp, bComplete = false;
	
	// try to creates an xmlhttp object
	try {
		xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
	} catch ( e ) { 
		try {
			xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
		} catch ( e ) {
  			try {
  				xmlhttp = new XMLHttpRequest();
  			} catch ( e ) { 
  				xmlhttp = false;
  			}
		}
	}
	
	// if the browser does not support ajax return false
	if ( !xmlhttp ) {
		return null;
	}
	
	/**
	 * Connection method of the class
	 * params:
	 * string sUrl
	 * string sMethod : "GET" || "POST"
	 * string sVars ( name of the vars to retrive )
	 * function_pointer fnDone ( function that will be executed when xmlhttp.readyState == 4 )
	 */
	this.connect = function( sURL, sMethod, sVars, fnDone ) {
		if ( !xmlhttp ) {
			return false;
		}
    
		bComplete = false;
   		sMethod = sMethod.toUpperCase();

    	try {
      		if ( sMethod == "GET" ) {
        		xmlhttp.open( sMethod, sURL + "?" + sVars, true );
        		sVars = "";
      		} else {
        		xmlhttp.open( sMethod, sURL, true );
        		xmlhttp.setRequestHeader( "Method", "POST " + sURL + " HTTP/1.1" );
        		xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
      		}
			xmlhttp.onreadystatechange = function() {
				if ( xmlhttp.readyState == 4 && !bComplete ) {
					bComplete = true;
					fnDone( xmlhttp );
        		}
			};
			xmlhttp.send(sVars);
		} catch( z ) {
			return false;
		}
    	
		return true;
	};
	return this;
}
function showVideo(video) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {
		var videoObject=oXML.responseText;
  		document.getElementById('video').innerHTML = videoObject;
		};
	var doc = window.document;
	myConn.connect("video.php", "GET", "video="+ video, fnWhenDone);
	
}
