
//contact/contact_suggestion.asp
function checkData()
{	
	var thename = document.TechSupport.name;	
	var thecid = document.TechSupport.cid;	
	var theEmail = document.TechSupport.email;
	var thephone = document.TechSupport.phone;
	var thecategory = document.TechSupport.cat1;
	var theproductID = document.TechSupport.productID;
	var thePN = document.TechSupport.PN;
	var theSN = document.TechSupport.SN;
	var thecomments = document.TechSupport.comments;
	var thepdate = document.TechSupport.pdate;
	var message= "";
	var nospace=true;
	if (thecid.value=='0'){
		message = message + "Please select a region.\n";
		nospace = false;
	}
	if (thename.value.length<2){
		message = message + "Inserire il nome.\n";
		nospace = false;
	}
	if(theEmail.value.length<2 || email_check(theEmail.value)==false){
		message = message + "Inserire un indirizzo valido di posta .\n";
		nospace = false;
	}			
	if(thephone.value.length<6 ){
		message = message + "Inserire il numero di telefono.\n";
		nospace = false;
	}
	if(thecategory.value.length<3){
		message = message + "Selezionare una categoria di prodotto.\n"
		nospace = false;
	}	
	if(theproductID.value.length<3){
		message = message + "Selezionare un prodotto.\n"
		nospace = false;
	}
	if(thePN.value.length<3){
		message = message + "Inserire il numero del prodotto.\n"
		nospace = false;
	}
	if(theSN.value.length<3){
		message = message + "Inserire il numero di serie del prodotto.\n"
		nospace = false;
	}	
	if(thepdate.value.length<4){
		message = message + "Inserire la data d’acquisto del prodotto.\n"
		nospace = false;
	}		
	if(thecomments.value.length<4){
		message = message + "Descrivere il problema nella casella di testo.\n";
		nospace = false;
	}
	if(validateDate(thepdate.value,'J','P') || thepdate.value==''){
	}
	else	
	{
		message = message + "Inserire la data d’acquisto del prodotto.\n"
		nospace = false;
	}	
	if (nospace == false)
      {
        alert(message);
		return false;
      }
	  return nospace;
	  //document.TechSupport.submit();
 } 

 //email check
function email_check(email)
{
   var len = email.length;  
   var ck =0;
   for(var i=0;i<len;i++)
   {  var c= email.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
         return false; 
   }
   if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
      return false;
   if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
      return false; 
   if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
      return false;
}
//Telephone check
function checkNumber(numStr){
	var len = numStr.length;  
	var ck = 0 ;
	var checkstring = "0123456789()_-#^*";
	for(var i=0; i<len; i++){
		var  ddd= numStr.charAt(i);		
		if(checkstring.indexOf(ddd) == -1)
			{return false;}
	}
	return true;
}

function valDateFmt(datefmt) {myOption = -1;
for (i=0; i<datefmt.length; i++) {if (datefmt[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date format");return ' ';}
return datefmt[myOption].value;}
function valDateRng(daterng) {myOption = -1;
for (i=0; i<daterng.length; i++) {if (daterng[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date range");return ' ';}
return daterng[myOption].value;}
function stripBlanks(fld) {
var result = "";
var c="";
for (i=0; i<fld.length; i++) {
if (fld.charAt(i) != " ") {result += fld.charAt(i);
if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}
var numb = '0123456789';
function isValid(parm,val) {if (parm == "") return true;
for (i=0; i<parm.length; i++) {if (val.indexOf(parm.charAt(i),0) == -1)
return false;}return true;}
function isNum(parm) {return isValid(parm,numb);}
var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function validateDate(fld,fmt,rng) {
var dd, mm, yy;var today = new Date;var t = new Date;fld = stripBlanks(fld);
if (fld == '') return false;var d1 = fld.split('\/');
if (d1.length != 3) d1 = fld.split(' ');
if (d1.length != 3) return false;
if (fmt == 'u' || fmt == 'U') {
  dd = d1[1]; mm = d1[0]; yy = d1[2];}
else if (fmt == 'j' || fmt == 'J') {
  dd = d1[2]; mm = d1[1]; yy = d1[0];}
else if (fmt == 'w' || fmt == 'W'){
  dd = d1[0]; mm = d1[1]; yy = d1[2];}
else return false;
var n = dd.lastIndexOf('st');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('nd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('rd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('th');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf(',');
if (n > -1) dd = dd.substr(0,n);
n = mm.lastIndexOf(',');
if (n > -1) mm = mm.substr(0,n);
if (!isNum(dd)) return false;
if (!isNum(yy)) return false;
if (!isNum(mm)) {
  var nn = mm.toLowerCase();
  for (var i=1; i < 13; i++) {
    if (nn == mth[i] ||
        nn == mth[i].substr(0,3)) {mm = i; i = 13;} 
  }
}
if (!isNum(mm)) return false;
dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);
if (yy < 100) yy += 2000;
if (yy < 1582 || yy > 4881) return false;
if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
if (mm < 1 || mm > 12) return false;
if (dd < 1 || dd > day[mm-1]) return false;
t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
if (rng == 'p' || rng == 'P') {
if (t > today) return false;
}
else if (rng == 'f' || rng == 'F') {
if (t < today) return false;
}
else if (rng != 'a' && rng != 'A') return false; 
return true;
}
