
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;

  document.MM_nbOver = nbArr = new Array();
  if (event == "init" && args.length > 2) {
	if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
	  img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
	  if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
	  nbArr[nbArr.length] = img;
	  for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
		if (!img.MM_up) img.MM_up = img.src;
		img.src = img.MM_dn = args[i+1];
		nbArr[nbArr.length] = img;
	} }
  } else if (event == "over") {

	for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
	  if (!img.MM_up) img.MM_up = img.src;
	  img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
	  nbArr[nbArr.length] = img;
	}
  } else if (event == "out" ) {
	for (i=0; i < document.MM_nbOver.length; i++) {
	  img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
	nbArr = document[grpName];
	if (nbArr)
	  for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
	document[grpName] = nbArr = new Array();
	for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
	  if (!img.MM_up) img.MM_up = img.src;
	  img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
	  nbArr[nbArr.length] = img;
  } }
}



function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}


function validateEmail(vfld){
	  var tfld = trim(vfld.value);
	  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/

	  if (tfld == "" || !email.test(tfld)) {
		  return false;
	  }
	  return true;
}

function checkPresent(str){
	if(trim(str) != ''){
		return true;
	}
	return false;
}


function checkLength(mystr, minlenght){
	var str = trim(mystr.value);

	if(str.length >= minlenght){
		return true;
	}
	return false;
}


function openPopup(image_name, image_width, image_height){
	var top = (screen.height - image_height) /2;
	var left = (screen.width - image_width) /2;
	window.open("inc/image_popup.php?file_name="+image_name,"picture","resizable=no, width="+image_width+", 	height="+image_height+", top="+top +", left="+left);
}

function showDialog(name)
{
	var dlgCommon = dojo.widget.byId(name);
	dlgCommon.show();
	hideFlashDivs();
	return true;
}

function hideDialog(name)
{
	showFlashDivs();
	var dlgCommon = dojo.widget.byId(name);
	dlgCommon.hide();
	return true;
}


function hideFlashDivs()
{
	var logo = dojo.byId('logo');
	var news = dojo.byId('news');
	var anim = dojo.byId('anim');
	if (logo != null) logo.style.display="none";
	if (news != null) news.style.display="none";
	if (anim != null) anim.style.display="none";
}

function showFlashDivs()
{
	var logo = dojo.byId('logo');
	var news = dojo.byId('news');
	var anim = dojo.byId('anim');
	if (logo != null) logo.style.display="block";
	if (news != null) news.style.display="block";
	if (anim != null) anim.style.display="block";
}

function show_div(id)
{
	if(document.getElementById(id)){
		document.getElementById(id).style.display ="block";
	}
}

function hide_div(id)
{
	if(document.getElementById(id)){
		document.getElementById(id).style.display ="none";
	}
}

//-------------------------------------------------------------------------------
// Check Browser
function loadBrowserCSS(id, path){

	var theUA = navigator.userAgent.toLowerCase();
	isExplorer = (theUA.indexOf('msie')!=-1);
	var posInicio = theUA.lastIndexOf('msie')+4;
	theversion = parseFloat(theUA.substring(posInicio, posInicio+4));

	if (isExplorer){
		//var link ='<link href="' + path + "styles_ie" + theversion + '.css" rel="stylesheet" type="text/css" id="IE_style" />';
		//document.write(path + "styles_ie" + theversion + '.css');
		/*
		if(document.getElementById(id)){
			document.write('Load Style');
			document.getElementById(id).href = path + "styles_ie"+theversion+".css";
		}
		*/

		var link = document.createElement('link');
		link.href = path + "styles_ie" + theversion + '.css';
		link.rel = 'stylesheet';
		link.type = 'text/css';
		document.getElementsByTagName('head')[0].appendChild(link);

		//document.write(link);
		//alert(document.getElementById(id).href+"::");
	}
}

function showDialog(name)
{
	var dlgCommon = dojo.widget.byId(name);
	if(dlgCommon != null) dlgCommon.show();
	hideFlashDivs();
	return true;
}

