// JavaScript Document
function autofitmenu(thewidth) {
	var themenu = document.getElementById('elmenu');
	var thiswidth = thewidth + 'px';
	themenu.style.width = thiswidth;
}
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 YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert("La informaci\u00f3n requerida no es v\u00e1lida o contiene errores:\t\t\t\t\t\n\n"+s)}
  document.MM_returnValue = (s=='');
}
function logincentroclientes() {
	YY_checkform('loginform','email','#S','2','Por favor llene el campo \'E-mail\' con la direcci\u00f3n electr\u00f3nica que tenemos en registro.','passed_password','#q','0','Por favor escriba su contrase\u00f1a');
	if (document.MM_returnValue) {
		document.forms.loginform.submit();
	}
}
function autoIframe(frameId){
	try{
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		var theight = innerDoc.body.scrollHeight + 100;
		objToResize.height = theight + 'px';
		
	}
	catch(err){
		window.status = err.message;
	}
}

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 = 'itnetcontent';
	}
	if (!themethod) {
		var themethod = "get";
	}
	var thecontentlayer = document.getElementById(contentlayer);
	if (querystring != "0") {
		thecontentlayer.innerHTML = '<div align="center"><img src="images/spinner.gif" width="50" height="50" align="absmiddle" />Cargando...</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 } );
		}
	});
}
function loginCE() {
	YY_checkform('loginform','ceemail','#S','2','Por favor llene el campo \'E-mail\' con la direcci\u00f3n electr\u00f3nica que tenemos en registro.','passed_password','#q','0','Por favor escriba su contrase\u00f1a');
	if (document.MM_returnValue) {
		
		var url = 'centroclientes/index.php?fuse=admin&action=Login&public=1';
		var temail = document.getElementById('ceemail');
		var tpassword = document.getElementById('passed_password');
		var pars = 'ajax=true&passed_password=' + encodeURIComponent(tpassword.value) + '&email=' + encodeURIComponent(temail.value);
		var theaj = new Ajax.Request(url, {
		method: 'post', parameters: pars, 
		onSuccess: function(transport) {
			if (transport.responseText.match(/contrase\u00f1a incorrecta/)) {
				alert("Nombre de usuario y/o contrase\u00f1a incorrecta");	
			} else {
				var randomnumber=Math.floor(Math.random()*11);
				var redirect = "http://www.itnetmedia.com/index.php?klink=cclientes&r=" + randomnumber;
				location.href = redirect;
			}
			/*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 } );
		}*/
		}
	});
		
		
		//submitForm(url, pars, 'post', 'Login Exitoso', 'Login Fallido', tredirecturl, tredirectquerystring, contentlayer, themethod, tresultdiv);
	}
}
function CheckReg(tipoquerydominio) {
	var turl = 'index.php';
	var tdomain = document.getElementById('reqDomain').value;
	var tExt = document.getElementById('reqExt').value;
	var thedomain = tdomain + '.' + tExt;
	if (/^\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b$/i.test(thedomain)) {
		if (tipoquerydominio == 1) {
			location.href = 'index.php?klink=dominios&domain=' + tdomain +'&reg=' + tExt;
		} else {
			var tpars= 'ajax=true&klink=dominios&domain=' + tdomain +'&reg=' + tExt;
			openLink(turl, tpars, 'itnetcontent', 'get');
		}
	} else {
		alert("Por favor ingrese un nombre de dominio v\u00e1lido");	
	}	
}
function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
function vertallesRegistro() {
	var tdomaindetailsdiv = document.getElementById('domaindetails');
	if (tdomaindetailsdiv) {
		tdomaindetailsdiv.style.display = '';	
	}
}

