//*************************************************************************************************************//
//Declare the strings to be used in the javascript error messages
var strerr1 =  "Nome utente non valido";
var strerr6 =  "Il nome utente non può essere più lungo di 20 caratteri";

var strerr2 =  "Password non valida";
var strerr42 = "Password attuale non valida";
var strerr43 = "Nuova password non valida";
var strerr44 = "Non hai confermato la tua nuova password";

var strerr3 =  "Cognome non valido";
var strerr4 =  "Nome non valido";
var strerr5 =  "E-mail non valida";		

var strerr7 =  "Anno della Data di nascita non valido";
var strerr8 =  "L'anno della Data di nascita deve essere numerico";
var strerr9 =  "L'anno della Data di nascita deve essere in formato YYYY";
var strerr10 = "L'anno della Data di nascita deve essere successivo al 1900";
var strerr11 = "Giorno della Data di nascita non valido";
var strerr12 = "Mese della Data di nascita non valido";

var strerr13 =  "Lingua non disponibile";
var strerr14 =  "Codice postale non valido";
var strerr15 =  "Paese non valido";
var strerr16 =  "Stato/Provincia non valido";
var strerr17 =  "Città non valida";
var strerr18 =  "Indirizzo non valido";
var strerr19 =  "Telefono principale non valido";

var strerr20 =  "Scheda di rete 1 - Versione driver non valida";
var strerr21 =  "Scheda di rete 1 - Nome non valido";

var strerr22 =  "Scheda audio 1 - Produttore driver non valido";
var strerr23 =  "Scheda audio 1 - Versione driver non valida";
var strerr24 =  "Scheda audio 1 - Nome non valido";

var strerr25 =  "Scheda video 1 - Produttore driver non valido";
var strerr26 =  "Scheda video 1 - Versione driver non valida";
var strerr27 =  "Scheda video 1 - Nome non valido";

var strerr28 =  "Memoria non valida";
var strerr29 =  "La memoria deve essere un numero";

var strerr30 =  "Velocità del processore non valida";
var strerr31 =  "La velocità del processore deve essere un numero";
var strerr32 =  "Modello di processore non valido";
var strerr33 =  "Tipo di processore non valido";

var strerr34 =  "Versione/Data BIOS Scheda Madre non valida";
var strerr35 =  "Chipset Scheda Madre non valido";
var strerr36 =  "Modello Scheda Madre non valido";
var strerr37 =  "Produttore Scheda Madre non valido";

var strerr38 =  "Versione Direct X non valida";

var strerr39 =  "Service Pack non valido";
var strerr40 =  "OS non valido";

var strerr41 =  "Nome del sistema non valido";

var strerr45 =  "Problema vuoto";
var strerr46 =  "Oggetto vuoto";
var strerr47 =  "Sistema non valido";
var strerr48 =  "Prodotto non valido";
var strerr51 =  "FAQ ID non valida";

var strerr49 =  "L'età deve essere un numero";
var strerr50 =  "Per rispettare le leggi ed i regolamenti vigenti in materia, non si raccolgono informazioni provenienti da soggetti di età inferiore ai 16 anni. In questo caso, dovranno essere i tuoi genitori (o il tuo tutore legalmente indicato) ad agire per te.";

var confirmMsgtext = "Elimina sistema:";

var messagestart = "Si sono verificati i seguenti errori:";

//*****************************************************************************************************************//


function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function checkLoginform()
{
	// create error message string variable, with nothing in it

	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false

	//Checking for empty last name field
	trimmed_string = trim(document.login_form.username.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr1 + "\n";
	        //message = message + "Username is invalid\n";
			document.login_form.username.focus();
	}

	//Checking for empty last name field
	trimmed_string = trim(document.login_form.password.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr2 + "\n";
			document.login_form.password.focus();
	}

	form = checkMessage(message);
return form;

}


function checkLoginform2()
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false

	//Checking for empty last name field
	trimmed_string = trim(document.login_form2.username.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr1 + "\n";
			document.login_form2.username.focus();
	}

	//Checking for empty last name field
	trimmed_string = trim(document.login_form2.password.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr2 + "\n";
			document.login_form2.password.focus();
	}

	form = checkMessage(message);
