// JS Subscribe Module - alStudios 2008 - TODOS OS DIREITOS RESERVADOS - A reprodução ou distribuição não autorizada deste arquivo, ou de qualquer parte dele, poderá resultar em severas punições civis e criminais, e os infratores serão punidos dentro do máximo rigor permitido por lei.

var http_request = false;

function ok(){}

it0 = setInterval(ok,100);

it1 = setInterval(ok,100);

it2 = setInterval(ok,100);

it3 = setInterval(ok,100);

it4 = setInterval(ok,100);

clearInterval(it0);

clearInterval(it1);

clearInterval(it2);

clearInterval(it3);

clearInterval(it4);

k=l=m=n=o=p=1;

now=0;

function check(di,ti,vi,niz){

	if(niz==0){

		this[vi.name+'time'] = 0;

		clearInterval(eval('it'+di));

		var oThis = this;

		!document.all ? this['it'+di] = setInterval(counter,500,di,ti,vi) : this['it'+di] = setInterval(function(){oThis.counter.apply(oThis,[di,ti,vi]);},500);

	} else {

		clearInterval(eval('it'+di));

		this[vi.name+'time'] = 2;

		var oThis = this;

		!document.all ? this['it'+di] = setInterval(counter,500,di,ti,vi) : this['it'+di] = setInterval(function(){oThis.counter.apply(oThis,[di,ti,vi]);},500);

	}

}

function counter(di,ti,vi){

	this[vi.name+'time']++;

	now = 1;

	sd_check();

	if(this[vi.name+'time']>=2){

		this[vi.name+'time'] = 0;

		now = 0;

		clearInterval(eval('it'+di));

		switch(di){

			case 0:

				nick_check(di,ti,vi);

				break;

			case 1:

				oid_check();

				break;

			case 2:

				mail_check(di,ti,vi);

				break;

			case 3:

				if(ti == 0){

					pass_check(0,vi.value);

				}

				if(ti == 1){

					pass_check(1,vi.value);

				}

				break;

			case 4:

				name_check();

				break;

		}

	}

	

}

function sde(d,t,v) {

	ve = v.value == '' ? '' : v.value;

	t == 1 ? url = 'dget.php?d='+d+'&v='+ve : url = d;

	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType) {

			http_request.overrideMimeType('text/xml');

		}

	} else if (window.ActiveXObject) { // IE

		try {

			http_request = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try {

				http_request = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e) {}

		}

	}



	if (!http_request) {

		alert('Erro 2002');

		return false;

	}

	obj_i = v.name;

	http_request.onreadystatechange = alertContents;

	http_request.open('GET', url, true);

	http_request.send(null);

}



function alertContents() {

	if (http_request.readyState == 4) {

		if (http_request.status == 200) {

			if(http_request.responseText == '0'){

				b_status(obj_i,'Disponível!',1);

				obj_i=='nick' ? k=0 : '';

				obj_i=='mail' ? m=0 : '';

			} else if(http_request.responseText == '1'){

				b_status(obj_i,'Indisponível!',0);

				obj_i=='nick' ? k=1 : '';

				obj_i=='mail' ? m=1 : '';

			} else {

				b_status(obj_i,'Não foi possível checar se o valor do campo escolhido está disponível',3);

				obj_i=='nick' ? k=1 : '';

				obj_i=='mail' ? m=1 : '';

			}

			sd_check();

		} else {

			alert('Erro 2001 - Entre em contato com o Suporte Técnico.');

		}

	} else if (http_request.readyState == 1) {

		b_status(obj_i,'Carregando...',2);

	}

}

function nick_check(dn,tn,vn){

	if(document.cd.nick.value.length >= 5){

		sde(dn,tn,vn);

	} else {

		k = 1;

		b_status('nick','O Apelido digitado deve ter no mínimo <b>5</b> caracteres.',0);

	}

}

