









function  ScrollCenter ( parameters ) 
{
	var _self 			= this;
	var _loading 		= false;
	var _loaded 		= false;
	
	this.container		= null;
	
	this.floatX			= 0;
	this.floatY			= 0; 
	this.layerwidth		= 0;
	this.layerheight	= 0;
	this.halign			= "left";
	this.valign			= "top";
	this.delayspeed		= 0;
	this.ifloatX		= 0;
	this.ifloatY		= 0;
	this.lastX			=-1;
	this.lastY			=-1;

	this.ajust_object_timer = 0;	
	
	function _getScrollTop ()
	{
		return $Y.Dom.getDocumentScrollTop() ;//( YAHOO.env.ua.ie > 5 ? (document.compatMode=="CSS1Compat"?document.documentElement.scrollTop:document.body.scrollTop) :  ( window.pageYOffset?window.pageYOffset:  Math.max(document.body.scrollTop,document.documentElement.scrollTop))  ) ;
	}

	function _getScrollLeft ()
	{
		return $Y.Dom.getDocumentScrollLeft();//( YAHOO.env.ua.ie > 5 ? (document.compatMode=="CSS1Compat"?document.documentElement.scrollLeft:document.body.scrollLeft) :  ( window.pageXOffset?window.pageXOffset:  Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)) ) ;
	}
	
	
	function _adjust() {

	    var innerHeight=  $Y.Dom.getClientHeight();
	    var innerWidth =  $Y.Dom.getClientWidth();
		
		if (_self.lastX == -1 || _self.delayspeed == 0) 
		{
			_self.lastX = _getScrollLeft() + _self.floatX;
			_self.lastY = _getScrollTop () + _self.floatY;
		} 
		else 
		{
			var dx = Math.abs( _getScrollLeft() + _self.floatX - _self.lastX);
			var dy = Math.abs( _getScrollTop () + _self.floatY - _self.lastY);
			var d  = Math.sqrt(dx * dx + dy * dy);
			var c  = Math.round(d / 10);
			
			if ( _getScrollLeft() + _self.floatX > _self.lastX) {
				_self.lastX = _self.lastX + _self.delayspeed + c;
			}
			if ( _getScrollLeft() + _self.floatX < _self.lastX) {
				_self.lastX = _self.lastX - _self.delayspeed - c;
			}
			if ( _getScrollTop () + _self.floatY > _self.lastY) {
				_self.lastY = _self.lastY + _self.delayspeed + c;
			}
			if ( _getScrollTop () + _self.floatY < _self.lastY) {
				_self.lastY = _self.lastY - _self.delayspeed - c;
			}

			
	        var obj 		= $Y.Dom.get(_self.container);
			
	        obj.style.left = _self.lastX+'px';
	        obj.style.top  = _self.lastY+'px';
		}
		
		_self.ajust_object_timer = setTimeout(_adjust, 5);
	}
	
	function _define( e ) 
	{
        //var innerHeight=  ( YAHOO.env.ua.ie > 5  ? document.body.clientHeight: window.innerHeight);
        //var innerWidth =  ( YAHOO.env.ua.ie > 5  ? document.body.clientWidth : window.innerWidth );
		
	    var innerHeight=  $Y.Dom.getClientHeight();
	    var innerWidth =  $Y.Dom.getClientWidth();
	   
        
		if (_self.halign == "left") 
			_self.floatX = _self.ifloatX;
		if (_self.halign == "right") 
			_self.floatX = innerWidth  - _self.ifloatX - _self.layerwidth - 20;
		if (_self.halign == "center") 
			_self.floatX = Math.round((   innerWidth - 20) / 2)- Math.round(_self.layerwidth / 2);
		if (_self.valign == "top") 
			_self.floatY = _self.ifloatY;
		if (_self.valign == "bottom") 
			_self.floatY = innerHeight - _self.ifloatY - _self.layerheight;
		if (_self.valign == "center") 
			_self.floatY = Math.round((  innerHeight - 20) / 2)- Math.round(_self.layerheight / 2);
	}	
	
	function _process()
	{
		_define( null );

		$Y.Event.addListener($Y.Dom.get(_self.container) , 'resize', _define  );
		$Y.Event.addListener($Y.Dom.get(_self.container) , 'scroll', _define  );
		
		_adjust();
	}
	
	this.loading 	= function() { _loading = false; }
	this.loaded 	= function() { _loading = true; }
	this.pageLoaded = function() { _loaded = true; }
	this.isLoading 	= function() { return _loading; }
	this.isLoaded 	= function() { return _loaded; }
	
	this.init = function() 
	{
		var s_key;
		
		for (s_key in parameters)
			this[s_key] = parameters[s_key];

		if (typeof(this.interval)=='undefined' || this.interval == 0)
			this.interval = 5000;
		
		if ( typeof(this.halign) == 'undefined' )
			this.halign = "center";
    	
		if ( typeof(this.valign ) == 'undefined' )
			this.valign = "center";
		
		if ( typeof(this.delayspeed ) == 'undefined'  || this.delayspeed == 0)
			this.delayspeed		= 1;

		if ( typeof(this.lastX ) == 'undefined'  || this.lastX == 0)
			this.lastX = -1;
		
		if ( typeof(this.lastY ) == 'undefined'  || this.lastY == 0)
			this.lastY = -1;
		
		if ( typeof(this.container ) == 'undefined'  || this.container == '')
			return ;

		//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
		//
		//
		//
		//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

        var obj 		= $Y.Dom.get(this.container);
        var l_point 	= getXY(obj);
        var l_dimension = getWH(obj);

        var innerHeight=  $Y.Dom.getClientHeight();
        var innerWidth =  $Y.Dom.getClientWidth();

        if ( typeof(this.floatX ) == 'undefined'  || this.floatX == 0)
			this.floatX = Math.abs( innerWidth  - l_dimension.w ) / 2;

        if ( typeof(this.floatY ) == 'undefined'  || this.floatY == 0)
			this.floatY = Math.abs( innerHeight - l_dimension.h ) / 2;
        
        $Y.Dom.setStyle(this.container,'top',  this.floatY + 'px');
        $Y.Dom.setStyle(this.container,'left', this.floatX + 'px');

    	this.layerwidth 	= l_dimension.w;
    	this.layerheight 	= l_dimension.h;
    	
    	this.ifloatX 		= this.floatX;
		this.ifloatY 		= this.floatY;
		
		_self.loading();
		
		_process() ;
	}

	
	this.showObject = function() 
	{
	}
	
	
}
Require.isLoaded['ScrollCenter'] = true;

var _popupTimer  = 0;

