//////////////////////////////////////////////////
// Site: www.-the-masters-plan.org              //
// System: Site Manager                         //
// Author: Henry Cordloba                       //
// mail: hecomain (at) hotmail (dot) (com)      //
//////////////////////////////////////////////////
var Host = window.location.hostname;
var proto = window.location.protocol;
var RHost = proto + "//" + Host + "/";

var HostnDom ={
	
	AjaxContent : null,
	LogOption : null,
	timeout : 0,
	urlL : RHost + "p/hndf.php",
	urlF : RHost + "hndf.php",
	objContName : "",
	objCon: "",
	
	HostnDomConten : function (){
		HostnDom.objContName = "ims_content";
		HostnDom.objCon = $(HostnDom.objContName).innerHTML;
		$(HostnDom.objContName).innerHTML = "";
		
		Dialog.confirm(HostnDom.AjaxContent, {
					className:"alphacube", 
					width:500, 
					okLabel: "Solicitar", 
					cancelLabel: "Cancelar", 
					buttonClass: "botonFormaGrisw",
					onOk:function(win){ 
						if(HostnDom.LogOption == "1"){
							HostnDom.HostnDom($('log').value,$('pass').value);	
						}else{
							HostnDom.checksp($('new_pass').value,$('re_pass').value);	
						}				
					},
					onCancel:function(win){
						$(HostnDom.objContName).innerHTML = HostnDom.objCon; 	
					}
		});	
		
	},
	
	showForm : function (option){
		HostnDom.LogOption = option;
		(HostnDom.LogOption == "1") ? option = "enter" : option = "changePass";
		var data = "op=" + escape(option);
		var ajax_HostnDom = new Ajax.Request(
			HostnDom.urlF,
			{
				method: 'post',
				postBody:  data,
				onSuccess: function( t ) { HostnDom.responseLC(t)},
				onFailure: function( t ) { HostnDom.showHostnDom }
			}
		);			
	},
	
	responseLC : function(t){
		HostnDom.AjaxContent = t.responseText;
		HostnDom.HostnDomConten();
	},
	
	HostnDom :  function (l,p){		
		var data = "ckl=1&l=" + escape(l) + "&p=" + escape(p);
		var ajax_HostnDom = new Ajax.Request(
			HostnDom.urlL,
			{
				method: 'post',
				postBody:  data,
				onSuccess: function( t ) { SM.HostnDomr(t) },
				onFailure: function( t ) { SM.HostnDomnr }
			}
		);		
	},
	
	HostnDomr : function(t){
		var xml = t.responseXML;
		var results = xml.getElementsByTagName('results')[0].childNodes;
		var id = results[0].getAttribute('id');
		var sts = results[0].childNodes[0].nodeValue;
		if(sts = "0"){
			SM.HostnDomEPU;
		}else{
			window.location("");
		}
	},
	
	HostnDomnr : function(){
		$('HostnDom_error_msg').innerHTML='Error ->El servidor no responde, intente de nuevo !'; 
		$('HostnDom_error_msg').show(); 		
	},
	
	HostnDomEPU : function(){
		$('HostnDom_error_msg').innerHTML='HostnDom y/o password invaido !'; 
		$('HostnDom_error_msg').show(); 
		Windows.focusedWindow.updateHeight(); 
		new Effect.Shake(Windows.focusedWindow.getId()); return false;
	},
	
	checksp : function(p1,p2){
		if( p1 == p2){
			HostnDom.changepass($('old_pass').value,$('new_pass').value);	
		}else{
			HostnDom.NSpass();
		}	
	},
	
	NSpass : function(){		
  		Dialog.info("Su nuevo password y su confirmacion no coinciden.\n",
               {width:250, height:100, showProgress: true,windowParameters: {className: "alphacube"}});
  		HostnDom.timeout=2;
  		setTimeout(HostnDom.NSpassD, 3000)	
	},
	
	NSpassD : function(){		
  		HostnDom.timeout--;
		if (HostnDom.timeout > 0) {
	    	Dialog.setInfoMessage("Esta ventana se cerrara en <br>in " + HostnDom.timeout + " segundos.")
	    	setTimeout(HostnDom.NSpassD, 1000)
	 	}else{
	 		$('old_pass').value = "";
	 		$('new_pass').value = "";
	 		$('re_pass').value = "";
	  		Dialog.closeInfo()
		}
		openInfoDialog();
	},
	
	changepass : function (lo, np){
		var data = "op=" + escape(option);
		var ajax_HostnDom = new Ajax.Request(
			HostnDom.url,
			{
				method: 'post',
				postBody:  data,
				onSuccess: function( t ) { HostnDom.responseLC(t)},
				onFailure: function( t ) { HostnDom.changepass }
			}
		);				
	}
			
}