function oid_check(){

	e1=e2=e3=e4=e5=e6=e7=e8=1;

	st = null;

	st = document.cd.oid.value;

	stz = st.match(/^http:\/\/www\.orkut\.com[\.\w*]*\/[Main#]*(\w+)\.aspx\?[\&rl\=ls]*(uid\=|xid\=)(\d+)/);

	if(stz != null && stz != '' && stz != 'null'){

		(op = stz.toString());

		var sti = op.split(",");

		(e1 = sti[1].indexOf('Profile'));

		(e2 = sti[1].indexOf('Scrapbook'));

		(e3 = sti[1].indexOf('AlbumList'));

		(e4 = sti[1].indexOf('AlbumZoom'));

		(e5 = sti[1].indexOf('FavoriteVideos'));

		(e6 = sti[1].indexOf('Marks'));

		(e7 = sti[1].indexOf('Notifications'));

		(e8 = sti[1].indexOf('Settings'));

		fn = sti[3].match(/\d\d\d\d\d\d\d+/);

		(fn+1 != 1+fn) ? fz = fn.toString() : '';

	}

	if((e1==0 || e2==0 || e3==0 || e4==0 || e5==0 || e6==0 || e7==0 || e8==0) && fn!=null && fz.length > 5){

		l = 0;

		b_status('oid','URL Correta!',1);

		document.cd.oid_n.value = sti[3];

	} else {

		l = 1;

		b_status('oid','A URL informada está incorreta. Cheque nosso tutorial sobre como copiar a URL correta.',0);

	}

	sd_check();

}

function mail_check(da,ta,va){

	sm = document.cd.mail.value;

	bm = sm.match(/\w+(?=@)/);

	cm = sm.match(/@(?=[a-z|0-9]+)/);

	dm = sm.match(/\.+(?=[a-z|0-9]+)/);

	if(bm != null && cm != null && dm != null){

		sde(da,ta,va);

	} else {

		b_status('mail','O e-mail digitado parece estar incorreto!',0);

		m = 1;

	}

}

function pass_check(kp,vp){

	if(kp == 0){

		lp = vp.length;

		vp0 = vp1 = vp2 = vp3 = vp;

//		///Special Chars

		npa0 = vp0.replace(/\w+/,'');

		npb0 = npa0.replace(/\w+/,'');

		npc0 = npb0.replace(/\w+/,'');

		///Special Chars Count

		(nb0 = npc0.match(/\W+/)) == null ? nb0 = '' : '';

//		////Numbers

		npa1 = vp1.replace(/\D+/,'');

		npb1 = npa1.replace(/\D+/,'');

		npc1 = npb1.replace(/\D+/,'');

		///Numbers Count

		(nb1 = npc1.match(/\d+/)) == null ? nb1 = '' : '';

//		///Lower Case

		npa2 = vp2.replace(/[^a-z]+/,'');

		npb2 = npa2.replace(/[^a-z]+/,'');

		npc2 = npb2.replace(/[^a-z]+/,'');

		///Lower Case Count

		(nb2 = npc2.match(/[a-z]+/)) == null ? nb2 = '' : '';

//		///Upper Case Count		

		npa3 = vp3.replace(/[^A-Z]+/,'');

		npb3 = npa3.replace(/[^A-Z]+/,'');

		npc3 = npb3.replace(/[^A-Z]+/,'');

		(nb3 = npc3.match(/[A-Z]+/)) == null ? nb3 = '' : '';

		

		nc0 = nb0.toString();

		nc1 = nb1.toString();

		nc2 = nb2.toString();

		nc3 = nb3.toString();

		sp = nc0.length+(nc1.length+nc2.length+nc3.length)/6;

		((nb2.length > 0 && nb3.length > 0) || (nb1.length > 0 && nb2.length > 0) || (nb1.length > 0 && nb3.length > 0)) ? sp = sp+.5 : sp = sp-.5;

		//alert(vp+'\n'+nb0+'-'+nb1+'-'+nb2+'-'+nb3+' : '+sp+'\n'+nc0.length+'+'+nc1.length+'+'+nc2.length+'+'+nc3.length);

		pass2_ct = document.getElementById('pass2_c');

		if(lp < 5){

			n = 1;

			b_status('pass','A senha deve ter no mínimo <b>5</b> caracteres.',0);

			o == 0 ? kp = 1 : kp = 0;

			pass2_ct.innerHTML = '';

		}

		if(lp >= 5){

			n = 0;

			if(sp < 1){

				b_status('pass','Sua senha é fraca.',3);

			} else if(sp >= 1 && sp < 2){

				b_status('pass','Senha é de média força.',2);

			} else if(sp >= 2){

				b_status('pass','Senha forte.',1);

			}

			

			pass2_ct.innerHTML = 'Redigite sua senha:&nbsp;<input name="pass2" id="pass2" class="box" type="password" size="30" maxlength="50" onKeyDown="check(3,1,this,0)" onChange="check(3,1,this,1)">&nbsp;<img src="images/white.gif" id="pass2_i" align="texttop">&nbsp;<span id="pass2_s"></span>';

		}

	}

	if(kp == 1){

		if(document.cd.pass.value == document.cd.pass2.value){

			o=0;

			b_status('pass2','OK!',1);

		} else {

			o=1;

			b_status('pass2','As senhas digitadas não são iguais!',0);

		}

		

	}

	sd_check();

}

function name_check(){

	if(document.cd.name.value.length >= 5){

		p = 0;

		b_status('name','OK!',1);

	} else {

		p = 1;

		b_status('name','O Nome digitado deve ter no mínimo <b>5</b> caracteres.<br><sup style="color:grey">Caso seu nome seja menor, use as iniciais do seu Sobrenome ou um Nome Fantasia.</sup>',0);

	}

	sd_check();

}



function sd_check(){

	if(document.cd.ap.checked == true && k==0 && l==0 && m==0 && n==0 && o==0 && p==0 && now==0){

		document.cd.sb.disabled = '';

	} else {

		document.cd.sb.disabled = 'disabled';

	}

}

function b_status(obj_b,msg,stb){

	obj = document.getElementById((obj_b+'_s').toString());

	img = document.getElementById(obj_b+'_i');

	fm = document.getElementById(obj_b);

	if(stb == 1){

		obj.innerHTML = msg;

		obj.style.color = 'green';

		img.src = 'images/accept.gif';

		fm.style.border = '1px solid green';

	} else if(stb == 0){

		obj.innerHTML = msg;

		obj.style.color = 'red';

		img.src = 'images/stop.gif';

		fm.style.border = '1px solid red';

	} else if(stb == 2){

		obj.innerHTML = msg;

		obj.style.color = 'blue';

		img.src = 'images/alert_b.gif';

		fm.style.border = '1px solid green';

	}

	else if(stb == 3){

		obj.innerHTML = msg;

		obj.style.color = '#333333';

		img.src = 'images/alert.gif';

		fm.style.border = '1px solid blue';

	}

}