function closePopup()
{
	$Y.Dom.removeClass('popupBox' ,"popupContact");
	$Y.Dom.removeClass('popupBkg' ,"contactBkg");
	$Y.Dom.removeClass('popupBox' ,"popupSendEmail");
	$Y.Dom.removeClass('popupBkg' ,"sendEmailBkg");
	$Y.Dom.setStyle('popupBox', 'display', 'none');
	$Y.Dom.setStyle('rootPopup', 'display', 'none');
	$Y.Dom.setStyle('popupBoxLoading', 'display', 'none');
	
	//M20090478 - JABG 20100120
	$Y.Dom.get('popupContainer').innerHTML = "";
	clearTimeout(_popupTimer);
	//M20090478 - JABG 20100120
}

function Popup ( parameters ) 
{
    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 	//  Se implemento la mejora centro estatico
	//  obtener el centro mediante el alto de client
    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	
	var p_style 	= 'popupDefault';
	var p_styleBkg	= 'popupDefaultBkg'; 
	var p_page      = '';
	var _self		= this ;
	
	this.init = function() 
	{	
		var s_key;
		
		for (s_key in parameters)
			this[s_key] = parameters[s_key];
		
		p_page      = this.url;
	
		$Y.Dom.addClass('popupBox', p_style);
		$Y.Dom.addClass('popupBkg', p_styleBkg);
	
		if (typeof( this.height ) != 'undefined')
			$Y.Dom.setStyle('popupBox', 'height', this.height+'px');
			
		if (typeof( this.width ) != 'undefined')
			$Y.Dom.setStyle('popupBox', 'width', this.width+'px');
			
		$Y.Dom.setStyle('rootPopup', 'display', 'block');

		$Y.Dom.setStyle('popupBox', 'position', 'absolute');
		$Y.Dom.setStyle('popupBox', 'display', 'block');
	    
        var obj 		= $Y.Dom.get('popupBox');
        var l_point 	= getXY(obj);
        var l_dimension = getWH(obj);
        var posYCenter =  0;
        var posXCenter =  0;
        
        var innerHeight=  $Y.Dom.getClientHeight();
        var innerWidth =  $Y.Dom.getClientWidth();
        
       	posYCenter = Math.abs( innerHeight - l_dimension.h ) / 2;
    	posXCenter = Math.abs( innerWidth  - l_dimension.w ) / 2;

        $Y.Dom.setStyle('popupBox','top',  posYCenter + 'px');
        $Y.Dom.setStyle('popupBox','left', posXCenter + 'px');

    	layerwidth 	= l_dimension.w;
    	layerheight = l_dimension.h;
	    
		$Y.Dom.setStyle('popupBoxLoading', 'display', 'block');
		
	     var h = 0, w=0;
	
	     $Y.Dom.setStyle('disablerDiv', 'top', '0px');
	     $Y.Dom.setStyle('disablerDiv', 'left', '0px');
	     $Y.Dom.setStyle('rootPopup', 'position', 'absolute');
	     $Y.Dom.setStyle('popupContainer', 'display', 'none');

	     //M20090478 - JABG 20100120
	     //h = Math.max(document.body.scrollHeight, document.documentElement.offsetHeight);
	     h = $Y.Dom.getDocumentHeight();
		 w = Math.max(document.body.scrollWidth, document.documentElement.offsetWidth);
		 
	     $Y.Dom.get('disablerDiv').style.height = (h) + "px";
	     //M20090478 - JABG 20100120
	
		var callback = {
			success: function(o){
				

				if (typeof( _self.process ) != 'undefined') 
					$Y.Dom.get('popupContainer').innerHTML = _self.process ( o.responseText );
				else
					$Y.Dom.get('popupContainer').innerHTML = o.responseText;

				$Y.Dom.setStyle('popupBoxLoading', 'display', 'none');
				$Y.Dom.setStyle('popupContainer', 'display', 'block');
	        	
				/* INICIO Req. S20100078 / cfveliz */
				if (typeof(_self.scrollable) != 'undefined') {
					if (_self.scrollable) {
						TPI.scrollCenter = new ScrollCenter ({'container' : 'popupBox'});
						TPI.scrollCenter.init();
					}
				}
	            /* FIN Req. S20100078 / cfveliz */
				/* INICIO Req. M20110198*/
				if (typeof( _self.ejecutar ) != 'undefined') {
					_self.ejecutar();
				}
				/* FIN Req. M20110198*/
			}, 
			failure: function(o){
				//Stage.handleFailure(o);
				$Y.Dom.get('popupContainer').innerHTML = "";	//M20090478 - JABG 20100120
			}
		}
		
		/* INICIO Req. M20100154 / cfveliz */
		if (typeof( _self.url ) != 'undefined') {
			$Y.Connect.asyncRequest('GET', p_page, callback);
		} else {
			$Y.Dom.get('popupContainer').innerHTML = _self.process();
			$Y.Dom.setStyle('popupBoxLoading', 'display', 'none');
			$Y.Dom.setStyle('popupContainer', 'display', 'block');
        	
			/* INICIO Req. S20100078 / cfveliz */
			if (typeof(_self.scrollable) != 'undefined') {
				if (_self.scrollable) {
					TPI.scrollCenter = new ScrollCenter ({'container' : 'popupBox'});
		            TPI.scrollCenter.init();
				}
			}
            /* FIN Req. S20100078 / cfveliz */
		}
		/* FIN Req. M20100154 / cfveliz */
		
	     if (typeof(this.autoClose)!='undefined')
	     {
	    	if (_popupTimer !=0 ) clearTimeout(_popupTimer);
	    	
	    	 _popupTimer = setTimeout( this.close, this.autoClose );
	     }
	
	}

	this.close = function () 
	{
		closePopup()
	}	
}

Require.isLoaded['Popup'] = true;

/* INICIO Req. M20100474 / cfveliz */
/*
//var totalEmails     = 0;	//Linea JABG / 20081017
var totalEmails     = 1;	//Linea JABG / 20081017
var MAX_SEND_EMAILS = 4;
var filaEliminada   = 0;	//Linea JABG / 20081017
*/
/**
 * Funcion para recomienda este aviso
 * @return
 * v2
 */
