//ñ
var n = new String();
n = unescape('%F1');

//á
var a = new String();
a = unescape('%E1');

//é
var e = new String();
e= unescape('%E9');

//í
var i = new String();
i = unescape('%ED');

//ó
var o = new String();
o = unescape('%F3');

//ú
var u = new String();
u = unescape('%FA');

// default font size
var currentSize = new Number();
currentSize = 10;

var aStatus = new Array();
aStatus = [0,0];

var aAllEnDivsID = new Array();
aAllEnDivsID = [
'en-us_01'
,'en-us_02'
,'en-us_03'
,'en-us_04'
,'en-us_05'
,'en-us_06'
];

var aAllEsDivsID = new Array();
aAllEsDivsID = [
'es_01'
,'es_02'
,'es_03'
,'es_04'
,'es_05'
,'es_06'
];

var aAllContactDivsId = new Array();
aAllContactDivsId = [
'en-us_07'
,'es_07'
];

function ChangeMyClass(objWich){
	//Checking DOM compatibility
	if (document.getElementById){
		//Checking if element's class is
		if (objWich.className == 'navCellON') {
			//Changing class acording to mouse event
			objWich.className = 'navCellOFF';
		}
		//Checking if element's class is
		else if (objWich.className == 'navCellOFF') {
			//Changing class acording to mouse event
			objWich.className = 'navCellON';
		}
	}
}

function ShowLink(strURL, strTarget){
	var aWindowsFeatures = new Array(10);
	if (strTarget == undefined){
		strTarget = '_self';
	}
	aWindowsFeatures[0] = 'copyhistory=1';
	aWindowsFeatures[1] = 'directories=1';
	// aWindowsFeatures[2] = 'height=600';
	aWindowsFeatures[3] = 'location=1';
	aWindowsFeatures[4] = 'menubar=1';
	aWindowsFeatures[5] = 'resizable=1';
	aWindowsFeatures[6] = 'scrollbars=1';
	aWindowsFeatures[7] = 'status=1';
	aWindowsFeatures[8] = 'toolbar=1';
	// aWindowsFeatures[9] = 'width=800';
	strTarget = window.open(strURL, strTarget, aWindowsFeatures.join(','));
	//alert(strURL);
}

function noDOM() {
	window.alert('Your internet browser doesn\'t support DOM specification, please try to upgrade as soon as you can to a newer version');
}

function fontSizer(mode){
	if(document.getElementById){
		if (mode == '+'){
			currentSize = currentSize + 2;
			for (i=0;i<document.getElementsByTagName('div').length - 1;i++){
				document.getElementsByTagName('div')[i].style.fontSize = currentSize + 'pt';
			}
		}
		if (mode =='-'){
			currentSize = currentSize - 2;
			for (i=0;i<document.getElementsByTagName('div').length - 1;i++){
				document.getElementsByTagName('div')[i].style.fontSize = currentSize + 'pt';
			}
		}
		if (mode ==null){
			currentSize = 10;
			for (i=0;i<document.getElementsByTagName('div').length - 1;i++){
				document.getElementsByTagName('div')[i].style.fontSize = currentSize + 'pt';
			}
		}
	}else{
	noDOM();
	}
}

function areGrpSameVisibility(Element){
	var aGroups = [aAllEnDivsID,aAllEsDivsID];
	function getGroup(myElement) {
		for(i=0;i<aGroups.length;i++){
			//alert(aGroups[i].length);
			for(j=0;j<aGroups[i].length;j++){
				//alert(myElement.id + ":"+ aGroups[i][j]);
				if (myElement.id == aGroups[i][j]){
					//alert(ElementID.id + ":"+ aGroups[i][j] + ":"+ aGroups[i]);
					return i;
					break;
				}
			}
		}
		return null
	}
	var groupIndex = getGroup(Element);
	if (groupIndex!=null){
		//alert(aGroup.length);
		var myCounter=0;
		for(k=0;k<aGroups[groupIndex].length;k++){
			tmpElementID = document.getElementById(aGroups[groupIndex][k]);
			//alert(aGroup[k] + ":"+ tmpElementID.style.display  + " compare with"+ Element.id);
			if(tmpElementID.style.display == Element.style.display){
				myCounter=myCounter+1;
			}
		}
		//alert(myCounter);
		if(myCounter==aGroups[groupIndex].length){
			var action = null;
			if (Element.style.display =='block'){
				action = 0;
			}else{
				action = 1;
			}
			//alert(action + ":"+aStatus[groupIndex]);
			if (action != aStatus[groupIndex]){
				BulkChngVisibility(aGroups[groupIndex],1,groupIndex);
				if (groupIndex == 0) toggleText('visibleSections','Expand Tabs','Collapse Tabs');
				if (groupIndex == 1) toggleText('visibleSecciones','Expandir Pesta' + n + 'as','Colapsar Pesta' + n + 'as');
			}
		}else{
		}
	}
}

