// JavaScript Document
function openLink(thefile, querystring, contentlayer, themethod, theEvalscripts) {
	var theoptions = querystring.split("|");
	var dofunction = 0;
	var after = "nofunction()";
	thequerystring = theoptions[0];
	if (theoptions.length > 1) {
		after = theoptions[1];
		dofunction = 1;
	}
	if ((!thefile) || (thefile == '')) {
		thefile = "content.php";	
	}
	if(!after) {
		dofunction =0;
		after = "nofunction()";
	}
	if(!theEvalscripts) {
		var theEvalscripts = false;
	}
	if (!contentlayer) {
		var contentlayer = 'contenttext';
	}
	if (!themethod) {
		var themethod = "get";
	}
	var thecontentlayer = document.getElementById(contentlayer);
	if (querystring != "0") {
		thecontentlayer.innerHTML = '<div class="wrapper"><div class="main"><div class="indent"><div class="w100 h100"><div class="column"><div class="box"><div class="side_top"><div class="left_top"><div class="right_top"><div class="boxcontent"><div align="center"><img src="images/spinner.gif" width="50" height="50" align="absmiddle" />Cargando...</div> </div></div></div></div></div></div><div class="clear"></div></div></div></div><!--content end--></div>';
		var pars = thequerystring;
		var ajax = new Ajax.Updater({success: contentlayer},thefile,
									{
										method: themethod, 
										parameters: pars, evalScripts:theEvalscripts, asynchronous:true, 
										onComplete: function() {
											if (dofunction != 0) {eval(after);}
										}
									});
	}
}
function nofunction() {
	return true;	
}
function submitForm(tposturl, tpars, tmethod, tsuccessmessage, tfailuremessage, tredirecturl, tredirectquerystring, contentlayer, themethod, tresultdiv) {
	if (!contentlayer) {
		var contentlayer = 'contenttext';
	}
	if (!themethod) {
		var themethod = "get";
	}
	if (!tresultdiv) {
		var resultdiv = document.getElementById('result');
		var resultstr = 'result';
	} else {
		var resultdiv = document.getElementById(tresultdiv);
		var resultstr = tresultdiv;
	}
	if (!tredirecturl) {
		var tredirecturl = 'dummy';	
	}
	var theoptions = tpars.split("|");
	var dofunction = 0;
	var after = "nofunction()";
	thequerystring = theoptions[0];
	if (theoptions.length > 1) {
		after = theoptions[1];
		dofunction = 1;
	}
	
	
	var theaj = new Ajax.Request(tposturl, {
		method: tmethod, parameters: thequerystring, 
		onSuccess: function(transport) {
			if (transport.responseText.match(/success/)) {
				resultdiv.innerHTML = tsuccessmessage;
				if (dofunction != 0) {eval(after);}
				if (tredirecturl != 'dummy') {
					openLink(tredirecturl, tredirectquerystring, contentlayer, themethod);
				}				
			} else {
				resultdiv.innerHTML = tfailuremessage;
			}
			new Effect.Opacity(resultstr, { duration: 2.0, from: 0.0, to: 1.0 } );
			new Effect.Opacity(resultstr,  { delay: 2.0, duration: 2.0, from: 1.0, to: 0.0 } );
		},
		onFailure: function() {
			resultdiv.innerHTML = tfailuremessage;
			new Effect.Opacity(resultstr, { duration: 2.0, from: 0.0, to: 1.0 } );
			new Effect.Opacity(resultstr,  { delay: 1.7, duration: 2.0, from: 1.0, to: 0.0 } );
		}
	});
}