return form;

}


//************************Customer Registration Step 1 validation**********************
//Take in mind that every error is checked to ensure user friendly error messages
//I understand that these if stmts can easily be combined
function checkCUSTREG1()
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false	

	//Checking for empty last name field
	trimmed_string = trim(document.customer_reg_step1.lastname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr3 + "\n";
			document.customer_reg_step1.lastname.focus();
	}

	//Checking for empty first name field
	trimmed_string = trim(document.customer_reg_step1.firstname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr4 + "\n";
			document.customer_reg_step1.firstname.focus();
	}

	//Check the email address
	if (!isEmailAddr(document.customer_reg_step1.email.value))
	{
		message = message + strerr5 + "\n";		
		document.customer_reg_step1.email.focus();
	}

	//Checking for blank username field
	trimmed_string = trim(document.customer_reg_step1.username.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr1 + "\n";
			document.customer_reg_step1.username.focus();
	}
	else
	{
		//Maximum of 12 characters
		if(trimmed_string.length > 20)
		{
			message = message + strerr6 + "\n";
			document.customer_reg_step1.username.focus();
		}
	}

	//Validate the age
	//trimmed_string = trim(document.customer_reg_step1.age.value);

	//If the string is age year
	//if(trimmed_string.length == 0)
	//{
	//	message = message + strerr49 + "\n"
	//	document.customer_reg_step1.age.focus();
	//}
	//else
	//{
		//if the age is numeric
	//	if(isNaN(document.customer_reg_step1.age.value) == true)
	//	{ 
	//		message = message + strerr49 + "\n";
	//		document.customer_reg_step1.age.focus();
	//	}
	//	else
	//	{
			//if the age is over 16
	//		if(document.customer_reg_step1.age.value < 16)
	//		{
	//			message = strerr50 + "\n";
	//			document.customer_reg_step1.age.focus();
	//		}			
	//	}
	//}

	//Language check
	if(document.customer_reg_step1.lang_id.value == 0)
	{
		message = message + strerr13 + "\n";
		document.customer_reg_step1.lang_id.focus();		
	}

	//Zip postal check
	trimmed_string = trim(document.customer_reg_step1.zip_postal.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr14 + "\n";
			document.customer_reg_step1.zip_postal.focus();
	}

	//Country id check
	if(document.customer_reg_step1.country_id.value == 0)
	{
		message = message + strerr15 + "\n";
		document.customer_reg_step1.country_id.focus();		
	}

	//State and Province check
	
    var isIE=document.all?true:false;
    var isDOM=document.getElementById?true:false;
    
    if( isIE )
    {
    	if( divstatetext.style.visibility == "visible" )
    	    document.customer_reg_step1.state_prov.value = document.customer_reg_step1.statetext.value;
        else
    	    document.customer_reg_step1.state_prov.value = document.customer_reg_step1.statelist.options[document.customer_reg_step1.statelist.selectedIndex].value;
    }
    else if( isDOM )
    {
    	if( document.getElementById("divstatetext").style.visibility == "visible" )
    	    document.customer_reg_step1.state_prov.value = document.customer_reg_step1.statetext.value;
        else
    	    document.customer_reg_step1.state_prov.value = document.customer_reg_step1.statelist.options[document.customer_reg_step1.statelist.selectedIndex].value;
    }

	trimmed_string = trim(document.customer_reg_step1.state_prov.value);

	if (trimmed_string.length == 0)
	{
	        message = message + strerr16 + "\n";
			//document.customer_reg_step1.state_prov.focus();
	}

	//City check
	trimmed_string = trim(document.customer_reg_step1.city.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr17 + "\n";
			document.customer_reg_step1.city.focus();
	}

	//Address check
	trimmed_string = trim(document.customer_reg_step1.address.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr18 + "\n";
			document.customer_reg_step1.address.focus();
	}

	//Primary phone 1
	trimmed_string = trim(document.customer_reg_step1.phone1.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr19 + "\n";
			document.customer_reg_step1.phone1.focus();
	}

	form = checkMessage(message);

return form;


} // end of the function checkform()





