//preloadImages
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];}}
}

//swapImgRestore
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//swapImage
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//findObj
function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

//openWin
function openWin(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	//mypage = 'popUp.asp?dpto=5&file='+mypage;
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function getSite() {
	var df_language = getCookie('idioma');
	if (df_language != '') {
		document.location.href='/'+df_language+'/index.html';
	} else {
		return false;
	}
}

function changeCellColor(cell, bgColor) {
	cell.bgColor = bgColor;
	cell.style.cursor = 'pointer';
	cell.style.cursor = 'hand';
}

//GET COOKIE
function getCookie(name) {
	var cookieNameLen = name.length;
	var cLen = document.cookie.length;
	var i = 0;
	var cEnd;
	var myStringToReturn;
	var myStringToReturnLen;
	while (i < cLen) {
		var j = i + cookieNameLen;
		if (document.cookie.substring(i,j) == name) {
			cEnd = document.cookie.indexOf(';',j);
			if (cEnd == -1) {
				cEnd = document.cookie.length;
			}
			myStringToReturn = unescape(document.cookie.substring(j,cEnd));
			myStringToReturnLen = myStringToReturn.length;
			myStringToReturn = myStringToReturn.substring(1,myStringToReturnLen+1);
			return myStringToReturn;
		}
		i++;
	}
	return '';
}	

//SET COOKIE
function setCookie(name, value, days){ //set cookie value
	var expireDate = new Date()
	//set "expstring" to either future or past date, to set or delete cookie, respectively
	var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
	document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

//getDateTime
function getDateTime(fecha, serverTime) {
	if (fecha != "") {
		var datetime = fecha;
	} else {
		//seperate time
		var timeSplit = serverTime.split(" ");
		var weekDay = timeSplit[0].split(",");
		var calendarSplit = timeSplit[1].split("-");
		var clockSplit = timeSplit[2].split(":");
		var initMonth = calendarSplit[1]; 
		var tmonth = '';
		
		if (initMonth == "Jan") {
			tmonth = '01';
		}
		if (initMonth == "Feb") {
			tmonth = '02';
		}
		if (initMonth == "Mar") {
			tmonth = '03';
		}
		if (initMonth == "Apr") {
			tmonth = '04';
		}
		if (initMonth == "May") {
			tmonth = '05';
		}
		if (initMonth == "Jun") {
			tmonth = '06';
		}
		if (initMonth == "Jul") {
			tmonth = '07';
		}
		if (initMonth == "Aug") {
			tmonth = '08';
		}
		if (initMonth == "Sep") {
			tmonth = '09';
		}
		if (initMonth == "Oct") {
			tmonth = '10';
		}
		if (initMonth == "Nov") {
			tmonth = '11';
		}
		if (initMonth == "Dec") {
			tmonth = '12';
		}
		
		//seperate to smaller date info
		var tday = weekDay[0];
		var tdate = calendarSplit[0];
		var tyear =  '20'+calendarSplit[2];
		
		//seperated to final bits
		var thour = clockSplit[0];
		var tminutes = clockSplit[1]; 
		var datetime = tyear+tmonth+tdate;
	}
	return datetime;
}

function setCountry() {
	var selectedCountry = document.countriesForm.countries.value;
	setCookie('selectedCountry', selectedCountry, 1);
	//--alert('1 - SET || selectedCountry = ' + getCookie('selectedCountry'));
	if(selectedCountry == '') {
		alert('\n seleccione su país | escolha seu país \n');
	} else {
		//--ToDo: hacer set en cookie del valor del country seleccionado.
		switch(selectedCountry) {
		case 'Argentina':
			document.location.href = '/ar/';
			break;    
		case 'Uruguay':
			document.location.href = '/ar/';
			break;    
		case 'Paraguay':
			document.location.href = '/ar/';
			break;    
		case 'Brasil':
			document.location.href = '/pt/';
			break;
		default:
			document.location.href = '/es/';
		}		
	}
}

function getSelectedCountry() {
	var selectedCountry = getCookie('selectedCountry');
	//--alert('2 - GET || selectedCountry = ' + selectedCountry);
	var qtyElementsofCountries = document.countriesForm.countries.length;
	for(i=0,j=qtyElementsofCountries; i < j; i++) {
		if(document.countriesForm.countries[i].value == selectedCountry) {
			document.countriesForm.countries[i].selected = true;
		}
	}
}

function submiteNewsForm() {
	var objEmail = document.eNewsForm.email;
	if(objEmail.value == '') {
		alert('\n ingrese su email | ingrese seu email \n');
		objEmail.focus();
	} else {
		document.eNewsForm.submit();
	}
}