/* Escribe flash embed para evitar bloqueo de IE*/

/*
 Se aplica:
 <div id="id_contenedor">
 	<img alternativa>
 	<script type="text/javascript">
		// <![CDATA[
		// Se aplica esta linea cuando es video
		urlVideo = "&MM_ComponentVersion=1&skinName=&MM_ComponentVersion=1&skinName=/es/Nombre_del_control&streamName=/swf/nombreflash&autoPlay=true&autoRewind=false";
		//
		var so = new SWFObject("/es/nombrepelicula.swf", "Video", "480px", "368px", "7", "#FFF","transparent", urlVideo);
		so.write("id_contenedor");
		// ]]>
	</script>
</div>
*/
 
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_mode,_FlashVars,_7,_8,_9,_a,_b){
if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
if(_mode) this.addParam("wmode",_mode);
if(_FlashVars) this.addParam("FlashVars",_FlashVars);
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=key+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
_19+="/>";
}else{
	if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{
try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{
var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);
axo.AllowScriptAccess="always";}
catch(e){
if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}
if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}
return true;
};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){
var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){
_2d[i].style.display="none";
for(var x in _2d[i]){if(typeof _2d[i][x]=="function"){_2d[i][x]=null;}}}};
if(typeof window.onunload=="function"){
var oldunload=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();
oldunload();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}
if(Array.prototype.push==null){
Array.prototype.push=function(_30){
this[this.length]=_30;
return this.length;};}

var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for legacy support
var SWFObject=deconcept.SWFObject;


function callback_test1(res)
{
	document.getElementById("display1").innerHTML = res.value;
}

function test1()
{
	DemoMethods.Test1(
		document.getElementById("firstName").value, 
		document.getElementById("familyName").value,
		document.getElementById("email").value,
		document.getElementById("comment").value,
		callback_test1
		);
}

function callback_test2(res)
{
	document.getElementById("display2").innerHTML = res.value;
}

function test2()
{
	var d = null;

	try	
	{
		d = new DateTime(
			document.getElementById("year").value,
			document.getElementById("month").value,
			document.getElementById("day").value,
			0, 0, 0
			);
		
		DemoMethods.Test2(d, callback_test2);
	}
	catch(e)
	{
		alert("Error: " + e.description);
	}
}

function callback_test3(res)
{
	lst = res.context;//document.getElementById('_ctl1_cmbComuna');
	lst.options.length = 0;
	lst.options[0] = new Option("Seleccione Comuna", "");
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
			//html[html.length] = "<option>" + res.value.Tables[0].Rows[i].Country + "</option>";
			lst.options[i+1] = new Option(res.value.Tables[0].Rows[i].nombre, res.value.Tables[0].Rows[i].codComuna);
		}
		//document.getElementById("display3").innerHTML = "<select>" + html.join("") + "</select>";
	}
}

function test3(sel, value)
{
	DemoMethods.Test3(value, callback_test3, sel);
}


function callback_GetOficinas(res)
{
	lst = res.context;
	lst.options.length = 0;
	lst.options[0] = new Option("Seleccione Oficina", "");
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
			lst.options[i+1] = new Option(res.value.Tables[0].Rows[i].des_oficina, res.value.Tables[0].Rows[i].cod_oficina);
		}
	}
}

function GetOficinas(sel, value)
{
	try
	{
		DemoMethods.GetOficinas(value, callback_GetOficinas, sel);
	}
	catch(e)
	{
		alert(e.description);
	}
}

function callback_GetCiudades(res)
{
	lst = res.context;
	lst.options.length = 0;
	lst.options[0] = new Option("Seleccione Ciudad", "");
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
			lst.options[i+1] = new Option(res.value.Tables[0].Rows[i].descripcion, res.value.Tables[0].Rows[i].cod_ciudad);
		}
	}
}
function GetCiudades(sel, value)
{
	try
	{
		DemoMethods.GetCiudades(value, callback_GetCiudades, sel);
	}
	catch(e)
	{
		alert(e.description);
	}
}


function OficinaEntrega(fecha, hora, minuto, oficina, ele)
{
	try
	{
		r = DemoMethods.OficinaEntrega(fecha, hora, minuto, oficina)
		return DemoMethods.OficinaEntrega(fecha, hora, minuto, oficina);
	}
	catch(e)
	{
		alert(e.description);
	}
}