/*
function sendAdvertise() 
{
   var _popup = new Popup ({'url':'viewMoreSendAdvertise.do', 'width':500, 'height':100});
   _popup.init ();
}


function addToEmail()
{
	if ( totalEmails <= MAX_SEND_EMAILS ) {
		if ( filaEliminada <= 0 ) {	//Linea JABG / 20081017
			$Y.Dom.replaceClass('sendAdvertiseTo_'+totalEmails, 'off', 'on');
		} else {	
			$Y.Dom.replaceClass('sendAdvertiseTo_'+filaEliminada, 'off', 'on');
		}	
		totalEmails++;
	} else
		totalEmails = MAX_SEND_EMAILS;
}

function removeToEmail(rowContainer)
{
	var el = $Y.Dom.get(rowContainer);

	if ( typeof (el) == 'undefined' ) return;
	totalEmails--;
	filaEliminada = rowContainer.substr(rowContainer.length - 1, 1);	

	$Y.Dom.replaceClass(rowContainer, 'on', 'off');
}

function checkEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function checkSendAdvForm()
{
	var formEl     = $Y.Dom.get('sendEmailForm');
	var fromNameEl = $Y.Dom.get('fromName');

	if ( fromNameEl.value.length < 2 ) {
		alert("Por favor ingrese un nombre v&aacute;lido");
		fromNameEl.focus();

		return false;
	}

	var fromMail = $Y.Dom.get('fromMail');

	if ( fromMail.value.length < 2 ) {
		alert("Por favor ingrese una direcci?n de email valida");
		fromMail.focus();

		return false;
	} else {
		if ( checkEmail(fromMail.value) == false ) {
			alert("Por favor ingrese una direcci?n de email valida");
			fromMail.value = '';
			fromMail.focus();

			return false;
		}
	}

	if ( !$Y.Dom.get('sendAvdCopyToMe').checked ) {
		var arToName  = document.getElementsByName('toName');
		var arToEmail = document.getElementsByName('toMail');

		for ( var i = 0; i < arToName.length; i++ ) {
			if ( (i + 1) <= totalEmails ) {
				var toNameEl = arToName[i];

				if ( toNameEl.value.length < 2) {
					alert("Por favor ingrese un nombre valido");
					toNameEl.focus();

					return false;
				}

				var toMailEl = arToEmail[i];

				if ( toMailEl.value.length < 2 ) {
					alert("Por favor ingrese una direcci?n de email valida");
					toMailEl.focus();

					return false;
				} else {
					if ( checkEmail(toMailEl.value) == false ) {
						alert("Por favor ingrese una direcci?n de email valida");
						toMailEl.value = '';
						toMailEl.focus();

						return false;
					}
				}
			}
		}
	}

	var comentarioID = $Y.Dom.get('sendAdvComment');

	if ( comentarioID.value == "Escriba aqu? su mensaje..." ) {
		alert("Por favor ingrese un Comentario valido");
		comentarioID.focus();

		return false
    } else if ( comentarioID.value.length > 1024 ) {
        alert("Su comentario no debe exceder los 1024 caracteres. Por favor ingrese un Comentario valido." );
		comentarioID.focus();

		return false
	} else if ( comentarioID && comentarioID.value == "Escriba aqu? su mensaje..." ) {
		comentarioID.value = "";
	}

	return true;
}

//Ini JABG / 20081017
function enviaSendEmailForm(p_advertiseId, p_addressId, p_keyword)
{
	var result = false;

	try {
		if ( checkSendAdvForm() ) {
			var objForm = document.getElementById('sendEmailForm');
			var inputs  = objForm.getElementsByTagName("input");
			var url     = document.location.toString();

			//JABG - 20100409
			var posExtra= url.indexOf('#content_detalle_servicio');

			if ( posExtra > 0 ) {
				url = url.replace("#content_detalle_servicio", "");
			} else {
				posExtra= url.indexOf('#');

				if ( posExtra > 0 ) {
					url = url.replace("#", "");
				}
			}
			//JABG - 20100409

			var pos     = url.indexOf('?');
			var request = objForm.action+url.substring(pos);

			for ( var i = 0; i < inputs.length; i++ ) {
				if ( inputs[i].name != null && inputs[i].name != "" ) {
					request += "&"+inputs[i].name +"="+ escape(inputs[i].value);
				}
			}

			var texts = objForm.getElementsByTagName("textarea");

			for ( var i = 0; i < texts.length; i++ ) {
				if ( texts[i].name != null && texts[i].name != "" ) {
					request += "&"+texts[i].name +"="+ escape(texts[i].value);
				}
			}

			loadSendAdvUrl(request, 'popupContainer');

			result = true;
		}
	} catch(e) {
		result = false;
	}

	return result;
}

function loadSendAdvUrl(pUrl, pDivId) {
    $Y.Dom.get(pDivId).innerHTML = "";
    $Y.Dom.setStyle('popupBoxLoading', 'display', 'block');

	var callback = {
		success: function(o){
            $Y.Dom.get(pDivId).innerHTML = '<div align="center" ><div id="popupMsg" style="background:#ffff01;">'
                + o.responseText
		        +'<div onclick="closePopup();" class="divSentImgClose" align="center" ><img src="images/btnCerrarTexto.jpg" alt="X"/></div>'
	            +'</div></div>'
		    onLoadPopup();
		},
		failure:function(o){
			$Y.Dom.get(pDivId).innerHTML = '<div style="position:absolute;margin-right:15px;top:5px;text-align:right;z-index:150000; width:98%;">'
				+'<a href="#" onclick="closePopup()" ><img src="images/btnCerrar.jpg" alt="Cerrar"  /></a></div>'
            	+'<div align="center"><div id="popupMsg" style="background:#ffff01;">'
                +'Por el momento este servicio no se encuentra disponible. Por favor, intente de nuevo en un momento. Gracias.'
		        +'<div onclick="closePopup();" class="divSentImgClose" align="center" ><img src="images/btnCerrarTexto.jpg" alt="X"/></div>'
	            +'</div></div>'
		    onLoadPopup();
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('POST', pUrl, callback);
}

function onLoadPopup() {
	$Y.Dom.setStyle('popupBoxLoading', 'display', 'none');
}


//Fin JABG / 20081017*/
/* FIN Req. M20100474 / cfveliz */
//JABG - 20100419
function obtieneRequest(dato1, dato2) {
	var objForm = document.getElementById("form-envio2");
	var inputs  = objForm.getElementsByTagName("input");
	var texts   = objForm.getElementsByTagName("textarea");
	var request = "catalogChangePedido.do?deItemChoose="+dato1+"&flElimina="+dato2;

	for ( var i = 0; i < inputs.length; i++ ) {
		if ( inputs[i].name != null && inputs[i].name != "" ) {
			request += "&"+inputs[i].name +"="+ escape(inputs[i].value);
		}
	}

	for ( var i = 0; i < texts.length; i++ ) {
		if ( texts[i].name != null && texts[i].name != "" ) {
			request += "&"+texts[i].name +"="+ escape(texts[i].value);
		}
	}

	return request;
}


