/* ******************** ATENCION *********************

	Este javascript es utilizado por varias páginas
	pudiendo confundirse el ambito de las variables
	y funciones. Las variables globales existen en todas
	las páginas pero teniendo cada página su copia
	separada.


******************************************************

*/
	var lofi=null
	var chatactivo=false;
	var formaM=null;
	var formaL=null;
	var midl=0;
	var debg=true
	function ncontribEnlace() {
		parametros='235339733@@ @@  @@ '
		ppp=top.applet.stringCallIseriesProgram("GENERALI", "BAPO35",parametros,"top.applet.document.CHAT")
		alert("ppp="+ppp)
		//top.applet.ncontrib();
	}
	//var appletbase=top.applet.document.CHAT
	function stringCallIseriesProgram(system, program, param, appletpath){
			//alert ("appletpath= "+appletpath)
			appletpath2=eval(appletpath)
			result= appletpath2.stringCallIseriesProgram(system, program, param);
			//alert("result="+result);
			return result;
	}
	function ncontrib(){
		if (chatactivo){
			alert("validando ncontrib")
			var pepe33 = top.applet.document.CHAT.validateNumberContrib("220865018");
			alert(pepe33);
			pepe33 = top.applet.document.CHAT.validateNumberContrib("235339733");
			alert(pepe33);
			pepe33 = top.applet.document.CHAT.validateNumberContrib2("220865018");
			alert(pepe33);
			pepe33 = top.applet.document.CHAT.validateNumberContrib2("235339733");
			alert(pepe33);
		}
	}
	function debug(ale) {
		if (debg)
			alert("debug="+ale);	
	}
//////////////////////////   Código postal   ///////////////////////////////////////
var ZONPOS=""
var ZONGIR=""	
	function zipcode() {
		if (chatactivo)
			top.applet.document.CHAT.zipcode();
	}
	
	function zipcodeEnlace(){
		top.applet.zipcode();
	}
	function setPostalFields(str) {
		ZONPOS=""
		ZONGIR=""	
		nframes=top.FRAMECT.FRAMECT.middle.frames.length
		if (nframes>0){
			top.FRAMECT.FRAMECT.middle.frames[1].setPostalFields(str);
		}	
		else {	
			top.FRAMECT.FRAMECT.middle.setPostalFields(str);
		}
	}
////////////////////////////////////////////////////////////////////////////////////	
	
	function chatAct2() {
		if (chatactivo)
			top.applet.document.CHAT.showDesktop();
	}
	// ATENCION es llamada desde la cabecera
	function chatAct() {
		top.applet.chatAct2();
	}
	// ATENCION es llamada desde el applet pero 
	// unicamente cambia el valor en el frame "applet"
	
	function activarChat() {
		chatactivo=true;
	}
  function resize() {
//   	var w_newWidth,w_newHeight;
//   	var w_maxWidth=1600, w_maxHeight=1200;
//   	if (navigator.appName.indexOf("Microsoft") != -1)  {
//		w_newWidth=document.body.clientWidth;
//		w_newHeight=document.body.clientHeight;
//   	}else{
//	   	var netscapeScrollWidth=15;
//   		w_newWidth=window.innerWidth-netscapeScrollWidth;
//   		w_newHeight=window.innerHeight-netscapeScrollWidth;
//	}
//	 if (w_newWidth>w_maxWidth)
//		w_newWidth=w_maxWidth;
//	if (w_newHeight>w_maxHeight)
//		w_newHeight=w_maxHeight;
//	document.CHAT.setSize(w_newWidth,w_newHeight);
//    window.scroll(0,0);
  }

	function feval(str) {
		alert(str);
		try {
			var resultado = eval(str);
			return resultado;
		}
		catch (e) {
			alert("error con "+str);
			return null;
		}
	}
	function fillsesion() {
		setForma();
		var OASSESSTR=formaM.OASSESSTR.value;
		var KOOLSCTR=null;
		try {
			KOOLSCTR=formaM.KOOLSCTR.value;
		}catch(e) { }	
		if (OASSESSTR!=""&&OASSESSTR.length>0&&OASSESSTR.substring(0,1)!=" ") {
			formaL.OASSESSTR.value=OASSESSTR
			formaL.KOOLSCTR.value=OASSESSTR
		}
		else {
			if (KOOLSCTR!=null&&KOOLSCTR!=""&&KOOLSCTR.length>0&&KOOLSCTR.substring(0,1)!=" ") {
				formaL.OASSESSTR.value=KOOLSCTR
				formaL.KOOLSCTR.value=KOOLSCTR
			}
		}
	}
	function setForma() {
		formaL=top.camposapplet.document.forms[0];
		midl=top.FRAMECT.FRAMECT.middle.frames.length
		if (midl>0) { 
			formaM=top.FRAMECT.FRAMECT.middle.frames[1].document.forms[0];
		}	
		else {	
			formaM=top.FRAMECT.FRAMECT.middle.document.forms[0];
		}
	}
	function datosAdicionales() {
		// no es llamada esta funcion
		setForma();
		try {
			formaL.AGENTE.value=formaM.AGENTE.value
		}catch(e){ }
		try {
			formaL.CODCLI.value=formaM.CODCLI.value
		}catch(e){ }
		
		
	}