//************************Customer Registration Step 2 validation**********************

function checkCUSTREG2() 
{
if(document.customer_reg_step2.testbutton.value == 2)
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false	


	form = checkMessage(message);
	return form;

}
else
{
	return true;
}
} // end of the function checkform()



function checkADDSYSTEM()
{
	if(document.customer_reg_step3.testbutton.value == 2)
	{
		// create error message string variable, with nothing in it
		var message = ""; 
		var trimmed_string;
		var form = "";      //The form return of true or false
	
		//Nickname
		trimmed_string = trim(document.customer_reg_step3.nickname.value);
		if (trimmed_string.length == 0) 
		{
				message = message + strerr41 + "\n";
				document.customer_reg_step3.nickname.focus();
				
		}
	
		form = checkMessage(message);
		return form;
	}
	else
	{
		return true;
	}
} // end of the function checkADDSYSTEM()


//*******************************Customer Registration Step 3 - Manual system**********************

function checkCUSTREG3()
{

//Os check

if(document.customer_reg_step3.testbutton.value == 2)
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false

	//Network Driver Version
	//trimmed_string = trim(document.customer_reg_step3.elements['network[0][driver_ver]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr20 + "\n";
	//		document.customer_reg_step3.elements['network[0][driver_ver]'].focus();
	//}

	//Network Name
	//trimmed_string = trim(document.customer_reg_step3.elements['network[0][name]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr21 + "\n";
	//		document.customer_reg_step3.elements['network[0][name]'].focus();
	//}

	//Audio Driver Provider
	//trimmed_string = trim(document.customer_reg_step3.elements['audio[0][driver_prov]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr22 + "\n";
	//		document.customer_reg_step3.elements['audio[0][driver_prov]'].focus();
	//}

	//Audio Driver Version
	//trimmed_string = trim(document.customer_reg_step3.elements['audio[0][driver_ver]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr23 + "\n";
	//		document.customer_reg_step3.elements['audio[0][driver_ver]'].focus();
	//}

	//Audio Name
	//trimmed_string = trim(document.customer_reg_step3.elements['audio[0][name]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr24 + "\n";
	//		document.customer_reg_step3.elements['audio[0][name]'].focus();
	//}

	//Video Driver Provider
	//trimmed_string = trim(document.customer_reg_step3.elements['video[0][driver_prov]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr25 + "\n";
	//		document.customer_reg_step3.elements['video[0][driver_prov]'].focus();
	//}

	//Video Driver Version
	//trimmed_string = trim(document.customer_reg_step3.elements['video[0][driver_ver]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr26 + "\n";
	//		document.customer_reg_step3.elements['video[0][driver_ver]'].focus();
	//}

	//Video Name
	//trimmed_string = trim(document.customer_reg_step3.elements['video[0][name]'].value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr27 + "\n";
	//		document.customer_reg_step3.elements['video[0][name]'].focus();
	//}

	//Memory
	//trimmed_string = trim(document.customer_reg_step3.memory_num.value);
	//if(trimmed_string.length == 0)
	//{
	//	message = message + strerr28 + "\n"
	//	document.customer_reg_step3.memory_num.focus();
	//}
	//else
	//{
		//Memory is numeric
	//	if(isNaN(document.customer_reg_step3.memory_num.value) == true)
	//	{ 
	//		message = message + strerr29 + "\n";
	//		document.customer_reg_step3.memory_num.focus();
	//	}
	//}

	//Processor Speed
	//trimmed_string = trim(document.customer_reg_step3.processor_speed_num.value);
	//if(trimmed_string.length == 0)
	//{
	//	message = message + strerr30 + "\n"
	//	document.customer_reg_step3.processor_speed_num.focus();
	//}
	//else
	//{
		//Processor Speed is numeric
	//	if(isNaN(document.customer_reg_step3.processor_speed_num.value) == true)
	//	{ 
	//		message = message + strerr31 + "\n";
	//		document.customer_reg_step3.processor_speed_num.focus();
	//	}
	//}

	//Processor Model
	//trimmed_string = trim(document.customer_reg_step3.processor_model.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr32 + "\n";
	//		document.customer_reg_step3.processor_model.focus();
	//}

	//Processor Type
	//trimmed_string = trim(document.customer_reg_step3.processor_type.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr33 + "\n";
	//		document.customer_reg_step3.processor_type.focus();
	//}

	//Motherboard Bios Version Date
	//trimmed_string = trim(document.customer_reg_step3.mboard_bios_ver.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr34 + "\n";
	//		document.customer_reg_step3.mboard_bios_ver.focus();
	//}

	//Motherboard Chipset
	//trimmed_string = trim(document.customer_reg_step3.mboard_chipset.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr35 + "\n";
	//		document.customer_reg_step3.mboard_chipset.focus();
	//}

	//Motherboard Model
	//trimmed_string = trim(document.customer_reg_step3.mboard_model.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr36 + "\n";
	//		document.customer_reg_step3.mboard_model.focus();
	//}

	//Motherboard Manufacturer
	//trimmed_string = trim(document.customer_reg_step3.mboard_manufac.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr37 + "\n";
	//		document.customer_reg_step3.mboard_manufac.focus();
	//}

	//Direct X Version
	//trimmed_string = trim(document.customer_reg_step3.directx_ver.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr38 + "\n";
	//		document.customer_reg_step3.directx_ver.focus();
	//}

	//Service Pack
	//trimmed_string = trim(document.customer_reg_step3.os_spack.value);
	//if (trimmed_string.length == 0) 
	//{
	//        message = message + strerr39 + "\n";
	//		document.customer_reg_step3.os_spack.focus();
			
	//}

	//OS ID
	//if(document.customer_reg_step3.os_id.value < 1)
	//{
	//	message = message + strerr40 + "\n";
	//	document.customer_reg_step3.os_id.focus();		
	//}

	//Nickname
	trimmed_string = trim(document.customer_reg_step3.nickname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr41 + "\n";
			document.customer_reg_step3.nickname.focus();
			
	}

	form = checkMessage(message);
	return form;
}
else
{
	return true;
}

} // end of the function checkform()