function validaNumero(e) {
	var tecla = (document.all)?e.keyCode:e.which;

	if ( ( tecla != 0 && tecla != 8 ) && tecla < 45 || tecla > 57 ) {
		return false;
	} else {
		return true;
	}
}

//JABG - 20100614
function cargaData(advertiseId, coItem, deItem) {
	document.getElementById("desItemAux").value    = deItem;
	
	/* INICIO Req. S20100079 / cfveliz */
	var nombreObj = document.getElementById("nombre");
	var empresaObj = document.getElementById("empresa");
	var telefonoObj = document.getElementById("telefono");
	var emailObj = document.getElementById("email");
	var comentarioObj = document.getElementById("comentario");
	if (nombreObj != null && empresaObj != null && telefonoObj != null && emailObj != null && comentarioObj != null) {
		document.getElementById("nombreAux").value     = nombreObj.value;
		document.getElementById("empresaAux").value    = empresaObj.value;
		document.getElementById("telefonoAux").value   = telefonoObj.value;
		document.getElementById("emailAux").value      = emailObj.value;
		document.getElementById("comentarioAux").value = comentarioObj.value;
	}
	/* FIN Req. S20100079 / cfveliz */

	document.forms["form-producto"].method = "POST";
	document.forms["form-producto"].action = "catalog.do?advertiseId="+advertiseId+"&coditemChoose="+coItem+"#content_detalle_servicio";
	document.forms["form-producto"].submit();
}

function verCatalogo(advertiseId, coItem, deItem) {
	document.getElementById("flElimina").value = "N";

	cargaData(advertiseId, coItem, deItem);
}

function addItem(advertiseId, coItem, deItem) {
	var pedidoAux = document.getElementById("pedidoAux").value;

	if ( pedidoAux == null || pedidoAux == "" ) pedidoAux = "0";

	if ( pedidoAux.indexOf(coItem) != -1 ) return;

	if ( pedidoAux == "0" ) {
		document.getElementById("pedidoAux").value = coItem;
	} else {
		document.getElementById("pedidoAux").value = pedidoAux + " " + coItem;
	}

	document.getElementById("flElimina").value = "N";

	cargaData(advertiseId, coItem, deItem);
}

function delPedido(advertiseId, coItem, deItem, coItemChoose) {
	var pedidoAux = document.getElementById("pedidoAux").value;

	if ( pedidoAux == null || pedidoAux == "" ) pedidoAux = "0";

	if ( pedidoAux == 0 ) return;

	var pos = pedidoAux.indexOf(coItem);

	if ( pos != -1 ) {
		pedidoAux = pedidoAux.replace(coItem, "");
		pedidoAux = pedidoAux.replace("  ", " ");
		document.getElementById("pedidoAux").value = pedidoAux;
	}

	document.getElementById("flElimina").value    = "S";
	document.getElementById("coItemChoose").value = coItem;
	document.getElementById("deItemChoose").value = deItem;

	cargaData(advertiseId, coItemChoose, deItem);
}
//JABG - 20100614
Require.isLoaded['catalog'] = true;

//Ini JABG / 20081010
var l_clickedObject = null;
var l_listSize = '2';
var vmMsgInitial = "";

function changeEmail(p_object, p_value) {
	l_clickedObject = p_object;
	var i = 0;
	var tempContact = $Y.Dom.get('contacto'+i);

	while(tempContact != null && tempContact != undefined) {
		tempContact.className = 'contacto-out';
		i++;
		tempContact = $Y.Dom.get('contacto'+i);
	}
	p_object.className = 'contacto-sel';

	// trocando os valores
	$Y.Dom.get('ctcEmailTo').value = p_value;
}

function changeBorderOver(p_object) {
	if(p_object.className != "contacto-sel") {
		p_object.className = 'contacto-over';
	}
}

function changeBorderOut(p_object) {
	if(p_object.className != "contacto-sel") {
		p_object.className = 'contacto-out';
	}
}

/**
 * Limpa os dados do form. 
 * Gambis para no utilizar o input reset
 */
function limpaForm() {
	document.getElementById('contactoForm').reset();

	var comment = document.getElementById('ctcComentario');

	if ( $Y.Dom.hasClass(comment, "textareaOn") ) {
		$Y.Dom.replaceClass(comment, 'textareaOn', 'textareaOff');
	}

	return false;
}

/**
 * Faz o envio via ajax, por isso no pode utilizar o action do form
 */
function enviaForm() {
	var result = false;

	try {
		if ( checkVMContactForm() ) {
			if ( $Y.Dom.get('ctcComentario').value == "Escriba aqu&iacute; el mensaje...") {
				$Y.Dom.get('ctcComentario').value = "";
			}

			var objForm = document.getElementById('contactoForm');
			var inputs  = objForm.getElementsByTagName("input");
			var request = objForm.action+"?";

			for ( var i = 0; i < inputs.length; i++ ) {
				if ( inputs[i].name != null && inputs[i].name != "" ) {
					request += "&"+inputs[i].name +"="+ escape(inputs[i].value);
				}
			}

			var selects = objForm.getElementsByTagName("select");

			for ( var i = 0; i < selects.length; i++ ) {
				if ( selects[i].name != null && selects[i].name != "" ) {
					request += "&"+selects[i].name +"="+ escape(selects[i].value);
				}
			}

			var texts = objForm.getElementsByTagName("textarea");

			for ( var i = 0; i < texts.length; i++ ) {
				if (texts[i].name != null && texts[i].name != "" ) {
					request += "&"+texts[i].name +"="+ escape(texts[i].value);
				}
			}

			$Y.Dom.get('contactenos_int_form').style.display = 'none';

			loadVMContactUrl(request, 'contactenos_int_mail');

			result = true;
		}
	} catch(e) {
		result = false;
	}

	return result;
}

/*M20090478 - JABG 20091216*/
function enviaFormMail(idContForm, idContEmail, idForm) {
	var result = false;

	try {
		var objForm = document.getElementById(idForm);
		var inputs  = objForm.getElementsByTagName("input");
		var request = objForm.action+"?";

		for ( var i = 0; i < inputs.length; i++ ) {
			if ( inputs[i].name != null && inputs[i].name != "" ) {
				request += "&"+inputs[i].name +"="+ escape(inputs[i].value);
			}
		}

		var selects = objForm.getElementsByTagName("select");

		for ( var i = 0; i < selects.length; i++ ) {
			if ( selects[i].name != null && selects[i].name != "" ) {
				request += "&"+selects[i].name +"="+ escape(selects[i].value);
			}
		}

		var texts = objForm.getElementsByTagName("textarea");

		for ( var i = 0; i < texts.length; i++ ) {
			if ( texts[i].name != null && texts[i].name != "" ) {
				request += "&"+texts[i].name +"="+ escape(texts[i].value);
			}
		}

		$Y.Dom.get(idContForm).style.display = 'none';

		loadEnviaMailUrl(request, idContEmail);

		result = true;
	} catch(e) {
		result = false;
	}

	return result;
}

