/*
Php YT Site
Copyright (C) 2007 Ciprian Dosoftei
http://www.phpytsite.org/

This program is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Further to the terms mentioned you should leave the copyright footers and
copyright notice in the code intact, stating me as the original author.
*/

function youTubePlayer( vid ) {
	document.write( "<object width='425' height='355'><param name='movie' value='http://www.youtube.com/v/" + vid + "'></param><param name='wmode' value='transparent'></param><embed src='http://www.youtube.com/v/" + vid + "' type='application/x-shockwave-flash' wmode='transparent' width='425' height='355'></embed></object>" );
}

function checkLogin() {
	if( ! $F("username") ) {
		$("username").setStyle( { background: '#a00' , color: '#fff' } );
		$("username").focus();
		window.alert( "Please enter your username!" );
		return false;
	} else
		$("username").setStyle( { background: '#fff' , color: '#000' } );

	if( ! $F("password") ) {
		$("password").setStyle( { background: '#a00' , color: '#fff' } );
		$("password").focus();
		window.alert( "Please enter your password!" );
		return false;
	} else
		$("password").setStyle( { background: '#fff' , color: '#000' } );

	$("loginFrm").submit();
}

function saveSettings() {
	var fields = new Array( "sitename" , "siteurl" , "path" , "tagline" , "tag" , "vpp" , "welcome" );

	for( f = 0 ; f < fields.length ; f++ )
		if( ! $F( fields[f] ) ) {
			$( fields[f] ).setStyle( { background: '#a00' , color: '#fff' } );
			$( fields[f] ).focus();
			window.alert( "Please fill in all fields!" );
			return false;
		} else
			$( fields[f] ).setStyle( { background: '#fff' , color: '#000' } );

	$("settingsFrm").submit();
}

function saveCredentials() {
	if( ! $F("admin") ) {
		$("admin").setStyle( { background: '#a00' , color: '#fff' } );
		$("admin").focus();
		window.alert( "Please enter your administrator username!" );
		return false;
	} else
		$("admin").setStyle( { background: '#fff' , color: '#000' } );

	if( $F("npassword") ) {
		if( ! $F("cpassword") ) {
			$("cpassword").setStyle( { background: '#a00' , color: '#fff' } );
			$("cpassword").focus();
			window.alert( "You must enter your current password before updating it!" );
			return false;
		} else
			$("cpassword").setStyle( { background: '#fff' , color: '#000' } );

		if( ! $F("rpassword") || $F("npassword") != $F("rpassword") ) {
			$("rpassword").setStyle( { background: '#a00' , color: '#fff' } );
			$("rpassword").focus();
			window.alert( "Please confirm your new password!" );
			return false;
		} else
			$("rpassword").setStyle( { background: '#fff' , color: '#000' } );
	}

	$("credentialsFrm").submit();
}

function updateVideos() {
	location.href = "admin.php?atask=updateVideos";
}

function desecho() {
	location.href = "admin.php?atask=desecho";
}


function dynamicSubmit(Accion)
{
//document.getElementById(Accion).action='admin.php?atask=valido';
//document.getElementById(Accion).submit();
$(Accion).action='admin.php?atask=valido';
$(Accion).submit();

//Expresion = "document.getElementById('"+Accion+"').action ='admin.php?atask=valido'";
//eval(Expresion);

//Expresion = "document.getElementById('"+Accion+"').submit();" ;
//eval(Expresion);


}

function dynamicSubmit2(Accion)
{
//document.getElementById(Accion).action='admin.php?atask=desecho';
//document.getElementById(Accion).submit();
$(Accion).action='admin.php?atask=desecho';
$(Accion).submit();
}

function dynamicSubmit3(Accion,Donde)
{
$(Accion).action=Donde;
$(Accion).submit();
}


function makeRequest(url,div)
{

	document.getElementById('control').value=div;

	var n_url=url;

	document.getElementById(div).innerHTML="Cargando...";
        http_request = false;

        if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType)
			{
                http_request.overrideMimeType('text/xml');
            }
        }
		else if (window.ActiveXObject)
		{ // IE
            try
			{
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e)
			{
                try
				{
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request)
		{
            alert('Falla :( No es posible crear una instancia XMLHTTP');
            return false;
        }
        http_request.onreadystatechange = alertContents;
        http_request.open('GET', n_url, true);
        http_request.send(null);
}

function alertContents()
{

		div=document.getElementById('control').value


	if (http_request.readyState == 4)
	{
   		if (http_request.status == 200)
		{
			document.getElementById(div).innerHTML=http_request.responseText;
    	}
		else
		{
        alert('Hubo problemas con la petición.');
    	}
	}
}