function hideDialog(name)
{
	showFlashDivs();
	var dlgCommon = dojo.widget.byId(name);
	if(dlgCommon != null) dlgCommon.hide();
	return true;
}

function changeLocation(form_id, section, action)
{
	eval('document.'+form_id+'.section.value = "'+section+'";');
	eval('document.'+form_id+'.action.value = "'+section+'";');
	eval('document.'+form_id+'.submit();');
	return true;
}

function changeLocationGET(form_id, location)
{
	eval('document.'+form_id+'.action = "'+location+'";');
	eval('document.'+form_id+'.method= "post";');
	eval('document.'+form_id+'.submit();');
	return true;
}


var id_data ="";
function loadData(form_name, id_name, _url)
{

	if(_url=="undefined"){
		var _url = "secure_page_low.php";
	}

	//alert(id_name+"::"+dojo.byId(id_name));
	//document.getElementById(id_name).innerHTML = "Cargando ... ";
	var kw = {
		url: _url,
		sync: true,
		load: function(data){
				//alert("LOAD "+id_name+" :: "+data);
				if(trim(data)!=""){
					document.getElementById(id_name).innerHTML = data;
					//alert("contenido:"+document.getElementById(id_name).innerHTML);
				}
		},
		error: function(data){
				console.debug("A ocurrido un error: ", data);
		},
		timeout: 3000,
		form: form_name
	};
	dojo.xhrPost(kw);

}

 function loadValue(form_name, id_name, _url)
 {
		if(_url=="undefined"){
			var _url = "secure_page_low.php";
		}

		//alert(id_name+"::"+dojo.byId(id_name));
		//document.getElementById(id_name).innerHTML = "cargando ... ";
		var kw = {
			url: _url,
			sync: true,
			load: function(data){
					//alert("LOAD "+id_name+" :: "+data);
					if(trim(data)!=""){
						document.getElementById(id_name).value = data;
						//alert("contenido:"+document.getElementById(id_name).innerHTML);
					}
			},
			error: function(data){
					console.debug("A ocurrido un error: ", data);
			},
			timeout: 2500,
			form: form_name
		};
		dojo.xhrGet(kw);
	}


 function goToSectionAction(section, action, link){
	document.formGeneral.section.value = section;
	document.formGeneral.HID_SiteAction.value = action;
	document.formGeneral.HID_Category.value = "";
	document.formGeneral.HID_Package.value = "";
	document.formGeneral.HID_Product.value = "";
	document.formGeneral.HID_City.value = "";
	document.formGeneral.HID_PageNumber.value = "";
	document.formGeneral.HID_Index.value = "";
	document.formGeneral.action = link;
	document.formGeneral.submit();
	return true;
 }
 
 function viewProduct( product , indice, link, city, page )
 {
    document.formGeneral.section.value = "producto";
    document.formGeneral.HID_SiteAction.value = "";
    document.formGeneral.HID_Product.value = product;
    document.formGeneral.HID_Index.value = indice;
    document.formGeneral.HID_City.value = city;
    document.formGeneral.HID_PageNumber.value = page;
    document.formGeneral.action = link;
    document.formGeneral.submit();

 	return false;
 }
 
 function goToCategory(category_id, link){
	document.formGeneral.section.value = "categoria";
	document.formGeneral.HID_SiteAction.value = "";
	document.formGeneral.HID_Category.value = category_id;
	document.formGeneral.HID_Package.value = "";
	document.formGeneral.HID_Product.value = "";
	document.formGeneral.action = link;
	document.formGeneral.submit();
	return true;
}

 function goToPackage(package_id, link)
 {
    document.formGeneral.section.value = "paquete";
    document.formGeneral.HID_SiteAction.value = "";
    document.formGeneral.HID_Package.value = package_id;
    document.formGeneral.action = link;
    document.formGeneral.submit();
 	return false;
 }
 
 
