// JavaScript Document

function spLoaded() {
	mainCont(0);
}

var page = 0;
function menubar(x) {
	var div = d.getElementById('centerCol');
	var bg;
	
	if( x < 7 )
	{
		var seekItem;
		var seekLink;
		var mItem;
		var mLink;
		seekItem = 'mItem_' + page;
		seekLink = 'mLink_' + page;
		mItem = d.getElementById(seekItem);
		mLink = d.getElementById(seekLink);
		mItem.style.borderBottom = '';
		mLink.style.color = '';
		page = x;
		
		seekItem = 'mItem_' + page;
		seekLink = 'mLink_' + page;
		mItem = d.getElementById(seekItem);
		mLink = d.getElementById(seekLink);
		mItem.style.borderBottom = '4px solid rgb(247, 147, 30)';
		mLink.style.color = 'rgb(247, 147, 30)';
	}
	
	switch(x)
	{
		case 0:
			bg = 'blank';
			break;
		case 1:
			bg = 'qs';
			break;
		case 2:
			bg = 'nl';
			break;
		case 3:
			bg = 'blank';
			break;
		case 4:
			bg = 'blank';
			break;
		case 5:
			bg = 'search';
			break;
		case 6:
			bg = 'cntct';
			break;	
		case 7:
			bg = 'note';
			break;	
	}
	div.style.background = 'transparent url(img/center_' + bg + '_684x414.jpg) no-repeat scroll top left';
}

var mainContObj;
var mainContUrl = 'php/sp_ajax.php';
function mainCont(x) {
	//soundManager.play('menucmd');
	//marianUp(); //formerly on mainContentTxtCallback() ..
	//setCookie('main_cont_txt_file', x, 365);

	menubar(x);
	
	mainContObj = getAjaxObj();
	var mod = 'read';
	var sec = x;

	mainContObj.open('GET', mainContUrl + "?mod=" + mod + "&sec=" + sec, true);
	mainContObj.onreadystatechange = mainContCallback; //callback es una funcin definida x el programador
	mainContObj.send(null);
}

function mainContCallback() {
var obj = mainContObj;
var divId = 'centerCol';
	if(obj.readyState == 4) {
		if(obj.status == 200) {
			if(obj.responseText != '') {
					var x = document.getElementById(divId);
					x.innerHTML = obj.responseText;
			}
		}
	}
}

var nlSubsObj;
var nlSubsUrl = 'php/sp_subs.php';
function nlSubs() {
	//soundManager.play('menucmd');
	
	nlSubsObj = getAjaxObj();
	var f_name = Url.encode(d.subsForm.f_name.value);
	var l_name = Url.encode(d.subsForm.l_name.value);
	var m_adrs = Url.encode(d.subsForm.m_adrs.value);
	var m_host = Url.encode(d.subsForm.m_host.value);

	nlSubsObj.open('GET', nlSubsUrl + "?f_name=" + f_name + "&l_name=" + l_name + "&m_adrs=" + m_adrs + "&m_host=" + m_host, true);
	nlSubsObj.onreadystatechange = nlSubsCallback; //callback es una funcin definida x el programador
	nlSubsObj.send(null);
}

function nlSubsCallback() {
var obj = nlSubsObj;
var divId = 'centerCol'
	if(obj.readyState == 4) {
		if(obj.status == 200) {
			if(obj.responseText != '') {
					var x = document.getElementById(divId);
					if(obj.responseText.match('Gracias'))
						d.getElementById('centerCol').style.background = 'transparent url(img/center_nl-thnx_684x414.jpg) no-repeat scroll top left';
					x.innerHTML = obj.responseText;
			}
		}
	}
}

function inputFocus(x) {
	x.style.border = "3px solid rgb(247, 147, 30)";
}

function inputBlur(x) {
	x.style.border = "1px solid #CCCCCC";
}

function fBtnIn(t) {
	t.style.color = 'rgb(247, 147, 30)';
	t.style.borderBottom = '3px solid rgb(247, 147, 30)';
}

function fBtnOut(t) {
	t.style.color = '';
	t.style.borderBottom = '';
}

//----------------------------------------------------------------------------------------------------------------------------------

function Menu() {
	var self = this;
	this.div = d.getElementById('mainContent');
	
	//test methods
	this.test = 'oa, viejah';
	this.alertSumthin = function() {
		alert(this.test);
	}
	
	//sys methods
	this._getAjaxObj = function() {
		var obj;
		if(w.XMLHttpRequest) { // Firefox, Opera 8.0+, Safari
			obj = new XMLHttpRequest();
		}
		else if(w.ActiveXObject) { // Internet Explorer
			try {
				obj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				obj = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return obj;
	}
}

Menu.prototype.qs = function() {
	this.div.innerHTML = '<div id="sp_qs"></div>';
}

Menu.prototype.nl = function() {
	this.div.innerHTML = '<div id="sp_nl"></div>';
}