
function postToUrl(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}

function initialize() {
	//alert("post");
	var params = new Object;
	params.screenWidth = screen.width;
	params.initialized = true;
	postToUrl("index.php", params, "post");
	
}

function writeCookie() {
	var today = new Date();
	var the_date = new Date("December 20, 2006");
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = "resolucao="+ screen.width +"x"+ screen.height;
	var the_cookie = the_cookie + ";expires=" + the_cookie_date;
	document.cookie=the_cookie;

	location = 'index.php';
}

function checkMail(mail){
	var flag = false;
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
    	if(er.test(mail)){ 
    		flag = true; 
    	}
    } else if(typeof(mail) == "object"){
    	if(er.test(mail.value)){ 
    		flag = true; 
    	}
    } else {
    	flag = false;
    }
    return flag;
}


function checkForm() {
	var flag = true;
	var flds = ["nome", "email", "assunto", "msg"];
	for (var i in flds) {
		if (document.getElementById(flds[i]).value == "") {
			alert("Todos os campos devem ser preenchidos." );
			flag = false;
			document.getElementById(flds[i]).focus();
			break;
		}
		if (flds[i] == "email") {
			//alert(checkMail(document.getElementById(flds[i])));
			if (!checkMail(document.getElementById(flds[i]))) {
				alert("Email inválido");
				flag = false;
				document.getElementById(flds[i]).focus();
				break;
			}
		}
	}
	return flag;
}


