function checkMail(mail)
{
	var x = mail;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else false;
}

function postStringForm(docForm) {

    var submitContent = '';
    var formElem;
    var lastElemName = '';

    for (i = 0; i < docForm.elements.length; i++) {

        formElem = docForm.elements[i];
        switch (formElem.type) {
            // Text fields, hidden form elements
            case 'text':
            case 'hidden':
            case 'password':
            case 'textarea':
            case 'select-one':
                submitContent += formElem.name + '=' + escape(formElem.value) + '&'
                break;

            // Radio buttons
            case 'radio':
                if (formElem.checked) {
                    submitContent += formElem.name + '=' + escape(formElem.value) + '&'
                }
                break;

            // Checkboxes
            case 'checkbox':
                if (formElem.checked) {
                    // Continuing multiple, same-name checkboxes
                    if (formElem.name == lastElemName) {
                        // Strip of end ampersand if there is one
                        if (submitContent.lastIndexOf('&') == submitContent.length-1) {
                            submitContent = submitContent.substr(0, submitContent.length - 1);
                        }
                        // Append value as comma-delimited string
                        submitContent += ',' + escape(formElem.value);
                    }
                    else {
                        submitContent += formElem.name + '=' + escape(formElem.value);
                    }
                    submitContent += '&';
                    lastElemName = formElem.name;
                }
                break;

        }
    }
    // Remove trailing separator
    submitContent = submitContent.substr(0, submitContent.length - 1);
    return submitContent;
}


function getPageWithoutRedir(page, div, id){
		//page = fisier prelucrare, div= element care se actualizeaza
	var param = "id="+id;
	res = ajaxUpdate( div, page, {
		params:param,
		meth:"post",
		async:true,
		startfunc:"onById('AJAXloading')",
		endfunc:"offById('AJAXloading'); onById('"+div+"');",
		errorfunc:"ajaxError()" }
	);
	return false;
}

function getPage(page, div, redirTo, formData){
//daca ajax response este gol si redirTo este setat se face redirectare
		//page = fisier prelucrare, div= element care se actualizeaza
	var param = 'id='+formData;
	res = ajaxUpdate( div, page, {
		params:param,
		meth:"post",
		async:true,
		startfunc:"onById('AJAXloading')",
		endfunc:"offById('AJAXloading'); onById('"+div+"');redir('"+redirTo+"', '"+div+"')",
		errorfunc:"ajaxError()" }
	);
	return false;
}

function redir(url, div){
	setTimeout("window.location='"+url+"'", 3000);
}

function onById(id){
	document.getElementById(id).style.display = "block";
}
function offById(id){
	document.getElementById(id).style.display = "none";
}
function ajaxError(){
	alert( "There was an error encountered while performing the request. Please try again later." );
}
function getById(id){
	return document.getElementById(id);
}

function MsgBox(msg,msg1)
{
  spring = window.confirm(msg1);
  if (spring == true)
    openNewWindow(msg);
}

function openNewWindow(msg)
{
  window.location = msg;
}


function toggle(id){
  if (document.getElementById(id).style.display=='none')
    document.getElementById(id).style.display='';
  else
    document.getElementById(id).style.display='none';
}
