// JavaScript Document
var http_request = false;
function createRequest() {
	http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}
	return http_request;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

//invalidate and set popup windows
function makeTransparent( obj, ndx ) { 
	if (obj.style) {		
		if (obj.style.filter !== undefined) 
			obj.style.filter = 'alpha(opacity=' + ndx + ');';
		else {	
			if (obj.style.MozOpacity !== undefined) {			
				obj.style.MozOpacity = '0.' + ndx;
			}
			else {	
				if (obj.style.opacity !== undefined)
					obj.style.opacity = '0.' + ndx;
			}
		}
	}
}

var invDiv = false;
var waitDiv = false;
function invalidate() {
	if (!browserWindowHeight || !browserWindowWidth) 
		_calculateBrowserSize();
		
	if (!invDiv) {
		invDiv = document.createElement('div');
		invDiv.id = 'invalidatorPanel';
		invDiv.style.zIndex = '500';
		invDiv.style.backgroundColor = '#FFFFFF';
		makeTransparent(invDiv, 50);
		invDiv.style.position = 'absolute';
		invDiv.style.top = '0';
		invDiv.style.left = '0';
		if (navigator.userAgent.indexOf('MSIE') != -1) {
			invDiv.style.width = browserWindowWidth + 'px';
			invDiv.style.height = browserWindowHeight + 'px';
		}
		invDiv.style.bottom = '0';
		invDiv.style.right = '0';
	}
	
	document.body.appendChild( invDiv );
}

function revalidate() {
	if (document.getElementById('invalidatorPanel')) 
		document.body.removeChild( document.getElementById('invalidatorPanel') );
}

function setWait() {
	if (!browserWindowHeight || !browserWindowWidth) 
		_calculateBrowserSize();
		
	if (!waitDiv) {
		waitDiv = document.createElement('div');
		waitDiv.id = 'waitWindow';
		waitDiv.style.zIndex = '501';
		waitDiv.style.backgroundColor = '#CCC8B6';
		waitDiv.style.border = '4px solid #FFFFFF';
		makeTransparent(waitDiv, 90);
		waitDiv.style.position = 'absolute';
		waitDiv.style.height = '30px';
		waitDiv.style.width = '200px';
		waitDiv.style.left = ((browserWindowWidth / 2) - 100) + 'px';
		waitDiv.style.top = ((browserWindowHeight / 2) - 15) + 'px';
		
		var tempP = document.createElement('p');
		tempP.style.fontFamilty = 'Arial';
		tempP.style.fontSize = '12px';
		tempP.style.color = '#5D5D5D';
		tempP.style.margin = '7px';
		tempP.style.textAlign = 'center';
		
		tempP.appendChild( document.createTextNode( 'Espere por favor...' ));
		waitDiv.appendChild(tempP);
	}
	
	invalidate();
	document.body.appendChild( waitDiv );
}

function stopWait() {
	if (document.getElementById('waitWindow')) {		
		document.body.removeChild( document.getElementById('waitWindow') );
		revalidate();
	}
}

function dateFormat(date) {
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	if (month < 10)
		month = '0' + String(month);
	var day = date.getDate();
	if (day < 10)
		day = '0' + String(day);
		
	var hour = date.getHours();
	if (hour < 10)
		hour = '0' + String(hour);
	var minutes = date.getMinutes();
	if (minutes < 10)
		minutes = '0' + String(minutes);
	
	return day + '/' + month + '/' + year + ' ' + hour + ':' + minutes;
}

function gotoModel(place) {
	if (document.getElementById('modelGoTo').value) {
		window.location = 'http://www.latinbabes.com.ar/' + place;
	}
}

function selectImage(path, mode) {
	if (mode) {
		document.getElementById('rightPanel').style.display = 'none';
	}
	else {
		document.getElementById('rightPanel').style.display = 'block';
	}
	
	document.getElementById('pictureTarget').setAttribute('src', path);
}

function init() {
	setInterval( 'goSlides()', 1000 );
}

function goSlides() {
	for (var n=0; n < slideshows.length; n++) {
		slideshows[n].curIndex++;
		if (slideshows[n].curIndex > slideshows[n].images.length -1)
			slideshows[n].curIndex = 0;
			
		if (slideshows[n].images[slideshows[n].curIndex])
			document.getElementById(slideshows[n].imgId).setAttribute('src', slideshows[n].images[slideshows[n].curIndex]);
	}
}

function showpopin(e) {
	if (!e)
		e = window.event;
		
	var elem = (e.target) ? e.target : e.srcElement;
	var x, y;
		
	if (e.pageX) {
		x = e.pageX + 16;
		y = e.pageY + 16;
	}
	else {
		if (e.x) {
			x = e.x + document.documentElement.scrollLeft + 16;
			y = e.y + document.documentElement.scrollTop + 16;
		}
		else {
			x = 0;
			y = 0;
		}
	}
	
	var targetDiv = document.getElementById('popInDiv');
	var ndx = Number(elem.id.substr(8));
	while (targetDiv.firstChild)
		targetDiv.removeChild(targetDiv.firstChild);
		
	if (popins[ndx]) {
		var first = true;
		for (var n=0; n < popins[ndx].length; n++) {
			if (first) {
				var str = document.createElement('strong');
				str.appendChild(document.createTextNode(popins[ndx][n]));
				targetDiv.appendChild(str);
			}
			else {
				targetDiv.appendChild(document.createTextNode(popins[ndx][n]));
			}
			first = false;
			targetDiv.appendChild(document.createElement('br'));
		}
	}
	
	targetDiv.style.left = x + 'px';
	targetDiv.style.top = y + 'px';
	targetDiv.style.display = 'block';
	
}

function movepopin(e) {
	if (!e)
		e = window.event;
		
	var elem = (e.target) ? e.target : e.srcElement;
	var x, y;
		
	if (e.pageX) {
		x = e.pageX + 16;
		y = e.pageY + 16;
	}
	else {
		if (e.x) {
			x = e.x + document.documentElement.scrollLeft + 16;
			y = e.y + document.documentElement.scrollTop + 16;
		}
		else {
			x = 0;
			y = 0;
		}
	}
	
	var targetDiv = document.getElementById('popInDiv');
	targetDiv.style.left = x + 'px';
	targetDiv.style.top = y + 'px';
}

function hidepopin(e) {
	document.getElementById('popInDiv').style.display = 'none';
}

function makeTransparent( obj, ndx ) { 
	if (obj.style) {		
		if (obj.style.filter !== undefined) 
			obj.style.filter = 'alpha(opacity=' + ndx + ');';
		else {	
			if (obj.style.MozOpacity !== undefined) {			
				obj.style.MozOpacity = '0.' + ndx;
			}
			else {	
				if (obj.style.opacity !== undefined)
					obj.style.opacity = '0.' + ndx;
			}
		}
	}
}