function CheckSendLogin()
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var form = "";      //The form return of true or false	

	//Check the email address
	if (!isEmailAddr(document.sendlogin.useremail.value))
	{
		message = message + strerr5 + "\n";		
		document.sendlogin.useremail.focus();
	}

	form = checkMessage(message);
return form;

}

function CheckSysAuto()
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false

	//Check nickname
	trimmed_string = trim(document.system.nickname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr41 + "\n";
			document.system.nickname.focus();
	}

	form = checkMessage(message);
return form;

}

function checkEDITPROF()
{
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false	

	//Language check
	if(document.edit_prof.lang_id.value == 0)
	{
		message = message + strerr13 + "\n";
		document.edit_prof.lang_id.focus();		
	}

	//Zip postal check
	trimmed_string = trim(document.edit_prof.zip_postal.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr14 + "\n";
			document.edit_prof.zip_postal.focus();
	}

	//Country id check
	if(document.edit_prof.country_id.value == 0)
	{
		message = message + strerr15 + "\n";
		document.edit_prof.country_id.focus();		
	}

	//State and Province check
    var isIE=document.all?true:false;
    var isDOM=document.getElementById?true:false;

    if( isIE )
    {
    	if( divstatetext.style.visibility == "visible" )
    	    document.edit_prof.state_prov.value = document.edit_prof.statetext.value;
        else
    	    document.edit_prof.state_prov.value = document.edit_prof.statelist.options[document.edit_prof.statelist.selectedIndex].value;
    }
    else if( isDOM )
    {
    	if( document.getElementById("divstatetext").style.visibility == "visible" )
    	    document.edit_prof.state_prov.value = document.edit_prof.statetext.value;
        else
    	    document.edit_prof.state_prov.value = document.edit_prof.statelist.options[document.edit_prof.statelist.selectedIndex].value;
    }

	trimmed_string = trim(document.edit_prof.state_prov.value);

	if (trimmed_string.length == 0) 
	{
	        message = message + strerr16 + "\n";
			//document.edit_prof.state_prov.focus();
	}

	//City check
	trimmed_string = trim(document.edit_prof.city.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr17 + "\n";
			document.edit_prof.city.focus();
	}

	//Address check
	trimmed_string = trim(document.edit_prof.address.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr18 + "\n";
			document.edit_prof.address.focus();
	}

	//Primary phone 1
	trimmed_string = trim(document.edit_prof.phone1.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr19 + "\n";
			document.edit_prof.phone1.focus();
	}

	//Checking for empty last name field
	trimmed_string = trim(document.edit_prof.lastname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr3 + "\n";
			document.edit_prof.lastname.focus();
	}

	//Checking for empty first name field
	trimmed_string = trim(document.edit_prof.firstname.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr4 + "\n";
			document.edit_prof.firstname.focus();
	}

	form = checkMessage(message);
return form;


}



