// JScript source code

var browserType;
var whitespace = " \t\n\r";
var data_type = 1;
var field_to_check;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

function ResetForm(form_name)
{
		form_name = eval(form_name);
		form_name.reset();
}

function isEmpty(s){return ((s == null) || (s.length == 0));}

function CheckEmail()
{
	var filter_email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter_email.test(field_to_check.value)){data_type = 1;}
	else
	{
		alert("O email que preencheu nao e valido!");
		GetFocus();
		return;
	}
}

function GetFocus()
{
	data_type = 0;
	field_to_check.value ="";
	field_to_check.focus();
	field_to_check.select;
}

function CheckData(alert_text)
{
	ValidateData(field_to_check.value);
	if(data_type == 0)
	{	
		alert(alert_text);
		GetFocus();
	}
	return;
}

function ValidateData(wich_field)
	{   
		// assign variable with the field value
		var field_value = wich_field;
		var i;
	
	    // Is s empty?
	    if (isEmpty(field_value))
		{ 
			//alert("d");
			GetFocus();
			//stop_check = 0;
			return;
		} 
		else
		{
		    // Search through string's characters one by one
		    // until we find a non-whitespace character.
		    // When we do, return false; if we don't, return true.
		
		    for (i = 0; i < field_value.length; i++)
		    {   
			// Check that current character isn't whitespace.
				var c = field_value.charAt(i);
				if (whitespace.indexOf(c) == -1)
				{
					//return false;
		    		// All characters are whitespace.
					//alert("s");
					data_type = 1;
					//stop_check = 1;
					return;
				}
			}
			//alert("w");
			//data_type = 0;
			//stop_check = 0;
			return;
		}
	}
	
	function OpenWindow(src)
{        
	Pop=window.open(src,"displayWindow","toolbar=no,width=800,height=600,directories=no,status=yes,scrollbars=yes,resize=yes,menubar=no");
}

function GetData()
{
   // alert(wich_one)
    field_to_check = document.frm_mail.nick;
    //alert("W");
    CheckData("Nome");
    if (data_type == 0) { return; }
    field_to_check = document.frm_mail.email;
    CheckEmail();
    if (data_type == 0) { return; }
    field_to_check = document.frm_mail.subject;
    CheckData("Assunto");
    if(data_type == 0){ return; }
    field_to_check = document.frm_mail.body;
    CheckData("Texto");
    if (data_type == 0) { return; }

    field_to_check = document.frm_mail.captchacode;
    //captcha = field_to_check.value
    //alert(captcha.lenght)
    if (field_to_check.value.length == 5) { data_type = 1; }
    else
    {
        alert("Entre os caracteres que vê na Imagem!")
        GetFocus();
    }
    if (data_type == 0) { return; }
    
    if(data_type == 0) { return; }
    if(data_type != 0)  { document.frm_mail.submit(); }
}

var min = 8;
var max = 18;
function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("pt", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "pt"
    }
}
function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("pt", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "pt"
    }
}

function ShowPop() {
    var el = document.getElementById('pop');
    el.style.visibility = "visible";
}

function HidePop() {
    var el = document.getElementById('pop');
    el.style.visibility = "hidden";
}

function showCustomer(ID) {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //document.frm_mail.email.value = xmlhttp.responseText;
            if (xmlhttp.responseText == "sucess") { HidePop(); }
            else { alert("Houve um erro ao mandar o link, tente de novo!"); }
        }
    }
    var name, email, email_r
    name = document.frm_mail.nick.value;
    email = document.frm_mail.email.value;
    email_r = document.frm_mail.email_r.value;
    xmlhttp.open("GET", "send_email_tema.asp?name=" + name + "&email=" + email + "&email_r=" + email_r + "&ID=" + ID, true);
    xmlhttp.send();
}

function GetDataTema(ID) {
    // alert(wich_one)
    field_to_check = document.frm_mail.nick;
    //alert("W");
    CheckData("Nome");
    if (data_type == 0) { return };
    field_to_check = document.frm_mail.email;
    CheckEmail();
    if (data_type == 0) { return };

    field_to_check = document.frm_mail.email_r;
    CheckEmail();
    if (data_type == 0) { return };


    if (data_type == 0) { return };
    showCustomer(ID);
}




function ConfirmDelete(page, ID, subject)
{
	input_box=confirm("Are you sure you want to Delete this " + subject + "?");
	if (input_box==true){ location.href = page + "?ID=" + ID;}
}

function ConfirmDeleteCourses(page, ID, subject)
{
	input_box=confirm("Are you sure you want to Delete this " + subject + "?");
	if (input_box==true){ location.href = page + "&ID=" + ID;}
}



