function showSearchOptions(type, id, optionContainer, fieldId)
{
	SimpleAJAXCall ( 'index.php?display_options/'+id+'/'+type+'/'+fieldId, ElementStateChanged, 'GET', optionContainer )
}

function showCriterio(number)
{
	SimpleAJAXCall ( 'index.php?user_criteria/'+number, ElementStateChanged, 'GET', 'newCriteria'+number )
}

function previewXls(url, form)
{
	form.action = url;
	form.target = '_blank';
	form.submit();
}

function getPageSize()
{
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	return [myWidth,myHeight];  
}
function setOverlayHeight() 
{
	var div = document.getElementById('TB_overlay');
	var pageSize = getPageSize();
	div.style.height = pageSize[1] + "px";
}

function showOverlay ( )
{
	document.getElementById('TB_overlay').style.display = '';
	setOverlayHeight();
}

function showWindow(windowId)
{
	document.getElementById(windowId).style.display = '';
}

function hideOverlay()
{
	document.getElementById('TB_overlay').style.display = 'none';	
}

function hideWindow(windowId)
{
	document.getElementById(windowId).style.display = 'none';
}

function loadFormLayer ( resp, object )
{
	toggleFlashObjects();
	ElementStateChanged (resp, object );
	showOverlay();
	showWindow(object);
	setOverlayHeight();

}

function closeFormLayer ( object )
{
	toggleFlashObjects();
	hideOverlay();
	hideWindow(object);
}

function verifyText(textareaObject, text)
{
	
	if(textareaObject.value == text)
		textareaObject.value = '';
	
	return true;
}

function cleanInnerHTML(response, elementId)
{
	document.getElementById(elementId).innerHTML = '';
}

function doNothing()
{
	void(0);
}

function displayLoading(elementId)
{
	
	if((typeof document.getElementById(elementId) != 'undefined') && (elementId != ''))
	{
		if(elementId == 'window2')
		{
			showOverlay();
			showWindow(elementId);
		}
		document.getElementById(elementId).innerHTML = '<img src="/images/loading.gif" style="margin:0 auto" />';
	}
}
function toggleFlashObjects()
{
	var elements = document.getElementsByTagName("embed");
	var length   = elements.length;
	for(i=0;i<length;i++)
	{
		if(elements[i].style.display == '')
		{
			elements[i].style.display = 'none';
		}
		else
		{
			elements[i].style.display = ''
		}
	}
}
function switchState(principalObj, secondaryObjId)
{
	principalObj.style.display = 'none';
	document.getElementById(secondaryObjId).style.display = '';
	document.getElementById(secondaryObjId).focus();
}
function saveStates(form, object, enter)
{
	var elements = form.elements;
	for(i=0; i<elements.length; i++)
	{
		if(((elements[i].type == 'text') && (elements[i] != object)) || (enter))
		{
			if(elements[i].title != '')
			{
				document.getElementById('span'+elements[i].title).innerHTML = elements[i].value;
				switchState(elements[i], 'span'+elements[i].title);
				if((enter) && (elements[i] == object))
					SimpleAJAXCall ( 'index.php?country.controller/update/'+elements[i].title+'/'+object.value, doNothing, 'GET', '' );
				
			}
		}
		else
		{
			if(elements[i].type == 'text')
			{
				SimpleAJAXCall ( 'index.php?country.controller/update/'+elements[i].title+'/'+elements[i].value, doNothing, 'GET', '' );
			}
		}
	}
}
function checkEnter(e, form, object){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		saveStates(form, object, true);
	}
}
function submitForm(formId)
{
	document.getElementById(formId).submit();
}
function toggleObject(objectId)
{
	var target = document.getElementById(objectId);
	if(target.style.display == 'none')
		showWindow(objectId);
	else
		hideWindow(objectId);
}
function parseCheckboxes()
{
	var inputs  = document.getElementsByTagName('input');
	var checked = new Array(0, 0);
	var current = 0;
	for(i = 0; i < inputs.length; i++)
	{
		if(inputs[i].type == 'checkbox')
		{
			if(inputs[i].checked == true)
			{
				checked[current] = inputs[i];
				current++;
			}
		}
	}
	if(current >= 2)
	{
		changeCheckboxesState(true);
	}
	else
	{
		changeCheckboxesState(false);	
	}
	return checked;
}
function changeCheckboxesState(state)
{
	var inputs  = document.getElementsByTagName('input');
	var checked = new Array(0, 0);
	for(i = 0; i < inputs.length; i++)
	{
		if(inputs[i].type == 'checkbox')
		{
			if(inputs[i].checked == false)
			{
				inputs[i].disabled = state;
			}
		}
	}
}
function compare(dir)
{
	var checked = parseCheckboxes();
	if((checked[0] != 0) && (checked[1] != 0))
	{
		window.location.href = dir + checked[0].alt + '/' + checked[1].alt + '.html'; 
	}
	else
	{
		alert('Se requieren 2 propiedades para comparar');
	}
}

function otherDepartments(value, extra)
{
	if(!extra)
		extra = '';
	if (value == 'other')
	{
		document.getElementById('departments'+extra).innerHTML = '<br><input class="extended_select01"  type="text" name="department_other" /><a href="javascript:void(0)" onClick="cancelDepartment('+extra+')">[cancelar]</a>';		
		document.getElementById('cities'+extra).innerHTML = '<input class="extended_select01"  type="text" name="city_other" />';
	}
	else if (value != 'NULL')
	{
		SimpleAJAXCall('/geo.controller/departmentChanged2/'+value+'/'+extra+'.html', ElementStateChanged, 'GET', 'cities'+extra);
	}
}

function otherCity(value, extra)
{
	if(!extra)
		extra = '';	
	if (value == 'other')
	{	
		document.getElementById('cities'+extra).innerHTML = '<input class="extended_select01"  type="text" name="city_other" /><a href="javascript:void(0)" onClick="cancelCity('+extra+')">[cancelar]</a>';
	}
}

function cancelDepartment(extra)
{
	if(!extra)
		extra = '';	
	value = document.getElementById('country_id'+extra).value;
	SimpleAJAXCall('geo.controller/countryChanged2/'+value+'/'+extra+'.html', ElementStateChanged, 'GET', 'departments'+extra);
}

function cancelCity(extra)
{
	if(!extra)
		extra = '';	
	value = document.getElementById('department_id'+extra).value;
	SimpleAJAXCall('geo.controller/departmentChanged2/'+value+'/'+extra+'.html', ElementStateChanged, 'GET', 'cities'+extra);
}

function changeImage(url, image)
{
	document.getElementById('imgppl').src = image;
}