function OficinaDevolucion(fecha, hora, minuto, oficina, ele)
{
	try
	{
		r = DemoMethods.OficinaDevolucion(fecha, hora, minuto, oficina)
		return DemoMethods.OficinaDevolucion(fecha, hora, minuto, oficina);
	}
	catch(e)
	{
		alert(e.description);
	}
}


function ConsultaHorario(oficina)
{
	if(oficina.options[oficina.selectedIndex].value!='')
	{	
		window.open('/PopHorarios.aspx?CodOficina='+oficina.options[oficina.selectedIndex].value, 'horario', 'width=400,height=240');
	}
}

function test4()
{
	var res = DemoMethods.Test4();
	if(res.error != null) alert(res.error);
}

function test5()
{
	DemoMethods.Test5(document.getElementById("sessionTest1").value);
}

function callback_test6(res)
{
	document.getElementById("sessionTest2").value = res.value;
}

function test6()
{
	DemoMethods.Test6(callback_test6);
}

function callback_test7(res)
{
	alert("The server has finished the 10 seconds call, now!");
}

function test7()
{
	DemoMethods.Test7(callback_test7);
}

function test8(ele)
{
	DemoMethods.Test8(test8_callback, ele);  // the server-side method has no arguments!
}

function test8_callback(res)
{
	if(res.error == null && res.context != null)
		res.context.innerHTML = res.value;
}

function test11()
{
	DemoMethods.Test11(test11_callback);
}

function test11_callback(res)
{
	if(res.value[2])							// bolean
		alert(res.value[1].toLocaleString());	// date
		
	alert(res.value[3].FirstName + " + " + res.value[4].FirstName);
}

function test12()
{
	DemoMethods.Test12(test12_callback);
}

function test12_callback(res)
{
	var s = res.value.FirstName + " " + res.value.FamilyName + ":\r\n";
	
	for(var i=0; i<res.value.Children.length; i++)
		s += "\t" + res.value.Children[i].FirstName + "\r\n";
	
	alert(s);
}

function test13()
{
	// call the Ajax.NET method on the server to get
	// a new news ticker object
  
	DemoMethods.Test13(test13_callback);
}

function test13_callback(res)
{
	if(typeof(res.value) == 'object')
	{
		// display the news ticker
    
		document.getElementById('newsticker').innerHTML = '<a href="' + res.value.URL + '">' + res.value.Text + '</a>';
		window.setTimeout(test13, res.value.Duration * 1000);
	}
}

function test16()
{
	DemoMethods.Test16(test16_callback);
}

function test16_callback(res)
{
	if(typeof(res.value) == 'object')
	{
		document.getElementById("imageholder").innerHTML = '';
		document.getElementById("imageholder").appendChild(res.value);
	}
}

function test17(n)
{
    // n will be a array of numbers/integer

	if(typeof(n) != 'object') return;
	alert(DemoMethods.Test17(n).value);
}

function test18()
{
	alert(DemoMethods.Test18( ["aaaa","bbbb","ccc\"ccccc"] ).value);
}

function test19(ele, car)
{
	HtmlControlUpdate('DemoMethods.Test19', 'dropDisplay', car);
}

function test20()
{
	return DemoMethods.Test20().value;
}

function test21(controlHolderId, id)
{
	HtmlControlUpdate('DemoMethods.Test21', controlHolderId, new HtmlControl(id));
}


function getSucursal(sucursal, rut)
{
	DemoMethods.getSucursal(sucursal, rut, getSucursal_callback);
}
function saveSucursal(rutCliente, sucursal, nombreSucursal, direccion, telefono, fax, celular, email, codigoPostal, comuna, ciuId, contacto, telefonoContacto, formaPago, puntos, vendedor, codigoRuta, banco, nroCtaCte, nroTarjeta, fechaCreacion, usuario, codigoBodega) {
	DemoMethods.saveSucursal(rutCliente, sucursal, nombreSucursal, direccion, telefono, fax, celular, email, codigoPostal, comuna, ciuId, contacto, telefonoContacto, formaPago, puntos, vendedor, codigoRuta, banco, nroCtaCte, nroTarjeta, fechaCreacion, usuario, codigoBodega);
	return;
}

function getSucursal_callback(res)
{
	//numero, descripcion, telefono, fax, postal,
	putDataInForm(res.value.mySucursal, res.value.myNombreSucursal, res.value.myTelefono, res.value.myFax, res.value.myCodigoPostal, res.value.myDireccion);
	//for(var i=0; i<res.value.Children.length; i++)
	//	s += "\t" + res.value.Children[i].FirstName + "\r\n";
}


