var istextwall = false;

function omo(obj) {
	obj.style.opacity = 0.8;
	obj.style.filter = 'alpha(opacity=80)';	
}

function omu(obj) {
	obj.style.opacity = 1;
	obj.style.filter = '';
}

function init(days,seconds) {
	if (navigator.userAgent.indexOf('Firefox') != -1) document.getElementById('bottomtable').style.top = '-7px';
	countdown(days,seconds);
	if (istextwall) mainTextScroller();
}

function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}

function linkan(obj) {
		colorFade(obj.id,'','A06D4E','41352C');
}

function linkian(obj) {
		colorFade(obj.id,'','41352C','A06D4E'); 

}

function countdown(days,secondss) {
	var goc = true;
	if ((days >= 0)&&(secondss > 0)) {
		var hours = Math.floor(secondss/3600);
		var minutes = Math.floor((secondss - hours*3600)/60);
		var seconds = (secondss - hours*3600 - minutes*60);
		var zilestr = ' zile, ';
		if (days == 1) zilestr = ' zi, ';
		var orestr = ' ore, ';
		if (hours == 2) orestr = ' ora, ';
		var minutestr = ' minute, ';
		if (minutes == 1) minutestr = ' minut, ';
		var secundestr = ' secunde';
		if (seconds == 1) secundestr = ' secunda';
		document.getElementById('realtime').innerHTML = days+zilestr+hours+orestr+minutes+minutestr+seconds+secundestr;
		secondss--; 
		if (secondss == 0) {
			days--; 
			if (days >= 0) secondss = 3600*24; else {checkwhois(); goc = false;}
		}
		var fstr = 'countdown('+days+','+secondss+')';
		if (goc) setTimeout(fstr,1000);
	}
	else checkwhois();
}

function beforesubmit() {
	var command = 'href=inner#beforesubmit,,width=430,,height=340';
	CB_Open(command);
}

function aplica() {
	CB_Close();
	CB_Init();
	var command = 'href=inner#signupdiv,,width=450,,height=700';
	var fstr = 'CB_Open("'+command+'")';
	setTimeout(fstr,500);
}

function contact() {
	var command = 'href=http://www.lets-pray.ro/contact.php,,width=700,,height=480';
	CB_Open(command);
}

function parteneri() {
	var command = 'href=http://www.lets-pray.ro/parteneri.php,,width=700,,height=480';
	CB_Open(command);
}

function despre() {
	var command = 'href=http://www.lets-pray.ro/despre.php,,width=800,,height=700';
	CB_Open(command);
}

function loginerrorstarter() {
	var fstr = 'loginerror()';
	setTimeout(fstr,1000);
}

function loginerror() {
	var command = 'href=inner#loginerror,,width=450,,height=40';
	CB_Open(command);
}

function strategie() {
	var command = 'href=http://www.lets-pray.ro/strategie.php,,width=800,,height=700';
	CB_Open(command);
}

