/*var/www/neoroot/backend/js*/
// <![CDATA[

	/*
	 * GET parsing.
	 */
	
	var previousDialog = false;
	function openLink(url, target){
			if(target != 'blank'){
				window.location.href = url;
			}else{
				window.open(url,'window','params');
			}
	}
	/*
	 * ajax requests
	 */
	function Request(sURL) {
		this.URL = sURL;
		this.Options = {
			method: 'post'
		}

	}
	
	Request.prototype = {
		Async: function(sPostBody, fnHandler, oObject, vExtra) {
			this.Options.postBody = sPostBody;
			this.Options.asynchronous = true;
			this.Options.evalJSON = 'force';
			this.Options.onSuccess = fnHandler.bind(oObject, vExtra);
			this.Options.on404 = function(oRequest) {
				sendError(oRequest.responseText);
			};
			this.Options.onFailure = function(oRequest) {
				sendError('Error ' + oRequest.status + ' -- ' + oRequest.statusText);
			}

			new Ajax.Request(this.URL, this.Options);		
		},
		
		Sync: function(sPostBody, fnHandler, oObject, vExtra) {
			this.Options.postBody = sPostBody;
			this.Options.asynchronous = false;
			this.Options.evalJSON = 'force';
			this.Options.onSuccess = fnHandler.bind(oObject, vExtra);
			this.Options.on404 = function(oRequest) {
				sendError(oRequest.responseText);
			};
			this.Options.onFailure = function(oRequest) {
				sendError('Error ' + oRequest.status + ' -- ' + oRequest.statusText);
			};
			new Ajax.Request(this.URL, this.Options);
		}
	}
	/*
	 * dialog class
	 */
	function Dialog() {
		if (previousDialog && previousDialog instanceof Dialog) {
			try{return previousDialog;}catch(e){}
		}
		
		this.Dialog = Builder.node('table', {cellpadding: 0, cellspacing: 0, border: 0});

		
		Element.hide(this.Dialog);

		//this.Dialog.setAttribute('id', 'dialog');
		//Element.addClassName(this.Dialog, "dialog");
		
		this.Background = Builder.node('div');
		this.Background.setAttribute('id', 'dialog_background');
		Element.hide(this.Background);
		
		this.oBody = document.getElementsByTagName("body").item(0);
		this.Background.setAttribute('id', 'dialog_background');
		this.oBody.insertBefore(this.Background, this.oBody.firstChild);
		this.oBody.appendChild(this.Dialog);
		
		
		this.Dialog.style.width = "100%";
		this.Dialog.style.height = "auto";
		
		
  		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;
		}
	
		
		this.Dialog.style.height = myHeight + "px";
		this.Dialog.style.zIndex = 99999;
		this.Dialog.style.position = "absolute";
		this.Dialog.style.left = "0px";
		this.Dialog.style.top = "0px";
		
		this.Background.style.height = myHeight + "px";
		this.Background.realHeight = myHeight;

		aTableTbody = Builder.node("tbody");
		aTableTr = Builder.node("tr");
		this.dialogContent = Builder.node("td");
		
		this.dialogContent.align = "center";
		this.dialogContent.valign = "middle";
		
		aTableTr.appendChild(this.dialogContent);
		aTableTbody.appendChild(aTableTr);
		this.Dialog.appendChild(aTableTbody);

		this.Browser = this.checkBrowser();
		
		if (this.Browser == "Internet Explorer"){
			//this.Background.style.height = Element.getDimensions(document.body).height;
			window.onscroll = this.setBackgroundPosition.bind(this);
			setInterval("getDialogInstance().setBackgroundPosition()", 1);
		} else {
			this.Background.style.position = "fixed";
			this.Dialog.style.position = "fixed";
		}
		previousDialog = this;
	}
	
	function getDialogInstance() {
		try{return new Dialog();}catch(e){}
	}
	Dialog.prototype = {
		Show: function(sDiv, bNoHideSelects) {
			if (!$(sDiv)) return false;
		    bNoHideSelects = ( bNoHideSelects == true ) ? false : true;
			
			/*if (this.Browser == 'Internet Explorer' && bNoHideSelects) {
				this.hideSelects('hidden');
			}*/
			if (this.checkBrowser() == 'Internet Explorer') {
				this.hideSelects('hidden');
				//document.body.onselectstart = function () { return false; }
			} else {

			}

			if (this.checkBrowser() == 'Internet Explorer') {

				//Ahora, una forma mas simple
				if ((document.body.scrollHeight) && (this.Background.realHeight < document.body.scrollHeight)) {
					this.Background.style.height = document.body.scrollHeight;
					this.Background.style.width = document.body.scrollWidth;
				} else 
					if ((document.documentElement.scrollHeight) && 
						(this.Background.realHeight < document.documentElement.scrollHeight)) {
					this.Background.style.height = document.documentElement.scrollHeight;
					this.Background.style.width = document.documentElement.scrollWidth;
				} else {
					this.Background.style.width = "100%";
					this.Background.style.height = this.Background.realHeight;
				}
			}
			
			this.hideObjects('hidden');
			this.Prepare('100%', 'hidden');

			this.dialogContent.appendChild($(sDiv));
			Element.show(this.Background);
			Element.show(this.Dialog);
			//$(sDiv).style.overflow = "auto";
			Element.show($(sDiv));
			if (this.checkBrowser() == 'Internet Explorer') {
				var inputs = $(sDiv).getElementsByTagName('input'); 
				try{
					inputs[0].focus();
				}catch(e){}
			}
		//new Draggable2(sDiv, {starteffect: function() {}, endeffect: function() {}, constraint: "vertical"});
			this.Center(this.Dialog);
			return true;			
		},
		
		Hide: function(sDiv) {
			if (this.Browser == "Internet Explorer"){
				this.hideSelects("visible");
				document.body.onselectstart = null;
			} else {
				document.onmousedown = null;
				document.onclick = null;
			}
			this.hideObjects('visible');
			
			this.Prepare("auto", "auto");
			
			Element.hide(sDiv);
			Element.hide(this.Background);
			Element.hide(this.Dialog);
			//parent.toolbar.scrollhere(0,3);

			return true;		
		},
		
		setBackgroundPosition: function () {
			if (this.Browser == "Internet Explorer") {
				if (document.body.scrollTop) {
					//this.Background.style.top = document.body.scrollTop;
					this.Dialog.style.top = document.body.scrollTop;
				} else {
					//this.Background.style.top = document.documentElement.scrollTop;
					this.Dialog.style.top = document.documentElement.scrollTop;
				}
			}
		},
		
		showError: function(sError) {
			$('error_message').innerHTML = sError;
			this.Show('error');
		},


		showErrorSinEncuesta: function(sError) {
			$('error_message').innerHTML = sError;
			this.Show('error');
		},

		showWarning: function (sWarning) {
			Element.update('warning_message', sWarning);
			this.Show('warning');
		},
				
		hideWarning: function () {
			this.Hide('warning');
		},
		
		hideError: function() {
			$('error_message').innerHTML = '';
			this.Hide('error');
		},
		
		showWorking: function() {
			this.Show('working');
		},
		
		hideWorking: function() {
			this.Hide('working');
		},
		
		parseError: function(errorData) {
			errorText = errorData["text"];
			errorType = errorData["type"];
			
			switch (errorType) {
				case 2: //Error
					this.showError(errorText);
					break;
				default: //Warning
					this.showWarning(errorText);
					break;
			}
			return true;
		},
		
		Prepare: function(height, overflow) {

		},
		
		checkBrowser: function() {
			sUserAgent = navigator.userAgent.toLowerCase();
			exists = sUserAgent.indexOf('msie') + 1;
			if(exists) {
				return 'Internet Explorer';
			} else {
				return 'Other';
			}
		},
		
		hideSelects: function(visibility) {

			selects = document.getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = visibility;
			}
		},
		
		hideObjects: function(visibility) {
			objects = document.getElementsByTagName('object');
			for(i = 0; i < objects.length; i++) {
				objects[i].style.visibility = visibility;
			}
		},
		
		Center: function(element) {
			
		}	
}
	
	/*
	 * dialog functions
	 */
	function dialog_init() {

	}
	
	/*
	 * error functions.
	 */
	function showError(sError) {
		try{getDialogInstance().showError(sError);}catch(e){}
	}
	
	

	function hideError() {
		try{getDialogInstance().hideError();}catch(e){}
		
	}
	
	function showWarning(sWarning) {
		try{getDialogInstance().showWarning(sWarning);}catch(e){}
		
	}
	
	function hideWarning() {
		try{getDialogInstance().hideWarning();}catch(e){}
	}
	
	function hideObjects (visibility) {
		try{getDialogInstance().hideObjects(visibility);}catch(e){}
	}
	
	function parseError (errorData) {
		try{getDialogInstance().parseError(errorData);}catch(e){}
	}
	 
	function dialog_show() {

	}
	
	function dialog_showDialog(sDialog) {
		try{getDialogInstance().Show(sDialog);}catch(e){}
	}
	
	function dialog_blockThemAll() {
		try{getDialogInstance().showWorking();}catch(e){}
	}
	
	function dialog_unblockThemAll() {
		try{getDialogInstance().hideWorking();}catch(e){}
	}

	function dialog_hide() {

	}
	
	function dialog_hideDialog(sDialog, hideNow) {
		try{getDialogInstance().Hide(sDialog);}catch(e){}
	
	}
	
	function dialog_showWorking() {
		try{getDialogInstance().showWorking();}catch(e){}
	}

	function dialog_hideWorking() {
		try{getDialogInstance().hideWorking();}catch(e){}
	}
	
	/* this is from http://particletree.com */
	function dialog_prepareBrowser(height, overflow) {
		try{getDialogInstance().Prepare(height, overflow);}catch(e){}
	}
	
	function dialog_hideSelects(visibility) {
		try{getDialogInstance().hideSelects(visibility);}catch(e){}
	}
	
	function dialog_checkBrowser() {
		try{getDialogInstance().checkBrowser();}catch(e){}
	}
	
	function dialog_center(element) {
		try{getDialogInstance().Center(element);}catch(e){}
	}
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function openPopUp(modulo){
		if(modulo == 'main'){
			window.open("neocontact.php?vienede="+modulo,null,"height=500,width=390,status=yes,toolbar=no,menubar=no,location=no");
		}else{
			window.open("/backend/neocontact.php?vienede="+modulo,null,"height=500,width=390,status=yes,toolbar=no,menubar=no,location=no");
		}
		return false;
	}
function logout() {
	window.location = '/backend/logout.php';	
}

function open_popup(h,w,theURL,scroll){
		if(!scroll) scroll = "no";
  		var t=(screen.height-h)/2;
 		var l=(screen.width-w)/2;
		var features=",scrollbars="+scroll+",top="+t+",left="+l+",height="+h+",width="+w+"";
 		 window.open(theURL,'form',features);
}
function logueoportal(donde){
	if(donde) {
		document.getElementById('miForm2').submit();
	} else {
		document.getElementById('miForm').submit();
	}
	DialogoLogin = new Dialog();
	DialogoLogin.Show('contenedor_cargador');
}
// ]]>