function ValidarEmail_callback(res)
{
	if(typeof(res.value) == 'object' && res.value!=null) {
		msgIncorrecto.style.display = 'none';
		msgCorrecto.style.display = 'block';
		document.forms[0].btnEnviar.disabled= true;
		//putDataInForm(res.value.myEmail);
	}
	else
	{
		msgCorrecto.style.display = 'none';
		msgIncorrecto.style.display = 'block';
	}
	AjaxUnLoading();
}
function ValidarEmail(email)
{
	AjaxLoading();
	DemoMethods.ValidarEmail(email, ValidarEmail_callback);
}

//window.attachEvent("onload", test13);


//funciones de arbol

function callback_Childrens(res)
{
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1) {
		el = res.context;
		removeChild(el);
		fillObjectsFolder(res, el);
	} else {
		el = res.context;
		removeChild(el);
	}
}

function removeChild(el) {
	if(nodo = getElementById(el)) {
		myDiv_ = getElementById('lmyDiv');
		if(typeof (myDiv_)=="object" && closeDiv) {
			myDiv_.parentNode.removeChild(myDiv_);
		}
	}
}

var myDiv;
var closeDiv = false;
function Childrens(ele, value, open)
{
	var d = null;
	if(!open) {
		open = false;
	}
	try	
	{
		id = value;
		if(nodo = getElementById(ele)) {
			if((treeDiv=getElementById('tree_'+id))) {
				if(open && treeDiv.style.display=='') {
					return;
				}
				myDiv = document.createElement("DIV");
				myDiv.id = 'lmyDiv';
				myDiv.className = "loading";
				myDiv.innerHTML = "<p>loading...</p>";
				treeDiv.appendChild(myDiv);
				closeDiv = true;
			}
		}
		DemoMethods.Childrens(value, callback_Childrens, 'tree_'+id);
	}
	catch(e)
	{
		alert("Error: " + e.description + " " + e.line);
	}
}


/* casillas de datos de beneficiarios */

function callback_documentosCarpeta(res) {
	documents = getElementById('tree_documents');
	try {
		for(var i=0; i <= documents.rows.length; i++) {
			documents.removeChild(documents.firstChild);
		}
	}
	catch(e){
	}
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1) {
		for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
			id = Math.floor(Math.random() * 10000);
			tr = document.createElement('tr');
			tr.id = 'detalle_' + id;
			/*icono del archivo*/
			td_icono = document.createElement('td');
			icono = document.createElement("IMG");
			icono.src = "../images/html/ic_" + res.value.Tables[0].Rows[i].docu_tipo+".gif";
			td_icono.appendChild(icono);
			td_icono.className = "documentos";
			tr.appendChild(td_icono);
			/*nombre del archivo*/
			td_nombre = document.createElement('td');
			td_nombre.appendChild(document.createTextNode(res.value.Tables[0].Rows[i].docu_titulo));
			td_nombre.className = "documentos";
			tr.appendChild(td_nombre);
			/*tamaņo del archivo*/
			td_tamano = document.createElement('td');
			td_tamano.appendChild(document.createTextNode(res.value.Tables[0].Rows[i].docu_titulo + ' kb'));
			td_tamano.className = "documentos";
			tr.appendChild(td_tamano);
			/*fecha de creacion*/
			td_creacion = document.createElement('td');
			td_creacion.appendChild(document.createTextNode(res.value.Tables[0].Rows[i].docu_creacion));
			td_creacion.className = "documentos";
			tr.appendChild(td_creacion);
			/*descarga*/
			td_descarga = document.createElement('td');
			icono = document.createElement("IMG");
			icono.src = "images/html/ic_actualizar.gif";
			icono.setAttribute('border', '0');
			var link = document.createElement('a');
			link.setAttribute('href', 'Carpeta.aspx?opc=EditDocumento&Id=' + res.value.Tables[0].Rows[i].documento_id);
			link.setAttribute('name', 'myanchor');
			link.appendChild(icono);		
			td_descarga.appendChild(link);
			td_descarga.className = "documentos";
			tr.appendChild(td_descarga);
			documents.appendChild(tr);
		}
	}
}



