function togme(diva)  {
	document.getElementById(diva).className=='uoff' ? document.getElementById(diva).className='uonoff' : document.getElementById(diva).className ='uoff'
} 
function postComment (){
		var f = document.getElementById('add_com');
		document.getElementById('URLgetfrom').value = document.getElementById('u').value; // methodo 1
		document.getElementById('fetchandparsecontent').value = 0;
		if ( checkComLength(f) )
		{   	
			f.submit();
			setTimeout('window.close(self)',500);
		}
}
function postDocument (){
	var f = document.getElementById('add_com');
	if ( document.getElementById('URLgetfrom') ) 
		document.getElementById('URLgetfrom').value = ""; // methodo 2
	if ( checkForm(f) ) 
	{   	
		f.submit();
		setTimeout('window.close(self)',500);
	}
}
function postCommentNoPop (){
		var f = document.getElementById('add_com');
		document.getElementById('URLgetfrom').value = document.getElementById('u').value; // methodo 1
		document.getElementById('fetchandparsecontent').value = 0;
		if ( checkComLength(f) )
		{   	
			f.submit();
		}
}
function postDocumentNoPop (){
	var f = document.getElementById('add_com');
	if ( document.getElementById('URLgetfrom') ) 
		document.getElementById('URLgetfrom').value = ""; // methodo 2
	if ( checkForm(f) ) 
	{   	
		f.submit();
	}
}
function post(andPublish) { 
   	var f = document.getElementById('add_com');
	if (checkForm(f)) {   	
		f.submit();
		setTimeout('window.close(self)',500);
	}
}
function justpost(andPublish) { 
   	var f = document.getElementById('add_com');   	
		f.submit();
		setTimeout('window.close(self)',500);
}
function postTags(andPublish) { 
   	var f = document.getElementById('add_com');  	
		f.submit();
		setTimeout('window.close(self)',500);
}
function postComm(andPublish) { 
   	var f = document.getElementById('add_com');
	if (checkComLength(f)) {   	
		f.submit();
		setTimeout('window.close(self)',500);
	}
}
function postJob(andPublish) { 
	var f = document.getElementById('form2');
  var tit = document.getElementById('job_titleE').value.length;
	if (tit < 3 ) {
		alert("Title is required (3 characters min.)");
		document.getElementById('job_titleE').focus();
		return false;
	} else {
		f.submit();
		setTimeout('window.close(self)',100);
	}
}
function postJobClose(andPublish) { 
	var f = document.getElementById('formclose');
		f.submit();
		setTimeout('window.close(self)',100);
}
function checkComLength(f) {
	var lunghez = document.getElementById('commentar').value.length;
	if (lunghez < 5 || lunghez > 1000) {
		alert("Comments must be min. 5 characters and max. 1,000 : you typed "+lunghez);
		document.getElementById('commentar').focus();
		return false;
	} else {
		return true;
	}
}

function checkForm(f) {
	var lunghez = document.getElementById('commentar').value.length;
	if (lunghez>1000 ) {
		alert("Your comments are too long... 1,000 characters allowed: you typed "+lunghez);
		document.getElementById('commentar').focus();
		return false;
	} else {
		return true;
	}
}
function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13){
myfield.form.submit();
return false;
}
else
return true;
}
// http://www.faqs.org/docs/htmltut/forms/index_famsupp_157.html
function writepseudo(pseudo) {
        document.forms[0].PERSON_EMAIL.value = pseudo;
}

function validateForm2(form) {
        if (isNotEmpty(form.PERSON_EMAIL)) {
            if (isNotEmpty(form.PERSON_PASS)) {       
                            return true;
            }
        }
    return false;
}

function validateForm(form) {
    if (isNotEmpty(form.commentar)) {
        if (isNotEmpty(form.PERSON_EMAIL)) {
            if (isNotEmpty(form.PERSON_PASS)) {       
                            return true;
            }
        }
    }
    return false;
}
function validateFormLogin() {
    if (isEMailAddr(document.getElementById('passwreminder'),4,'reminder or email')) {
        if (isNotEmpty(document.getElementById('PERSON_EMAIL'),3,'collection/login name')) {
            if (isNotEmpty(document.getElementById('PEMAIL'),5,'password')) { 
            	if (isNotTheSameValue(document.getElementById('PEMAIL'),document.getElementById('PEMAIL2'))) {      
                            // return true;
                            document.getElementById('logincreation').submit();
                }
            }
        }
    }
    // return false;
}

// validates that the field value string has one or more characters in it
function isNotEmpty(elem,nchar,elemname) {
    var str = elem.value;
   	if(!elemname)  var elemname = 'required field';
    if(!nchar) var nchar = 3;
    if(str.length < nchar) {
        alert("The "+elemname+" is minimum "+nchar+" characters.");
        return false;
    } else {
        return true;
    }
}
function isNotTheSameValue(elem1,elem2) {
	var str1 = elem1.value;
	var str2 = elem2.value;
	if(str1 != str2) {
			alert("The password and confirmed password do not match?!!");
			return false;
		} else {
			return true;
		}
}
// validates that the entry is formatted as an email address
function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-+]+(\.[\w-+]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the email address format.");
        return false;
    } else {
        return true;
    }
}

// validate that the user made a selection other than default
function isChosen(select) {
    if (select.selectedIndex == 0) {
        alert("Please make a choice from the list.");
        return false;
    } else {
        return true;
    }
}
   
// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return true;
        }
    }
    alert("Make a choice from the radio buttons.");
    return false;
}

function postSendEmail(andPublish) { // isEMailAddr
	var f = document.getElementById('formsendemail');
	if (isNotEmpty(document.getElementById('sentto')) && isNotEmpty(document.getElementById('subjecto'),3,'Subject is required and') ) {
			f.submit();
		// setTimeout('window.close(self)',100);
	} else {
		// alert("A valid email address is required");
		document.getElementById('sentto').focus();
		return false;
	}
}