var site_url = "http://www.kerambit-fiocchi.com";
//var site_url = "http://192.168.0.4/kerambit";
var NN3 = false;

img = new Array
image1 = new Image();
image1.src = site_url + "/image/img1_off.gif";
image1on = new Image();
image1on.src = site_url + "/image/img1_on.gif";
image2 = new Image();
image2.src = site_url + "/image/img2_off.gif";
image2on = new Image();
image2on.src = site_url + "/image/img2_on.gif";
image3 = new Image();
image3.src = site_url + "/image/img3_off.gif";
image3on = new Image();
image3on.src = site_url + "/image/img3_on.gif";
image4 = new Image();
image4.src = site_url + "/image/img4_off.gif";
image4on = new Image();
image4on.src = site_url + "/image/img4_on.gif";

function on3(name)   {
        document[name].src = eval(name + "on.src");
}

function off3(name)  {
        document[name].src = eval(name + ".src");
}

NN3 = true;
function on(name)  {
        if (NN3) on3(name);
}

function off(name)  {
        if (NN3) off3(name);
}
// Default Statusbar
defaultStatus="-=[ Welcome To Kerambit-Fiocchi ]=-"

// Email Form Validations
function init()	{
                define('realname','string','Real Name','1','25');
								define('company','string','Company','1','50');
								define('email','email','Email','1','50');
								define('message','string','Message','1','250');								
        				}
// name       	:		the field's name in the form
// type       	:		(string, num, email)
// displayName	:		Name shown in the error message
// min         	:		[minimum num. of characters,null]
// max         	:		[maximum num. of characters,null]

// -----------------------------------------------------------------------------
// Generic Form Validation
//
// Copyright (C) 2000 Jacob Hage - [info@hagedesign.dk]
// Distributed under the terms of the GNU Library General Public License
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// Initializing script  - setting global variables
// -----------------------------------------------------------------------------
var checkObjects		= new Array(); 	// Array containing the objects to validate.
var errors				= ""; 			// Variable holding the error message.
var returnVal			= false; 		// General return value. The validated form will only be submitted if true.
var language			= new Array(); 	// Language independent error messages!
var selectecLanguage	= "english";	// Choose between "english", "danish", "dutch", "french", "spanish", "russian", "portuguese"
language.english		= new Array();
// Error messages in english:
	language.english.header		= "The following error(s) occured:"
	language.english.start		= "->";
	language.english.field		= " Field ";
	language.english.require	= " is required";
	language.english.min		= " and must consist of at least ";
	language.english.max		= " and must not contain more than ";
	language.english.minmax		= " and no more than ";
	language.english.chars		= " characters";
	language.english.num		= " and must contain a number";
	language.english.email		= " must contain a valid e-mail address";
// -----------------------------------------------------------------------------
// define - Call this function in the beginning of the page. I.e. onLoad.
//
// n = name of the input field (Required)
// type= string, num, email (Required)
// min = the value must have at least [min] characters (Optional)
// max = the value must have maximum [max] characters (Optional)
// d = (Optional)
// -----------------------------------------------------------------------------
function define(n,type,HTMLname,min,max,d){
	var p;
	var i;
	var x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length){
    	d=parent.frames[n.substring(p+1)].document;
    	n=n.substring(0,p);
    }
	if(!(x=d[n])&&d.all) x=d.all[n];
	
  	for (i=0;!x&&i<d.forms.length;i++){
  		x=d.forms[i][n];
  	}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++){
		x=define(n,type,HTMLname,min,max,d.layers[i].document);
		return x;		
	}
	
	// Create Object. The name will be "V_something" where something is the "n" parameter above.
	eval("V_"+n+" = new formResult(x,type,HTMLname,min,max);");
	checkObjects[eval(checkObjects.length)] = eval("V_"+n);
}

// -----------------------------------------------------------------------------
// formResult - Used internally to create the objects
// -----------------------------------------------------------------------------
function formResult(form,type,HTMLname,min,max){
	this.form = form;
	this.type = type;
	this.HTMLname = HTMLname;
	this.min  = min;
	this.max  = max;
}

// -----------------------------------------------------------------------------
// validate - Call this function onSubmit and return the "returnVal". (onSubmit="validate();return returnVal;")
// -----------------------------------------------------------------------------
function validate(){
	if(checkObjects.length>0){
		errorObject = "";
	
		for(i=0;i<checkObjects.length;i++){
			validateObject 			= new Object();
			validateObject.form 	= checkObjects[i].form;
			validateObject.HTMLname = checkObjects[i].HTMLname;
			validateObject.val 		= checkObjects[i].form.value;
			validateObject.len 		= checkObjects[i].form.value.length;
			validateObject.min 		= checkObjects[i].min;
			validateObject.max 		= checkObjects[i].max;
			validateObject.type 	= checkObjects[i].type;
			
			//Debug alert line
			//alert("validateObject: "+validateObject+"\nvalidateObject.val: "+validateObject.val+"\nvalidateObject.len: "+validateObject.len+"\nvalidateObject.min,validateObject.max: "+validateObject.min+","+validateObject.max+"\nvalidateObject.type: "+validateObject.type);
			
			// Checking input. If "min" and/or "max" is defined the input has to be within the specific range
			if(validateObject.type == "num" || validateObject.type == "string"){
				if((validateObject.type == "num" && validateObject.len <= 0) || (validateObject.type == "num" && isNaN(validateObject.val))){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].require+language[selectecLanguage].num+"\n";
				} else if (validateObject.min && validateObject.max && (validateObject.len < validateObject.min || validateObject.len > validateObject.max)){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].require+language[selectecLanguage].min+validateObject.min+language[selectecLanguage].minmax+validateObject.max+language[selectecLanguage].chars+"\n";
				} else if (validateObject.min && !validateObject.max && (validateObject.len < validateObject.min)){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].require+language[selectecLanguage].min+validateObject.min+language[selectecLanguage].chars+"\n";
				} else if (validateObject.max && !validateObject.min &&(validateObject.len > validateObject.max)){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].require+language[selectecLanguage].max+validateObject.max+language[selectecLanguage].chars+"\n";
				} else if (!validateObject.min && !validateObject.max && validateObject.len <= 0){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].require+"\n";
				}
			} else if(validateObject.type == "email"){
				// Checking existense of "@" and ".". The length of the input must be at least 5 characters. The "." must neither be preceding the "@" nor follow it.
				if((validateObject.val.indexOf("@") == -1) || (validateObject.val.charAt(0) == ".") || (validateObject.val.charAt(0) == "@") ||(validateObject.len < 6) || (validateObject.val.indexOf(".") == -1) || (validateObject.val.charAt(validateObject.val.indexOf("@")+1) == ".") || (validateObject.val.charAt(validateObject.val.indexOf("@")-1) == ".")){errors+=language[selectecLanguage].start+language[selectecLanguage].field+validateObject.HTMLname+language[selectecLanguage].email+"\n";}
			}
		}
	}
	// Used to set the state of the returnVal. If errors -> show error messages in chosen language
	if(errors){
		alert(language[selectecLanguage].header.concat("\n"+errors));
		errors = "";
		returnVal = false;
	} else {
		returnVal = true;
	}
}
		