//******************Frame superior (gen1100)********************************************************************
	function chatmessage_onclick() {
//		alert(top.opener)
//		alert(top.opener.top)
//		alert(top.opener.top.agenteoculto)
//		alert(top.opener.top.agenteoculto)
//		alert(top.opener.top.agenteoculto.document)
//		alert(top.opener.top.agenteoculto.document.CHAT)
		var campos = new Array()
		campos[0]= "ANOSIN";
		campos[1]= "CODSUC";
		campos[2]= "CORSIN";
		campos[3]= "POLID";
		campos[4]= "NUMTRA";
		campos[5]= "OASHTML";
		campos[6]= "GENCIA";
		campos[7]= "OASAMB";
		campos[8]= "POLIZA";
		campos[9]= "NUMSIN";
		var mensaje="";
		var applic="";
		var separadorParamProgram="&";
		var tmp="";
		var formaM2=""
		var ANOSIN=""
		var NUMTRA=""
		midl3=top.FRAMECT.FRAMECT.middle.frames.length
		if (midl3>0) { 
			formaM2="top.FRAMECT.FRAMECT.middle.frames[1].document.forms[0]";
		}	
		else {	
			formaM2="top.FRAMECT.FRAMECT.middle.document.forms[0]";
		}
		for (i=0;i<campos.length;i++){
			try {
				ppp=formaM2+"."+campos[i]+".value";
				tmp=eval(ppp);
				if(tmp==null||tmp==undefined){
					ppp=formaM2+"."+campos[i]+"[0].value";
					tmp=eval(ppp);
					if(tmp==null||tmp==undefined){
						tmp="";
					}
				}
//				alert(campos[i]+"="+tmp);
				mensaje=mensaje+campos[i]+"="+tmp;
				if (campos[i]=="ANOSIN")
					ANOSIN=tmp
				if (campos[i]=="NUMTRA")
					NUMTRA=tmp
				mensaje=mensaje+separadorParamProgram;
			}catch(e){
			}	
		}
		var sistema=""
		if (ANOSIN!="" && NUMTRA!="")
			sistema="SN"
		else {
			sistema="EM"
		}
		if (NUMTRA==""){
			alert("Têm que ter uma a Transacção");
			return;
		}	
		mensaje=mensaje+"SYSTEM="+sistema
//		top.applet.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
//		top.applet.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
//*******   determinando donde esta el Contact Center
		var errmsg="Têm que ter o Contact Center activo";
		if (top.opener.top.applet!=null&&top.opener.top.applet!=undefined)
			top.opener.top.applet.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
		else {
			if (top.opener==null||top.opener.top==null||top.opener==undefined||top.opener.top==undefined){
				alert(errmsg)
				return;
			}
			if (top.camposapplet.document.forms[0].GENCIA.value==""||top.camposapplet.document.forms[0].GENCIA.value){
				if (top.opener.top.agenteoculto==null||
					top.opener.top.agenteoculto.document==null||
					top.opener.top.agenteoculto.document.CHAT==null||
					top.opener.top.agenteoculto.document.CHAT==undefined){
					alert(errmsg)
					return;
				}
				top.opener.top.agenteoculto.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
			}
			if (top.camposapplet.document.forms[0].GENCIA.value=="V"){
				if (top.opener.top.agenteoculto_V==null||
					top.opener.top.agenteoculto_V.document==null||
					top.opener.top.agenteoculto_V.document.CHAT==null||
					top.opener.top.agenteoculto_V.document.CHAT==undefined){
					alert(errmsg)
					return;
				}
				top.opener.top.agenteoculto_V.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
			}
				
		}	
//		top.opener.top.agenteoculto.document.CHAT.dynamicMethodInvoke("chatmessage",mensaje,separadorParamProgram);
	}