function signup() {
	var auxc = document.getElementById('signupdiv').innerHTML; 
	document.getElementById('signupdiv').innerHTML = '';
	var el1 = document.getElementById('nume');
	var el2 = document.getElementById('user');
	var el3 = document.getElementById('password');
	var el4 = document.getElementById('repassword');
	var el5 = document.getElementById('oras');
	var el6 = document.getElementById('tara');
	var el7 = document.getElementById('biserica');
	var el8 = document.getElementById('varsta');
	var el9 = document.getElementById('email');
	var el10 = document.getElementById('incognito');
	el1.style.backgroundColor = '#FFFFFF'; el1.title = '';
	el2.style.backgroundColor = '#FFFFFF'; el2.title = '';
	el3.style.backgroundColor = '#FFFFFF'; el3.title = '';
	el4.style.backgroundColor = '#FFFFFF'; el4.title = '';
	el5.style.backgroundColor = '#FFFFFF'; el5.title = '';
	el6.style.backgroundColor = '#FFFFFF'; el6.title = '';
	el7.style.backgroundColor = '#FFFFFF'; el7.title = '';
	el8.style.backgroundColor = '#FFFFFF'; el8.title = '';
	el9.style.backgroundColor = '#FFFFFF'; el9.title = '';

	var b1 = true;
	var b2 = true;
	var b3 = true;
	var b4 = true;
	var b5 = true;
	var b6 = true;
	var b7 = true;
	var b8 = true;
	var b9 = true;

	if (el1.value.length < 1) b1 = false;
	if (el2.value.length < 4) b2 = false;
    if (el3.value.length < 5) b3 = false;
	if (el4.value != el3.value) b4 = false;
	if (el5.value.length < 1) b5 = false;
	if (el6.value.length < 1) b6 = false;
	if (el7.value.length < 1) b7 = false;
	if (el8.value.length < 1) b8 = false;
	if (isNaN(el8.value)) b8 = false;
	
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if (el9.value.length < 1) b9 = false;
    if (!pattern.test(el9.value)) b9 = false;

	if (!b9) {el9.style.backgroundColor = '#EEEEEE'; el9.title = 'Scrie te rog o adresa de email valida.'; el9.focus();}		
	if (!b8) {el8.style.backgroundColor = '#EEEEEE'; el8.title = 'Scrie te rog varsta ta, cu cifre.';  el8.focus();}
	if (!b7) {el7.style.backgroundColor = '#EEEEEE'; el7.title = 'Scrie te biserica din care faci parte.';  el7.focus();}	
	if (!b6) {el6.style.backgroundColor = '#EEEEEE'; el6.title = 'Scrie te rog tara, in care traiesti.';  el6.focus();}	
	if (!b5) {el5.style.backgroundColor = '#EEEEEE'; el5.title = 'Scrie te rog orasul in care traiesti.';  el5.focus();}		
	if (!b4) {el4.style.backgroundColor = '#EEEEEE'; el4.title = 'Cele doua parole nu sunt identice.';  el4.focus();}
	if (!b3) {el3.style.backgroundColor = '#EEEEEE'; el3.title = 'Alege-ti o parola, de cel putin 5 caractere.';  el3.focus();}	
	if (!b2) {el2.style.backgroundColor = '#EEEEEE'; el2.title = 'Alege-ti un username de cel putin 4 caractere.';  el2.focus();}	
	if (!b1) {el1.style.backgroundColor = '#EEEEEE'; el1.title = 'Scrie-ti numele te rog.';  el1.focus();}		
	
	if (b1&&b2&&b3&&b4&&b5&&b6&&b7&&b8&&b9) {
		var pv = new Array();
		pv['nume'] = 1;
		pv['user'] = 1;
		pv['password'] = 1;
		pv['repassword'] = 1;
		pv['oras'] = 1;
		pv['tara'] = 1;
		pv['biserica'] = 1;
		pv['varsta'] = 1;
		pv['email'] = 1;
		var params = buildparams(pv,'');
		params = params + '&incognito='+Number(el10.checked);
		process('register.php',params);		
	}
	document.getElementById('signupdiv').innerHTML = auxc;
}

function process_answer($ans) {
	if ($ans.indexOf('registeruserfail') > -1) {
		var auxc = document.getElementById('signupdiv').innerHTML; 
		document.getElementById('signupdiv').innerHTML = '';
		var el = document.getElementById('user');	
		el.style.backgroundColor = '#DDDDDD'; 
		el.title = 'Numele de utilizator: "'+el.value+'" exista deja. Alege alta te rog.'; 
		el.focus();
		document.getElementById('signupdiv').innerHTML = auxc;
	}
	else
	if ($ans.indexOf('registermailfail') > -1) {
		var auxc = document.getElementById('signupdiv').innerHTML; 
		document.getElementById('signupdiv').innerHTML = '';
		var el = document.getElementById('email');	
		el.style.backgroundColor = '#DDDDDD'; 
		el.title = 'Sa mai facut o inregistrare cu adresa: "'+el.value+'". Alege alta adresa te rog.'; 
		el.focus();
		document.getElementById('signupdiv').innerHTML = auxc;
	}
	else 
	if ($ans.indexOf('registerok') > -1) {
		CB_Close();
		CB_Init();
		var command = 'href=inner#signupok,,width=420,,height=100';
		var fstr = 'CB_Open("'+command+'")';
		var xobj = document.getElementById('usersregistered');
		var nrur = Number(xobj.innerHTML)+1;
		xobj.innerHTML = nrur;
		setTimeout(fstr,1000);
	}
	else
	if ($ans.indexOf('registerfail') > -1) {
		CB_Close();
		CB_Init();
		var command = 'href=inner#signupfail,,width=420,,height=300';
		var fstr = 'CB_Open("'+command+'")';
		setTimeout(fstr,1000);
	}
	else
	if ($ans.indexOf('Acuma se roaga') > -1) {
		myobj = document.getElementById('whois');
		myobj.innerHTML = $ans;
	}
	else alert($ans);
}

function login() {
	document.myform.submit();
}

function logout() {
	document.location.href = '?lo=1';
}

function reaplica() {
	var command = 'href=http://www.lets-pray.ro/reaplica.php,,width=800,,height=300';
	CB_Open(command);
}

function cautauser() {
	var command = 'href=http://www.lets-pray.ro/cauta.php,,width=1006,,height=600';
	CB_Open(command);
}

function checkwhois() {
	var params = 'telltheworld=JesusLives';
	process('whois.php',params);
	var fstr = 'checkwhois()';
	setTimeout(fstr,60000);
}