// JavaScript Document
// Custom
var _imgHost = "http:\/\/fsi.dmmotion.com\/10087\/img\/";
//var _imgHost = "http:\/\/desarrollo-cstv.nspmotion.com\/10087\/img\/";
//var _imgHost = "img\/";
var ftUser = true;
var ftPass = true;
var register = "<a href='http:\/\/www.elnuevodia.com/XStatic/endi/template/content.aspx?se=registro'>Reg&iacute;strate aqu&iacute;</a>";
// Player

/*Funciones para el Permalink*/

function queryToObj (query) {
	var args=new Object(), pairs=query.split("&");
	var i = pairs.length;
	while (i--) {
		var pos=pairs[i].indexOf("=");
		if (pos==-1) continue;
		var argname=pairs[i].substring(0,pos), value=pairs[i].substring(pos+1);
		args[argname]=unescape(value);
	}
	return args;
}

var obj = queryToObj(location.search.substring(1));
var btnOk = getEl("logForm_enviar");
var txtUser = getEl("logForm_usuario");
var txtPass = getEl("logForm_password");


function Player() {
	this._plDivId = "EndiPlayer";
	this._plFile = _imgHost+"tv_custom_colors.swf";

	this.show = function () {
		var oE = document.getElementById(this._plDivId);
		oE.innerHTML = this.generateSwf("TVCustom", 900, 955, this._plFile, "PermalinkV="+obj.v+"&action="+obj.action+"&playerId="+playerId+"&principalColorText=0x"+principalColorText+"&secondaryColorText=0x"+secondaryColorText+"&bgColor=0x"+bgColor+"&highlightColor=0x"+highlightColor+"&uplAct="+uplAct, "window");
	}
	this.generateSwf = function(id, width, height, file, fv, wmode, bgcolor) {
		if (typeof(fv)=="undefined") fv="";
		if (typeof(wmode)=="undefined") wmode="window";
		var h = '';
		h+= '<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'"><param name=movie value="'+file+'" \/><param name=quality value=high \/><param name=menu value=false \/>';
		if (typeof(bgcolor)!="undefined") h+= '<param name="bgcolor" value="'+bgcolor+'" \/>';
		h+= '<param name="wmode" value="'+wmode+'" \/>';
		h+= '<param name=FlashVars value="'+fv+'" \/>';
		h+= '<param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/>';
		h+= '<embed name="'+id+'" src="'+file+'" menu=false quality=high width="'+width+'" height="'+height+'" type="application\/x-shockwave-flash" pluginspace="http:\/\/www.macromedia.com\/go\/getflashplayer" wmode="'+wmode+'"';
		if (typeof(bgcolor)!="undefined") h+= ' bgcolor="'+bgcolor+'"';
		h+= ' FlashVars="'+fv+'"';
		h+= ' allowScriptAccess="always" allowFullScreen="true"><\/embed>';
		h+= '<\/object>';
		return h;
	}
	this.show();
}
//WSLogin
function oSw(x) {
	return (navigator.appName.indexOf("Microsoft") != -1) ? window[x] : document[x];
}

function swfOnPlayerInit(){
	disabledLoginForm(false);
	btnOk.onclick = function(){
		oSw("TVCustom").WSLogin(txtUser.value, txtPass.value);
		clearLoginForm();
	}
}
function getEl(x){return document.getElementById(x);}

function disabledLoginForm(p){
	btnOk.disabled    = p;
	txtUser.disabled  = p;
	txtPass.disabled  = p;

	if(!p){
		txtUser.onclick = function(){
			if(ftUser){txtUser.value = "";ftUser=false;}
		}
		txtPass.onclick = function(){
			if(ftPass){txtPass.value = "";ftPass =false;}
		}
	}
}

function clearLoginForm(){
	//txtUser.value  = "";
	txtPass.value  = "";
}

function showInfoLogin(n){
	var info = ""
	 switch(n){
				case 1 :	//Success
					info = "Login exitoso.";
					hideLogin(true);
					getEl("infoLogin").innerHTML = info;
					setTimeout(function(){getEl("infoLogin").innerHTML = "";},4000);
					break;
				case 2 :    //Expired
					break;
				case 3 :    //IncorrectPassword
					info = "Usuario o Password incorrecto."
					getEl("infoLogin").innerHTML = info;
					setTimeout(function(){getEl("infoLogin").innerHTML = register;},4000);
					break;
				case 4 :	//ChangePassword
					break;
				case 5 :	//Deactivated
					break;
				case 6 :	//NonExistent
					info = "Usuario o Password incorrecto.";
					getEl("infoLogin").innerHTML = info;
					setTimeout(function(){getEl("infoLogin").innerHTML = register;},4000);
					break;
				case 7 :	//InsufficientData
					break;
				case 8 :	//Failure
					break;
			}
}
function hideLogin(p){	getEl("headerCenter").style.visibility =  (p)? "hidden":"";  getEl("infoLogin").innerHTML =(p)? "" :  register;}
function setHeaderStyle(){
	var header = getEl("admtv_header");
	
	header.style.backgroundColor  = '#'+ headerColor;
	header.style.color			  = '#'+ headerTextColor;
	txtUser.style.backgroundColor = '#'+ headerColor;
	txtUser.style.borderColor	  = '#'+ headerTextColor;
	txtUser.style.borderWidth	  = '1px';
	txtUser.style.color			  = '#'+ headerTextColor;
	txtPass.style.backgroundColor = '#'+ headerColor;
	txtPass.style.borderColor	  = '#'+ headerTextColor;
	txtPass.style.borderWidth	  = '1px';
	txtPass.style.color			  = '#'+ headerTextColor;
}
setHeaderStyle();
hideLogin(true);
var to = new Player();