function documentosCarpeta(carpeta_id) {
	try	{
		document.forms[0].padreId.value = carpeta_id;
		DemoMethods.documentsByFolder(carpeta_id, callback_documentosCarpeta);
	} catch(e) {
		alert("Error: " + e.description);
	}
}


// unserializeArray: deserializa el parametro param y devuelve un arreglo hash 
function _unserializeArray(param) {
	var i, j, text, value, aux;
	objects = param.split("|");
	var aObjects = new Array();
	for(i = 0; i < objects.length; i++) {
		vars = objects[i].split("&");
		var object = new Array();
		for (j = 0; j < vars.length; j++) {
			aux = vars[j].split("=");
			object[aux[0]] = aux[1];
		}
		aObjects[aObjects.length] = object;
	}
	return aObjects;
}

function fillObjectsFolder(data, select) {
	fillTreeFromArray(select, data);
	return true;
}

var ultimoElemento;
var IMG_FOLDER_OPEN = "../images/html/int_carpeta_abierta.gif";
var IMG_FOLDER_CLOSE = "../images/html/int_carpeta_cerrada.gif";

function fillTreeFromArray(ele, res) {
	var contenido = '';
	//contenido = getElementById(ele).innerHTML;
	id = res.value.Tables[0].Rows[0].car_carpeta_id;
	nodo = getElementById('tree_'+id);
	if(nodo.innerHTML!='') {
		img_tree = getElementById('img_tree_'+id);
		if(nodo.style.display=='') {
			img_tree.src = IMG_FOLDER_CLOSE;
			nodo.style.display='none';
		} else {
			img_tree.src = IMG_FOLDER_OPEN;
			nodo.style.display='';
		}
		return;
	} else {
        img_tree = getElementById('img_tree_'+id);
		img_tree.src = IMG_FOLDER_OPEN;
		nodo.style.display='';
	}
	
	var regexp = new RegExp("</DIV>");
	var encontrados = contenido.match(regexp);
	//myString = new String(contenido);
	//rExp = /<\/div>/gi;
	//contenido = myString.replace(rExp, "");
	contenido= "<DIV id='tree_"+id+"'>";
	for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
		carpeta = res.value.Tables[0].Rows[i].carp_nombre;
		carpeta_id = res.value.Tables[0].Rows[i].carpeta_id;
		car_carpeta_id = res.value.Tables[0].Rows[i].car_carp_nombre;
		carpetas = res.value.Tables[0].Rows[i].carp_nombre;
		archivos = res.value.Tables[0].Rows[i].carp_nombre;
		hijos = res.value.Tables[0].Rows[i].hijos;
		if (carpeta) {
			html = '';
			html = 'class="linkfolder" href="javascript:Childrens(\'folderChildren\', '+carpeta_id+', true);documentosCarpeta(\''+carpeta_id+'\');"';
			if (hijos == 0){
				html = 'class="linkfolder" href="javascript:documentosCarpeta(\''+carpeta_id+'\');"';
				contenido+= '<p class="documentos">'+hijos+' carpetas&nbsp;</p><p onmousedown="preparar('+carpeta_id+')"><img src="../images/html/int_carpeta_cerrada.gif" id="img_tree_'+carpeta_id+'" alt="" border="0" align="absmiddle"><a '+html+' onFocus="blur()">'+carpeta+'</a></p>';
			} else {
				//documentosCarpeta(\'documento\', \''+cliente_id+'\', \''+carpeta_id+'\',\'content_files\');
				contenido+= '<p class="documentos">'+hijos+' carpetas</p><p onmousedown="preparar('+carpeta_id+')"><a href="javascript:void(null);" onClick="Childrens(\'folderChildren\', '+carpeta_id+');" onFocus="blur()"><img src="../images/html/int_carpeta_cerrada.gif" id="img_tree_'+carpeta_id+'" alt="" border="0" align="absmiddle"></a><a '+html+' onFocus="blur()">'+carpeta+'</a></p>';
			}
			contenido+= "<SPAN id='tree_"+carpeta_id+"' style='display:none'>";
			contenido+= "</SPAN>";
		}
	}
	
	ultimoElemento = contenido;
	if(encontrados){
		for(i=0;i<encontrados.length; i++) {
			contenido+= "</DIV>";	
		}
	}
	contenido+= "</DIV>";
	
	getElementById(ele).innerHTML = getElementById(ele).innerHTML + (contenido);
}


function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
	return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
	return "";
	}
	else{
	return TRIM_VALUE;
	}
} //End Function