//************************************************************************************************************	


	function datosiniciales() {
		ok=false;
		try {
			setForma();
			if (midl>0) {
				if(formaM!=null&&formaM.name!="" && formaM.name.length>4 && formaM.name.substring(0,4)!="GETK") {
					formaL.AGENTE.value=formaM.AGENTE.value;
					formaL.OASAMB.value=formaM.OASAMB.value;
					formaL.GENCIA.value=formaM.GENCIA.value;
// Edgar E 2004/09/14					if (formaL.AGENTE[0].value!="" ||formaL.AGENTE[0].value!=" ") {
//					alert("formaM.AGENTE[0].value"+formaM.AGENTE[0].value)
					if (formaM.AGENTE.value!="" && formaM.AGENTE.value!=" " && formaM.AGENTE.value!=undefined) {
						fillsesion();
						ok=true;
// Edgar E 2004/09/14
					}else{
						if (formaM.AGENTE[0].value!="" && formaM.AGENTE[0].value!=" " && formaM.AGENTE[0].value!=undefined) {
							formaL.AGENTE.value=formaM.AGENTE[0].value;
							formaL.OASAMB.value=formaM.OASAMB.value;
							formaL.GENCIA.value=formaM.GENCIA.value;
							fillsesion();
							ok=true;
						}
					}
				}
			}
			else {
				if(formaM!=null&&formaM.name!="" && formaM.name.length>4 && formaM.name.substring(0,4)!="GETK") {
					formaL.AGENTE.value=formaM.AGENTE.value;
					formaL.OASAMB.value=formaM.OASAMB.value;
					formaL.GENCIA.value=formaM.GENCIA.value;
					
// Edgar E 2004/09/14					if (formaL.AGENTE[0].value!="" ||formaL.AGENTE[0].value!=" ") {
					if (formaM.AGENTE.value!="" && formaM.AGENTE.value!=" " && formaM.AGENTE.value!=undefined) {
						fillsesion();
						ok=true;
// Edgar E 2004/09/14
					}else{
						if (formaM.AGENTE[0].value!="" && formaM.AGENTE[0].value!=" " && formaM.AGENTE[0].value!=undefined) {
							formaL.AGENTE.value=formaM.AGENTE[0].value;
							formaL.OASAMB.value=formaM.OASAMB.value;
							formaL.GENCIA.value=formaM.GENCIA.value;
							
							fillsesion();
							ok=true;
						}
					}
				}
			}	
		}
		catch(e) {
			ok=false;
		}
		return ok;
	}
	
	function setNameVedior(str){
	//	alert(str)
		top.CABEZERA.document.forms[0].NOMVEDIOR1.value="Utilizador: ";
		top.CABEZERA.document.forms[0].NOMVEDIOR2.value=str;
	}
//	function fun(what) {
//		if(what) {
		//do actual submit;
//		} else{
//			alert("operação não permitida2");
//			top.window.close();
//		}
//	}