function checkChangePass()
{
	
	// create error message string variable, with nothing in it
	var message = ""; 
	var trimmed_string;
	var form = "";      //The form return of true or false

	trimmed_string = trim(document.changepass.cur_pass.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr42 + "\n";
			document.changepass.cur_pass.focus();
	}

	trimmed_string = trim(document.changepass.new_pass.value);
	if (trimmed_string.length == 0) 
	{
	        message = message + strerr43 + "\n";
			document.changepass.new_pass.focus();
	}

	if(document.changepass.cnew_pass.value != document.changepass.new_pass.value)
	{
		message = message + strerr44 + "\n";
		document.changepass.cnew_pass.focus();
	}
	
	form = checkMessage(message);
return form;

}



function confirmLink(theLink, strQuery)

{



	confirmMsg = confirmMsgtext;

    // Confirmation is not required in the configuration file

    // or browser is Opera (crappy js implementation)

    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {

        return true;

    }



    var is_confirmed = confirm(confirmMsg + '\n' + strQuery);

    if (is_confirmed) {

        theLink.href += '&is_js_confirmed=1';		

    }



    return is_confirmed;

} // end of the 'confirmLink()' function





function isEmailAddr(email)

{

  var result = false

  var theStr = new String(email)

  var index = theStr.indexOf("@");

  if (index > 0)

  {

    var pindex = theStr.indexOf(".",index);

    if ((pindex > index+1) && (theStr.length > pindex+1))

	result = true;

  }

  return result;

}



function checkEMAILSUP()

{

	

	// create error message string variable, with nothing in it

	var message = ""; 

	var trimmed_string;

	var form = "";      //The form return of true or false



	trimmed_string = trim(document.email_support.problem.value);

	if (trimmed_string.length == 0) 

	{

	        message = message + strerr45 + "\n";

			document.email_support.problem.focus();

	}



	trimmed_string = trim(document.email_support.subject.value);

	if (trimmed_string.length == 0) 

	{

	        message = message + strerr46 + "\n";

			document.email_support.subject.focus();

	}



	if(document.email_support.system.value < 1)

	{

		message = message + strerr47 + "\n";

		document.email_support.system.focus();

	}

	

	if(document.email_support.product.value < 1)

	{

		message = message + strerr48 + "\n";

		document.email_support.product.focus();

	}



	form = checkMessage(message);

return form;



}



  

function checkMessage(message)

{

	// is there an error message?   		

	if ( message.length > 0 ) 

	{ 

		   message = messagestart + "\n\n" + message;	

		   alert( message ); // display error message 

	       return false; // return false, not ok to process 

    }

	else 

	{

		   return true; // no error message to display, return ok to process 

	} 



}



function MM_openBrWindow(theURL,winName,features) 

{ //v2.0

  var winpops = window.open(theURL,winName,features);
  winpops.moveTo(0,0);
}



function checkSearchFAQ()

{

	

	var message = ""; 

	var form = "";      //The form return of true or false
	if( document.search_faq.FAQProductID.value < 1 && document.search_faq.faqid.value == '' )

	{

		message = strerr48 + "\n";

		document.search_faq.FAQProductID.focus();

	}

    if( document.search_faq.faqid.value != '' && isNaN( document.search_faq.faqid.value ) )
    {
        message = strerr51 + "\n";
		document.search_faq.faqid.focus();
    }

	form = checkMessage(message);

return form;

}

