var requiredFields=new Array();
var requiredFieldsName=new Array();
var requiredSelect=new Array();
var requiredSelectName=new Array();
var checkBoxField=new Array();
var checkBoxName=new Array();
var emailFields=new Array();
var checkRadioField=new Array();
var checkRadioName=new Array();

function validateGeneralForm(formname){
	var error="";
	var error1;
	var error2="";

	for(var i=0;i<requiredFields.length;i++){
		if(eval("document."+formname+"."+requiredFields[i]+".value") == ""){
			if(error==""){
				eval("document."+formname+"."+requiredFields[i]+".focus()");
			}
			error=error+"\n   - "+requiredFieldsName[i];
		}
	}

	for(var i=0;i<checkRadioField.length;i++){
		var field = "";
		var cary = 0;
		field = eval("document."+formname+"."+checkRadioField[i]);
		if(eval("document."+formname+"."+checkRadioField[i]+".length")){
			for(j= 0;j < eval("document."+formname+"."+checkRadioField[i]+".length");j++){
				if(!field[j].checked && cary != 1){
					cary = 0;
					if(error==""){
						eval("document."+formname+"."+field[j].name+"[0].focus()");
					}//end if
				}//end if	
				else cary = 1;
			}//end for
		}else{
			if(field.checked){
				cary = 1;
			}
		}
		if(cary == 0) error=error+"\n   - "+checkRadioName[i];
	}//end for

	
	for(var i=0;i<requiredSelect.length;i++){
		if(eval("document."+formname+"."+requiredSelect[i]+".selectedIndex") == "0"){
			if(error==""){
				eval("document."+formname+"."+requiredSelect[i]+".focus()");
			}
			error=error+"\n   - "+requiredSelectName[i];
		}
	}
	
	
		for(var i=0;i<checkBoxField.length;i++){
			if(eval("document."+formname+"."+checkBoxField[i]+".checked") == ""){
				if(error==""){
					eval("document."+formname+"."+checkBoxField[i]+".focus()");
				}//end if
				error=error+"\n   - "+checkBoxName[i];
			}//end if
		}//end for

	for(var i=0;i<emailFields.length;i++){
		if(eval("document."+formname+"."+emailFields[i]+".value") != ""){
			if(!emailCheckMultiple(formname,emailFields[i])){
				error1=1;
				//here I fix this condition to make a priority of fileds focus
				if(!error)eval("document."+formname+"."+emailFields[i]+".focus()");
			}
		}
	}

   
		
	if(error){
		alert("Please fill all mandatory fields:"+error);
		return false;
	}else{
		if(error1){
			alert("Please insert a correct email address!");
			return false;
		}else{
			return true;
		}
	}
}



function emailCheckMultiple(formname,emailfield)
{
	var formname,ret;
	var emailfield;
	  var email_list=eval("document."+formname+"."+emailfield+".value");
      var pl=email_list.split(",");
      for(var j=0;j<pl.length;j++){
		var item = (pl[j].replace(' ','')).replace(' ','');
		var returnVal = false
        checkVal = 0
        period = 0
        count1 = 0
        count2 = 0
		ret = 0
		//----------------- here I check the name of email before @ start -------
		var text_error = item.split('www');	
		if(!text_error["0"])return false;
		var text_error = item.split('@');	
		if(text_error["1"] == "hotmail.de" || text_error["1"] == "aol.de")return false;
		//-----------------------------------------------------------------------		
		
		for (var i=0; i < item.length; i++)
        {
				//------------checking the name between @ and .must be more than 1 char.
				if (item.substring(i,i+1) == '@')
                {
                        checkVal = checkVal + 1
                        count1 = count1 + 1
                }
                if (item.substring(i,i+1) == '!')
                {
                        checkVal = checkVal + 2
                        count2 = count2 + 1
                }
                if (item.substring(i,i+1) == '.')
                {
                        if (period != 1)
                        {
                           checkVal = checkVal + 4
                           period = 1
                        }
                }
                if (item.substring(i,i+1) == ' ')
                {
                        checkVal = 8
                }
                if (item.substring(i,i+1) == ',')
                {
                        checkVal = 8
                }
                if (item.substring(i,i+1) == '"')
                {
                        checkVal = 8
                }
                if (item.substring(i,i+1) == '\'')
                {
                        checkVal = 8
                }
        }
        if (checkVal == 5 || checkVal == 6)
        {
               var p=item.split("@");
               var r=p[1].split(".");
			   var lungime=(r.length-1);
				
				//here I work with the text after "@"
				if(p[0].length<1 || (p[0].search("[^0-9a-zA-Z_\.-]")) > -1){
		        	var ret=1;
		        	fout="1";
		        }
				//here I work with the text between "@" and "."
				if(r[0].length<1){// || r[0].length > 4
		        	var ret=1;
		        	fout="1";
		        }
  		        //here I work with the text before "."
				if(r[lungime].length<2 || r[lungime].length>4){
					if(r[lungime].length<2){//here I check if the domain is one integer
					   if(r[lungime] <= 0 || r[lungime] >= 10)var ret=1;
					}//end if
					else var ret=1;
		        	fout="1";
		        }
				else if(r[lungime] >= 10 || r[lungime] <= 0)var ret=1;//here I check if the domain is an integer between 0 and 10
				if(ret==1){
		        	returnVal=false;
		        }else{
		        	returnVal = true
		        }
        }
        else

        if (checkVal == 0) fout = '1'
        if (checkVal == 1) fout = '1'
        if (checkVal == 2) fout = '1'
        if (checkVal == 3) fout = '1'
        if (checkVal == 4) fout = '1'
        if (checkVal == 7) fout = '1'
        if (checkVal > 7)  fout = '1'

        if (count1 > 1) fout =    '1'
        if (count2 > 1) fout =    '1'
	}
    return returnVal;
}


function window_picture( newsitem, x, y, title )
{
	var thisWindow;
	
	thisWindow = window.open(newsitem,title,"width="+x+",height="+y+",scrollbars=auto,screenX=0,screenY=0,toolbar=no,location=no,menubar=no");
	thisWindow.moveTo((screen.width-x)/2,(screen.height-y)/3);
 	thisWindow.window.focus();
}

function window_picture1( newsitem, x, y, title )
{
	var thisWindow;
		
	thisWindow = window.open(newsitem,title,"width="+x+",height="+y+",scrollbars=yes,screenX=0,screenY=0,toolbar=no,location=no,resizable=yes,menubar=no");
	thisWindow.moveTo((screen.width-x)/2,(screen.height-y)/3);
 	thisWindow.window.focus();
}




function stopErrors() {
	return true;
}



//window.onerror = stopErrors;

