/**************************************
Script for Webmaster secondary page
****************************************/

function imposeMaxLength(Object, MaxLen)
{
	
  if(Object.value.length==eval(MaxLen+1))
	{
	  alert('You have exceeded the maximum number of characters allowed in this field. Please shorten your comment to 1000 characters or less.');
	  Object.focus();	
	}
  return (Object.value.length <= MaxLen);
  
}

function isEmail(email) {
  
	invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
        return false;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {	
        badChar = invalidChars.charAt(i);
		
	// To include apostrophe in the email address before '@' symbol				
		if(badChar=="'"){
			if (email.indexOf(badChar,0) > email.indexOf("@",1)) {
				return false;		
				}
			}
		else {
			if (email.indexOf(badChar,0) > -1) {
	            return false;
    	    }
		}
    }
	
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
   if (periodPos+3 > email.length) {
        return false;
    }

    return true;
}

function isTrString(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function isProper(string)
{

   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()@&$#%";

   for (var i = 0; i < string.length; i++) 
   {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
} 
 
function isProper1(string)
{

   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()@&$%";

   for (var i = 0; i < string.length; i++) 
   {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
} 
 
function isProper2(string)
{

   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()@&$%0123456789";

   for (var i = 0; i < string.length; i++) 
   {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
} 
function emptyfield(textObj)
{
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; ++i)
	{
		var ch=textObj.value.charAt(i);
		if (ch != "" && ch != "\t") return false;
	}
	return true;
}
  
function checkForm()
{

	get_radio_value();
	
	if((document.webmasterForm.hddRadioValue.value=='MissingProductInfo')||(document.webmasterForm.hddRadioValue.value=='IncorrectProductInfo'))
	{
		if(document.webmasterForm.Primaryproduct.value=='-- Select One --')
		{
//Start Changes on 20thjuly2006 for Changing the validation message Development of Webmaster form, CaseID-5085621
			alert('Please choose a product category for the missing/incorrect information.');
//End Changes on 20thjuly2006 for Changing the validation message Development of Webmaster form, CaseID-5085621


			document.webmasterForm.Primaryproduct.focus();
			return false;
		}
	}
	if(document.webmasterForm.Note.value.length>=1001)
	{
	  alert('Exceeding Maximum No of Character Limit')
	  document.webmasterForm.Note.focus();	
	  return false;
	}
  	if (emptyfield(document.webmasterForm.email))
	{
	}
	else
	{
		if(!isEmail(document.webmasterForm.email.value))
		{
			alert('Please enter a valid e-mail address');
			document.webmasterForm.email.focus();
            return false;
		}
	}
	

}
function hideAll(valId){ 
		tag = document.getElementsByTagName("span"); 
		for(x=0;x<tag.length; x++){ 
      if((tag[x].getAttribute('id')!= valId)||(valId=='Brokenlink')){ 
		tag[x].style.display = "none"; 
      } 
   } 
} 

function chkFrm(el){ 
  // hideAll(el.value);

   if(el.value=='MissingProductInfo'){
	   document.webmasterForm.selectIncorrectProductInfo.value='select';
       document.webmasterForm.OtherText.value='';
   }

if(el.value=='IncorrectProductInfo'){
	   document.webmasterForm.selectMissingProductInfo.value='select';
       document.webmasterForm.OtherText.value='';
       document.webmasterForm.documentNumber.value='';
   }
   if(el.value=='Other'){
	   document.webmasterForm.selectMissingProductInfo.value='select';
	   document.webmasterForm.selectIncorrectProductInfo.value='select';
       document.webmasterForm.documentNumber.value='';
   }
   if(el.value=='Brokenlink'){
	   document.webmasterForm.selectMissingProductInfo.value='select';
	   document.webmasterForm.selectIncorrectProductInfo.value='select';
       document.webmasterForm.documentNumber.value='';
       document.webmasterForm.OtherText.value='';
   }

/*   for(x=0; x<el.form.radiobutton.length; x++){ 
      if(el.checked){ 
         document.getElementById(el.value).style.display = 'block'; 
      } 
   }*/
   
	

} 

function get_radio_value()
{
	for (var i=0; i < document.webmasterForm.radiobutton.length; i++)
	{
	if (document.webmasterForm.radiobutton[i].checked)
      {
		  document.webmasterForm.hddRadioValue.value= document.webmasterForm.radiobutton[i].value;
		  
      }
   }

}


 function selctedOption(e1)
 {
	if(e1.value=='Can\'t find PDF file (data sheet, installation, brochure, etc.)')
		{
			document.getElementById('documentNumber0').style.display = 'block'; 
		}
		else
		{
			document.getElementById('documentNumber0').style.display = 'none'; 
			document.webmasterForm.documentNumber.value="";		

		}


 }

function gotoPage(varItem, strSupra)
{
  switch(varItem)
  {
    case 1:
    alert(strSupra);
      window.location(strSupra);
      break;
  }
}