function loadEnviaMailUrl(pUrl, pDivId) {
	$Y.Dom.get(pDivId).style.display = 'block';

    var callback = {
    	success: function(o){
            $Y.Dom.get(pDivId).innerHTML = o.responseText
            /* INICIO Req. M20100416 / cfveliz */
            // no se necesita
            /*jQuery("#form-envio").validate({
        		rules: {
        			nombre1: "required",
        			nombreempresa1: "required"
        		},
        		messages: {
        			nombre1: "* Por favor llene este campo",
        			nombreempresa1: "* Por favor llene este campo"
        		},
        		highlight: function(element) {
        		    jQuery("span.status").css({ display:"none" });
        		 	jQuery("span.error").css({ display:"block" });
        			jQuery('#form-envio input').addClass('error');
        	  	}
        	});

            jQuery("#btnenviar").bind("click", function(){
        		if ( jQuery("#form-envio").valid() ) {
        			enviaFormMail("contenvia", "enviado", "form-envio");
        		} else {
        			return;
        		}
        	});*/
            /* FIN Req. M20100416 / cfveliz */
		},
		failure:function(o){
			$Y.Dom.get(pDivId).innerHTML = o.responseText
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('GET', pUrl, callback);
}

function backForm(idContForm, idContEmail, idForm) {
	$Y.Dom.get(idContForm).style.display  = 'block';
	$Y.Dom.get(idContEmail).style.display = 'none';

	resetFormMail(idForm);
}

function resetFormMail(idForm) {
	document.getElementById(idForm).reset();

	//Esto no es la idea pero ya estaba con los tiempos
	if ( idForm.trim() == "form-envio2" ) {
		//JABG - 20100419
		//var divPedido = '<ul id="agregalista" style="height:100px; width:175px;"><table id="tblSample"><thead></thead><tbody></tbody></table></ul>';
		var divPedido = '<form id="form-envio2" action="catalogContactoEmail.do" method="post">' +
	                    '<ul id="form-part2">' +
	                    '<li>' +
						'<label class="text" for="nombre">Nombre completo</label>' +
						'<input id="nombre" name="nombre" class="cajatexto2" type="text" value=""/>' +
						'<input id="contacto" name="contacto" type="hidden" value=""/>' +
						'<input id="advertiseId" name="advertiseId" type="hidden" value=""/>' +
						'</li>' +
						'<li>' +
						'<label class="text">Nombre de tu empresa</label>' +
						'<input id="empresa" name="empresa" class="cajatexto2" type="text" value=""/>' +
						'<input id="companyName" name="companyName" type="hidden" value=""/>' +
						'<span class="status2">(opcional)</span>' +
						'</li>' +
						'<li>' +
						'<label class="text">Tel?fono</label>' +
						'<input id="telefono" name="telefono" class="cajatexto2" type="text" value="" onkeypress="return validaNumero(event)"/>' +
						'<input id="status" name="status" type="hidden" value=""/>' +
						'<span class="status2">(opcional)</span>' +
						'</li>' +
						'<li>' +
						'<label class="text">Email</label>' +
						'<input id="email" name="email" class="cajatexto2" type="text" value=""/>' +
						'<input id="coAviso" name="coAviso" type="hidden" value=""/>' +
						'<input id="totalIdProd" name="totalIdProd" type="hidden" value="0"/>' +
						'</li>' +
						'<li>' +
						'<label class="text">Productos o servicios de inter&eacute;s</label>' +
						'<div id="pedido">' +
						'<ul id="agregalista" style="height:100px; width:175px;">' +
						'<table id="tblSample">' +
						'<thead></thead>' +
						'<tbody></tbody>' +
						'</table>' +
						'</ul>' +
						'</div>' +
						'</li>' +
						'<li>' +
						'<label class="text">Escribe tu comentario</label><textarea id="comentario" class="cajaarea" type="text" name="comentario"/></textarea>' +
						'</li>' +
						'<li><a href="javascript:;" id="btnenviar2" class="btnenvialo2"></a></li>' +
						'<input id="totalRegistro" name="totalRegistro" type="hidden" value=""></input>' +
						'</ul>' +
						'</form>'

		$Y.Dom.get("pedido").innerHTML = divPedido;

		jQuery("#form-envio2").validate( {
			rules: {
				nombre: "required",			
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				nombre: "* Por favor llene este campo",			
				email: "* Por favor ingrese un mail valido"
			}
		} );

		jQuery("#btnenviar2").bind("click", function() {
			if ( jQuery("#form-envio2").valid() ) {
				enviaFormMail("contformdercata", "msgenviado", "form-envio2");
			} else {
				return;
			}
		});
		//JABG - 20100419
	}
}

function changeImage(status, advertiseId, item) {
	var request = "catalogChangeProduct.do?";

	request += "status="+status+"&advertiseId="+advertiseId+"&coditemChoose="+item+"#content_detalle_servicio";

	loadEnviaMailUrl(request, "changeprod");
}
/*M20090478 - JABG 20091216*/

function loadVMContactUrl(pUrl, pDivId) {
	$Y.Dom.get(pDivId).style.display = 'block';

	/*M20090478 - JABG 20091216*/
    //$Y.Dom.get(pDivId).innerHTML = '<div class="contactoMsg"><img src="images/carregando.gif" alt="cargando..." /></div>';
    $Y.Dom.get(pDivId).innerHTML = '<div><img src="images/carregando.gif" alt="cargando..." /></div>';

    var callback = {
		success: function(o){
    		/*M20090478 - JABG 20091216*/
    		//$Y.Dom.get(pDivId).innerHTML = '<div class="contactoMsg">'
            $Y.Dom.get(pDivId).innerHTML = '<div>'
                + o.responseText
	            +'</div>'
		},
		failure:function(o){
			/*
            $Y.Dom.get(pDivId).innerHTML = '<div class="contactoMsg">'
            	+'Por el momento este servicio no se encuentra disponible. Por favor, intente de nuevo en un momento. Gracias.'
            	+'<a href="">Volver al formulario</a>'
	            +'</div>'
	        */
			/*M20090478 - JABG 20091216*/
			//$Y.Dom.get(pDivId).innerHTML = '<div class="contactoMsg">'
			$Y.Dom.get(pDivId).innerHTML = '<div>'
                + o.responseText
	            +'</div>'
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('GET', pUrl, callback);
}

function f_back_form(pLimpia) {
	$Y.Dom.get('contactenos_int_form').style.display = 'block';
	$Y.Dom.get('contactenos_int_mail').style.display = 'none';

	if ( pLimpia == 'S' ) limpaForm();
}

/**
 * Apaga o conteudo da mensagem de contato
 * @param {Object} msg
 */
function msgIn() {
	var obj = document.getElementById("ctcComentario");
	if(vmMsgInitial == "") {
		vmMsgInitial = obj.value;
	}
	if(obj.value == vmMsgInitial) {
		obj.value = "";
		
		$Y.Dom.replaceClass(obj, 'textareaOff', 'textareaOn')
	}
}

/**
 * Coloca o valor inicial na mensagem de contato
 * @param {Object} msg
 */
function msgOut(obj) {
	if(obj.value == "" && vmMsgInitial != "") {
		$Y.Dom.replaceClass(obj, 'textareaOn', 'textareaOff')
		obj.value = vmMsgInitial;
	}
}

/**
 * Script retirado de
 * http://guia.com.pe/contactanos.asp
 */
function checkVMContactForm() {
	var formObj = document.getElementById('contactoForm');
	
	var nombreID = document.getElementById('ctcName');
	if (!nombreID || nombreID.value.length<2) {
		alert("Por favor ingrese un nombre valido");
        nombreID.focus();
		return false;
	}

	var telefonoID = $Y.Dom.get('ctcPhone');
	if (!telefonoID || telefonoID.value.length<2) {
		//no hay telefono, ver si hay email antes de dar alerta
		var emailID2 = $Y.Dom.get('ctcEmailFrom');
		if (!emailID2 || emailID2.value.length<2) {
			alert("Por favor ingrese un Telfono o e-Mail valido");
			telefonoID.focus();
			return false;
		}
	}

	//email es obligatorio para todos!
	var emailID = $Y.Dom.get('ctcEmailFrom');
	if (!emailID || emailID.value.length<2) {
		alert("Por favor ingrese una direccin de email valida");
		emailID.focus();
		return false
	} else {
		/*if (checkEmail(emailID.value)==false) {
			alert("Por favor ingrese una direccin de email valida");
			emailID.value="";
			emailID.focus();
			return false
		}*/
	}

	var comentarioID = $Y.Dom.get('ctcComentario');
	if (!comentarioID || comentarioID.value===vmMsgInitial) {
		alert("Por favor ingrese un Comentario valido");
		comentarioID.focus();
		return false
    } else if (comentarioID.value.length > 1024) {
        alert("Su comentario no debe exceder los 1024 caracteres. Por favor ingrese un Comentario valido.");
		comentarioID.focus();
		return false
	} else if(comentarioID && comentarioID.value == "Escribir aqu el mensaje...") {
			comentarioID.value = "";
	}
	return true;
 }
//Fin JABG / 20081010
Require.isLoaded['vmContacto'] = true;

/* INICIO Req. M20100526 /cfveliz */

//var ende_id = '';

function getMap( p_object, p_advertiseId, p_addressId ) {
	var pars = '?zoomLevel=6&width=400&height=300&urlImage=2';

	if ( p_advertiseId ) {
		pars += '&anun_id='+ p_advertiseId;
	}
	
	if ( p_addressId ) {
		pars +='&ende_id='+p_addressId;
	}

	var url = 'viewMoreProxyAction.do';

	var container;

	if ( typeof(p_object) != 'undefined' && p_object != null )
		container = $Y.Dom.get(p_object);
	else
		container = $Y.Dom.get('getMap');

	if ( typeof(container) == 'undefined' || container == null ) return;

	container.innerHTML = '<br /><br /><br /><br /><br /><br /><br /><br />' + xmlLoadingHTML ;
	
	//ende_id = p_addressId ;
	
	var callback = { success: loadImgMap };
	$Y.Connect.asyncRequest('POST', url + pars, callback);
}

function loadImgMap( request ) {
	var responseJSON = JSON.parse(request.responseText);
	var urlImagen = responseJSON.urlImagen;
	//alert("urlImagen: "+urlImagen);
	var X = responseJSON.X;
	var Y = responseJSON.Y;
	var mapService = responseJSON.mapService;
	var calle = responseJSON.calle;
	var numero = responseJSON.numero;
	var barrio = responseJSON.barrio;
	
	var oElement = $Y.Dom.get('getMap');
	oElement.innerHTML = '<img id="mapa" src="' + urlImagen + '" style="width:285px; height:262px; cursor:pointer" />';
	$Y.Event.removeListener(oElement, "click");
	$Y.Event.addListener(oElement, "click", function(e) {
		openMapa(mapService, X, Y, calle, numero, barrio);
	});
}

function openMapa(p_mapService, l_longitude, l_latitude, calle, numero, barrio) 
{
	//if (ende_id!='')
		//window.open(p_mapService + 'default.asp?ende_id='+ende_id+'&E=1&nivel=6', '_blank');	//'_parent' JABG - 20100225
	window.open(p_mapService + 'default.asp?X='+l_longitude+'&Y='+l_latitude+'&calle='+calle+'&numero='+numero+'&barrio='+barrio, '_blank');
}
/* FIN Req. M20100526 /cfveliz */

/*M20090478 - JABG 20100119*/
function loadMapa(advertiseId, addressId, status, row, changeDiv) {
	if ( changeDiv == "S" ) {
		changeMapa(advertiseId, addressId, row, status);
	} else {
		getMap('getMap', advertiseId, addressId);
	}
}

function changeMapa(advertiseId, addressId, row, status) {
	var request = "viewMoreAddressChange.do?";

	request += "status="+status+"&advertiseId="+advertiseId+"&addressId="+addressId;

	loadAddressUrl(request, "direcciontelefono", advertiseId, addressId, row);
}

function loadAddressUrl(pUrl, pDivId, pAdvertiseId, pAddressId, row) {
	var callback = {
    	success: function(o){
    		$Y.Dom.get(pDivId).innerHTML = o.responseText

    		jQueryDireccion();

	    	var obj = document.getElementById("vmPlano"+row);

	    	$Y.Dom.addClass(obj, 'detalle_direccion_hover_click')

	    	getMap('getMap', pAdvertiseId, pAddressId);
		},
		failure:function(o){
			$Y.Dom.get(pDivId).innerHTML = o.responseText
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('GET', pUrl, callback);
}
/*M20090478 - JABG 20100119*/

/* INICIO Req. M20100673 / cfveliz */
/*M20100599 - JABG - 20101111*/
function loadMapaGoogle(advertiseId, addressId, status, row, changeDiv, url) {
	changeMapaGoogle(advertiseId, addressId, row, status, url);
}

function changeMapaGoogle(advertiseId, addressId, row, status, url) {
	var request = "viewMoreAddressGoogleChange.do?";

	request += "status="+status+"&advertiseId="+advertiseId+"&addressId="+addressId;

	loadAddressGoogleUrl(request, "direcciontelefono", advertiseId, addressId, row, url);
}

function loadAddressGoogleUrl(pUrl, pDivId, pAdvertiseId, pAddressId, row, url) {
	var callback = {
    	success: function(o){
    		$Y.Dom.get(pDivId).innerHTML = o.responseText

    		jQueryDireccion();

    		var obj = document.getElementById("vmPlano"+row);

    		$Y.Dom.get("contentmapa").innerHTML = '<div class="mapa" id="getMap">' +
    											  '<iframe src="'+url+'" noresize id="ifrm_plano" name="ifrm_plano" frameborder="no" width="98%" height="260"></iframe>' +
    											  '</div>'

	    	$Y.Dom.addClass(obj, 'detalle_direccion_hover_click')
		},
		failure:function(o){
			$Y.Dom.get(pDivId).innerHTML = o.responseText
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('GET', pUrl, callback);
}

function openMapaGoogle(url) {
	window.open(url, '_blank');
}
/*M20100599 - JABG - 20101111*/
/* FIN Req. M20100673 / cfveliz */
Require.isLoaded['vmAddress'] = true;

//Ini JABG / 20081006
var xmlLoadingHTML = '<table class="subbox-loading" style="margin-bottom:20px; width:400px"><tr><td align="center"><img src="images/carregando.gif" alt="" /></td></tr></table>';


function getXmlHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function loadUrl(p_url, p_div_id, p_callback) {
	var l_div = $Y.Dom.get(p_div_id);
	if (l_div == undefined) { return; }

	l_div.innerHTML = xmlLoadingHTML;

	var url = p_url;
	var callback = {
		success: function(o){
			l_div.innerHTML = o.responseText;
			if(p_callback){
				p_callback();
			}
		}, 
		failure: function(o){
			Stage.handleFailure(o);
		}
	}
	$Y.Connect.asyncRequest('GET', url, callback);
	
}

function loadUrlNoDiv(p_url) {
	var l_xmlhttp = getXmlHttpRequest();
	l_xmlhttp.open("POST", p_url, true);
	l_xmlhttp.onreadystatechange = function() {
		// 4 - Concluido (Completed). 
	}
	l_xmlhttp.send(null);
}

function loadMasInfo(p_url, p_div_id) {
	var l_div = $Y.Dom.get(p_div_id);
	if (l_div == undefined) { return; }

	l_div.innerHTML = xmlLoadingHTML;

	var url = p_url;
	var callback = {
		success: function(o){
			l_div.innerHTML = o.responseText;
			//TPI.Certifica('/viewMore/viewMoreInfo.do/');
		},
		failure: function(o){
			Stage.handleFailure(o);
		}
	}
	$Y.Connect.asyncRequest('GET', url, callback);
}

function loadUrlMap(advertiseId, addressId, status){
	$Y.Dom.get('viewMoreContent').innerHTML = xmlLoadingHTML;
	var url = 'viewMoreAddress.do';
	var postdata = 'advertiseId=' + advertiseId + '&status=' + status;
	
	if (addressId){postdata +="&ende_id="+addressId;}
		
	var callback = {
		success: function(o){
			$Y.Dom.get('viewMoreContent').innerHTML = o.responseText;

			if ($Y.Dom.get('addressLatitude').value != '' && $Y.Dom.get('addressLatitude').value != 0 &&
				$Y.Dom.get('addressLongitude').value != '' && $Y.Dom.get('addressLongitude').value != 0) {
				getMap($Y.Dom.get('vmPlano0'), $Y.Dom.get("addressLenght").value, $Y.Dom.get("addressLatitude").value, $Y.Dom.get("addressLongitude").value, advertiseId, addressId);
			} else {
				$Y.Dom.addClass($Y.Dom.get('getMap').parentNode, 'off');
				$Y.Dom.addClass('planoContainer', 'planoContainerNoMap');
			}
			//TPI.Certifica('/viewMore/viewMoreAddress.do/');
		}	
	}
	$Y.Connect.asyncRequest('POST', url, callback, postdata);
}

function loadUrlContact(p_url, p_div_id) {
	var callback = function(o){
		vmMsgInitial = document.getElementById('ctcComentario').value;
		//TPI.Certifica('/viewMore/viewMoreContact.do/');
	}
	loadUrl(p_url, p_div_id, callback);
}

function loadUrlProduct(p_url, p_div_id) {
	var callback = function(o){
		//TPI.Certifica('/viewMore/viewMoreProduct.do/');
	}
	loadUrl(p_url, p_div_id, callback);
}
//Fin JABG / 20081006
Require.isLoaded['xmlHttpRequest'] = true;

function redimensionarImagen(object, anchoReal, altoReal){
	var anchoObjeto = object.width;
	var altoObjeto = object.height;
	var factorAncho = anchoObjeto/anchoReal;
	var factorAlto = altoObjeto/altoReal;
	
	if ( factorAncho > factorAlto && factorAncho > 1 ){
		object.width = anchoReal;
		object.height = Math.round(altoObjeto/factorAncho); 
	}else if ( factorAncho < factorAlto && factorAlto > 1 ){
		object.height = altoReal;
		object.width  = Math.round(anchoObjeto/factorAlto); 
	}	else if (factorAncho == factorAlto && factorAlto >= 1 ){
		object.height = altoReal;
		object.width  = anchoReal; 
	}
}

/* INICIO Req. M20100302 /cfveliz */
/* Usar esta funci?n cuando la imagen no existe para darle dimensiones por defecto */
function redimensionarImagenError(object, anchoReal, altoReal) {
	object.height = altoReal;
	object.width  = anchoReal;
}
/* FIN Req. M20100302 /cfveliz */
Require.isLoaded['imagenes'] = true;


/**
 * Funciones para recomienda este p?gina
 * 
 * Req. M20100474 / cfveliz
 */
function sendAdvertise(advertiseId) {
	var _popup = new Popup ({'url':'viewMoreSendAdvertise.do?advertiseId='+advertiseId, 'width':471, 'height':335}); /* Req. M20100557 / cfveliz */
	_popup.init ();
}

function addToEmail() {
	for (var i = 0; i < 4; i++ ) {
		var el = $Y.Dom.get('sendAdvertiseTo_'+i);
		
		if (typeof (el) == 'undefined') return;
		
		//hago visible el primero que est? oculto
		if ($Y.Dom.hasClass(el, 'off')) {
			$Y.Dom.replaceClass(el, 'off', 'on');
			break;
		}
	}
}

function removeToEmail(rowContainer) {
	var el = $Y.Dom.get(rowContainer);
	
	if (typeof (el) == 'undefined') return;
	
	//oculto el email elegido
	if ($Y.Dom.hasClass(el, 'on')) {
		$Y.Dom.replaceClass(el, 'on', 'off');
	}
}

function checkEmail(value) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
}

function checkSendAdvForm()
{
	var formEl     = $Y.Dom.get('sendEmailForm');
	var fromNameEl = $Y.Dom.get('fromName');

	if ( fromNameEl.value.length < 2 ) {
		alert("Por favor ingrese un nombre valido");
		fromNameEl.focus();

		return false;
	}

	var fromMail = $Y.Dom.get('fromMail');

	if ( fromMail.value.length < 2 ) {
		alert("Por favor ingrese una direcci?n de email valida");
		fromMail.focus();

		return false;
	} else {
		if ( checkEmail(fromMail.value) == false ) {
			alert("Por favor ingrese una direcci?n de email valida");
			fromMail.value = '';
			fromMail.focus();

			return false;
		}
	}

	if ( !$Y.Dom.get('sendAvdCopyToMe').checked ) {
		var arToName  = document.getElementsByName('toName');
		var arToEmail = document.getElementsByName('toMail');

		for ( var i = 0; i < arToName.length; i++ ) {
			var divEl = $Y.Dom.get("sendAdvertiseTo_"+i);
			
			if ($Y.Dom.hasClass(divEl, 'on')) {
				var toNameEl = arToName[i];

				if ( toNameEl.value.length < 2) {
					alert("Por favor ingrese un nombre valido");
					toNameEl.focus();

					return false;
				}

				var toMailEl = arToEmail[i];

				if ( toMailEl.value.length < 2 ) {
					alert("Por favor ingrese una direcci?n de email valida");
					toMailEl.focus();

					return false;
				} else {
					if ( checkEmail(toMailEl.value) == false ) {
						alert("Por favor ingrese una direcci?n de email valida");
						toMailEl.value = '';
						toMailEl.focus();

						return false;
					}
				}
			} else {
				var toNameEl = arToName[i];
				toNameEl.value = '';
				var toMailEl = arToEmail[i];
				toMailEl.value = '';
			}
		}
	}

	var comentarioID = $Y.Dom.get('sendAdvComment');

	if ( comentarioID.value == "Escriba aqu? su mensaje..." ) {
		alert("Por favor ingrese un Comentario valido");
		comentarioID.focus();

		return false
    } else if ( comentarioID.value.length > 1024 ) {
        alert("Su comentario no debe exceder los 1024 caracteres. Por favor ingrese un Comentario valido." );
		comentarioID.focus();

		return false
	} else if ( comentarioID && comentarioID.value == "Escriba aqu? su mensaje..." ) {
		comentarioID.value = "";
	}

	return true;
}

function enviaSendEmailForm(p_advertiseId, p_addressId, p_keyword)

{
	/* req M20110037 william Valer*/

	var result = false;

	try {
		if ( checkSendAdvForm() ) {
			var objForm = document.getElementById('sendEmailForm');
			var varStatus = document.getElementById('statusRecPagina').value;
			var inputs  = objForm.getElementsByTagName("input");
			/* Inicio REQ. M20110376 */
			/*var url     = document.location.toString();
			
			var posExtra= url.indexOf('#');

			if ( posExtra > 0 ) { //quitamos el anchor
				url = url.substring(0, posExtra);
			}
			
			var pos     = url.indexOf('?');
			var request = objForm.action+url.substring(pos);*/
			var request = objForm.action+"?status="+varStatus;
			/* Fin REQ. M20110376 */

			for ( var i = 0; i < inputs.length; i++ ) {
				if ( inputs[i].name != null && inputs[i].name != "" ) {
					request += "&"+inputs[i].name +"="+ escape(inputs[i].value);
				}
			}

			var texts = objForm.getElementsByTagName("textarea");

			for ( var i = 0; i < texts.length; i++ ) {
				if ( texts[i].name != null && texts[i].name != "" ) {
					request += "&"+texts[i].name +"="+ escape(texts[i].value);
				}
			}

			loadSendAdvUrl(request, 'popupContainer');

			result = true;
		}
	} catch(e) {
		result = false;
	}

	return result;


/*fin req. M20110037*/
}

function loadSendAdvUrl(pUrl, pDivId) {
    $Y.Dom.get(pDivId).innerHTML = "";
    $Y.Dom.setStyle('popupBoxLoading', 'display', 'block');

	var callback = {
		success: function(o){
			$Y.Dom.get(pDivId).innerHTML = '<div align="center" ><div id="popupMsg" style="background:#ffff01;">'
                + o.responseText
		        +'<div onclick="closePopup();" class="divSentImgClose" align="center" ><img src="images/btnCerrarTexto.jpg" alt="X"/></div>'
	            +'</div></div>'
		    onLoadPopup();
		},
		failure:function(o){
			$Y.Dom.get(pDivId).innerHTML = '<div style="position:absolute;margin-right:15px;top:5px;text-align:right;z-index:150000; width:98%;">'
				+'<a href="#" onclick="closePopup()" ><img src="images/btnCerrar.jpg" alt="Cerrar"  /></a></div>'
            	+'<div align="center"><div id="popupMsg" style="background:#ffff01;">'
            	/* Inicio REQ. M20110376 */
            	//+'Por el momento este servicio no se encuentra disponible. Por favor, intente de nuevo en un momento. Gracias.'
            	+ o.responseText
            	/* Fin REQ. M20110376 */
		        +'<div onclick="closePopup();" class="divSentImgClose" align="center" ><img src="images/btnCerrarTexto.jpg" alt="X"/></div>'
	            +'</div></div>'
		    onLoadPopup();
			throw new Error('Servicio indisponible. Intente mas tarde.');
		}
	}

	$Y.Connect.asyncRequest('POST', pUrl, callback);
}

function onLoadPopup() {
	$Y.Dom.setStyle('popupBoxLoading', 'display', 'none');
}
Require.isLoaded['recomiendaPagina'] = true;