function ChangeVisibilityOf(ElementID){
	if (document.getElementById){
		ElementID = document.getElementById(ElementID);
		//alert(ElementID.id + ":" + ElementID.style.display);
		if (ElementID.style.display != 'none') {
			ElementID.style.display = 'none';
		}
		else {
			ElementID.style.display = 'block';
		}
		areGrpSameVisibility(ElementID);
	}
}

function toggleText(ElementID, text_01, text_02){
	if (document.getElementById){
		ElementID = document.getElementById(ElementID);
		//alert(ElementID.firstChild.nodeValue);
		if (ElementID.firstChild.nodeValue == text_01){
			ElementID.firstChild.nodeValue = text_02;
		}else{
			ElementID.firstChild.nodeValue = text_01;
		}
	}
}

function BulkChngVisibility(aDivsID,mode,indexStatus){
	//alert(nextAction + ":" + siguienteAccion);
	if (document.getElementById){
		for(i=0 ; i < aDivsID.length; i++){
			ElementID = document.getElementById(aDivsID[i])
			//In 'mode = 0' toggles element's visibility individually
			if (mode == 0){
				if (ElementID.style.display != 'none') {
					ElementID.style.display = 'none';
				}else {
					ElementID.style.display = 'block';
				}
			}
			//In 'mode = 1' set element's visibility to a certain value even if is already in that value
			if (mode == 1){
				//alert(myAction);
				if (aStatus[indexStatus] == 1) {
					ElementID.style.display = 'block';
				}else {
					ElementID.style.display = 'none';
				}
			}
		}
		if (mode == 1){
			if (aStatus[indexStatus] == 1){
				aStatus[indexStatus] = 0;
			}else{
				aStatus[indexStatus] = 1;
			}
		//alert(indexStatus + ":" + aStatus[indexStatus]);
		}
	}
}


var WindowImage;

function ShowImage(ImageName, MyWindow_Width, MyWindow_Height) {
	if (typeof(WindowImage) == 'object') {
		WindowImage.close();
	}
	WindowImage = open('ShowImage.aspx?src=' + ImageName,'WindowImage', 'resizable=1,scrollbars=1,height=' + MyWindow_Height + ',width=' + MyWindow_Width);
	WindowImage.resizeTo(MyWindow_Width, MyWindow_Height);
	WindowImage.focus();
}


function createMap(ElementID){
	if (document.getElementById){
		var map = new GMap(document.getElementById(ElementID));
		map.setMapType(G_MAP_TYPE);
		//map.setMapType(G_SATELLITE_TYPE);
		//map.setMapType(G_HYBRID_TYPE);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		var myAddr = new GPoint(-106.62891,35.083605);
		var myFormerAddr = new GPoint(-66.8565,10.46735);
		var myCtr = new GPoint(-106.6315,35.0845);
		map.centerAndZoom(myCtr, 2);
		//map.centerAndZoom(myFormerAddr,-1);
	
		var myMarker_01 = new GMarker(myAddr);
		var myHtml_01 = '<div><b>Sandia Bytes</b><br />1516 Tijeras Ave, NE<br />Suite 34<br />Albuquerque, NM 87106-4565</div>';
		GEvent.addListener(myMarker_01, 'click', function() {
			myMarker_01.openInfoWindowHtml(myHtml_01);
		});
		map.addOverlay(myMarker_01);
		var myMarker_02 = new GMarker(myFormerAddr);
		map.addOverlay(myMarker_02);
	}
}

var myControl;

function mapAnimate(){
	if (document.getElementById){
		if (map.getZoomLevel() >= 3){
			map.centerAndZoom(myCtr, map.getZoomLevel()-1);
			//currentZoom = currentZoom - 1;
			window.setTimeout(mapAnimate, 3000);
		} else{
		if (myControl != "undefined"){
			myControl = new GSmallMapControl();
			map.addControl(myControl);
			map.addControl(new GMapTypeControl());
		}
		}
	}
}

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	if (document.getElementById){
		BulkChngVisibility(aAllEnDivsID,1,0);
		BulkChngVisibility(aAllEsDivsID,1,1);
		BulkChngVisibility(['controls','controles'],0,null);
		createMap('map2');
		createMap('map');
		toggleText('visibleLang','Espa' + n + 'ol','&nbsp;');
	}else{
		noDOM();
	}
};

/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, null);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script defer src=JavaScript/ie_onload.js><"+"/script>");
/*@end @*/

/* for other browsers */
window.onload = init;

function translate(){
	//Show translated main context
	BulkChngVisibility(['en-us','es'],0,null);
	//Translate details of the interfase
	toggleText('visibleLang','Espa' + n + 'ol','English');
	toggleText('myIP','Mi IP','My IP');
}

function myLoader(){
	//Hide elements after load
	BulkChngVisibility(aAllContactDivsId,0,null);
	//Includes elements that need to be loaded first
	aAllEnDivsID[aAllEnDivsID.length] = aAllContactDivsId[0];
	aAllEsDivsID[aAllEsDivsID.length] = aAllContactDivsId[1];
	ChangeVisibilityOf('es');
}
