// JavaScript Document
/*-------------------- admin part -------------------*/
 function operationIlustration(id, action_sub, form_name, link_cmd) {
	var visible;
	visible = 1 ;
	if(action_sub == "remove"){
		action_sub = action_sub + "&cmd=operation";
		visible = 0;
	}//end if
	eval("document." + form_name + ".action = 'ilustration.php?visible_form=" + visible + "&action_sub=" + action_sub + "&id=" + id + link_cmd + "'");
	eval("document." + form_name + ".submit()");
	return true;
 }//end function modifyIlustration()



 function operationCategoryIlustration(id, action_sub, form_name, link_cmd) {
	var visible;
	visible = 1 ;

	if(action_sub == "remove"){
		visible = 0;
		action_sub = action_sub + "&cmd=operation_categories"; 
	}//end if
	else {
		action_sub = action_sub + "&cmd=list_categories"; 
	}
	eval("document." + form_name + ".action = 'ilustration.php?visible_form=" + visible + "&action_sub=" + action_sub + "&id=" + id + link_cmd + "'");
	eval("document." + form_name + ".submit()");
	return true;
 }//end function modifyIlustration()

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();
}

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();


function validateGeneralForm(formname){
	var error="";
	var error1;
	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<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;
				eval("document."+formname+"."+emailFields[i]+".focus()");
			}
		}
	}
	if(error){
		alert(alert_title+":"+error);
		return false;
	}else{
		if(error1){
			alert(alert_email);
			return false;
		}else{
			return true;
		}
	}
}
function emailCheckMultiple(formname,emailfield)
{
	var formname;
	var emailfield;
	if (eval("document."+formname+"."+emailfield+".value") == "")
	 { alert("Bitte tragen Sie Ihre Email-Adresse ein!");
	   
	   return false;}
      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];
	   
        var returnVal = false
        checkVal = 0
        period = 0
        count1 = 0
        count2 = 0
        
        for (var i=0; i < item.length; i++)
        {
                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);
		        if(p[0].length<1){
		        	var ret=1;
		        	fout="The address mail must contain an '@'";
		        }
		        
		        if(r[0].length<1){
		        	var ret=1;
		        	fout="Pls. use less one '.' after '@'";
		        }
		        if(r[lungime].length<2){
		        	var ret=1;
		        	fout="Pls. use only one '.' after '@'!";
		        }
		        if(r[lungime].length>3){
		        	var ret=1;
		        	fout="Domain extension is to large!";
		        }
		        if(ret==1){
		        	returnVal=false;
		        }else{
		        	returnVal = true
		        }
               
               
                
        }
        else
		var fout = "";	
        
        if (returnVal == false)
        {
                alert('The adress email isn\'t correct!\n'+fout)
   			   

        }else{
        	if(p[0].substring(0,4)=='www.'){
		        	return confirm("The address email doesn't contain usualy \"www\".\nIs this email address correct?:"+item+" ?");
		        	
		        	
		        }
        }
	}
        return returnVal
}

function showHideLayer_menu(layerName, actionType, frameName)
{

	//if no action specified, this function will toggle the current state	
	if (actionType == 2)
	{
		if (frameName != null)
		{
				new_style = (top.frames[frameName].document.getElementById(layerName).style.display != "none") ? "none" : "";		   
		}
		else
		{
   	 		 if(document.getElementById(layerName).style.display != "none"){
				//this not working on opera : later see why?
				new_style = "none";
			}
			else {
				new_style = "";
			}
   	}   
   }
   else
   {
   	new_style = (actionType == 1) ? "" : "none";
   }
   if (frameName != null)
	{
	   top.frames[frameName].document.getElementById(layerName).style.display = new_style;
	}
	else
	{
	   document.getElementById(layerName).style.display = new_style;
	}   
}
