// JavaScript Document
// Miscellaneous common functions used on lots of pages

// Open pop-up window
function popwin(aPage, aTarget, w, h, var1, var2){
	x = (640 - w)/2, y = (480 - h)/2;
	if (screen) {
		y = (screen.availHeight - h)/2;
		x = (screen.availWidth - w)/2;
	}
	window.open(aPage,aTarget,'status=no,top=0,left=0,scrollbars=yes,resizable=' +((var1=='resize' || var2=='resize')? 'yes' : 'no')+ ',width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}

// Returns a two-digit number with leading zero appended
// if necessary
function addZero( vNumber ) { 
	return ( ( vNumber < 10 ) ? "0" : "" ) + vNumber;
}





function validate_name(advanced)
{


  pass = 1; //assume everything is ok
  msg = "The following problems were found when trying to submit this form:\n\n";

  //make sure required fields are not empty
  if (isEmpty(document.advanced.f_name.value))
  {
    msg = msg + "- Name cannot be empty\n";
    pass = 0;
  }
   
   if (isEmpty(document.advanced.pno.value))
  {
    msg = msg + "- Please enter your phone\n";
    pass = 0;
  }
  if(document.advanced.pno.value!="")
  {
  
   if(!isNum(document.advanced.pno.value))
   {
   
    msg = msg + "- Please enter a valid phone\n";
    pass = 0;
   
   }
   
   
  }
     
  if (isEmpty(document.advanced.eml.value))
  {
    msg = msg + "- Please enter your email id\n";
    pass = 0;
  }
  
  if(document.advanced.eml.value!="")
  {
  
  if (!isEmail(document.advanced.eml.value))
  {
    msg = msg + "- Please enter a valid email id\n";
    pass = 0;
  }
   


   }
  
  
    if(document.advanced.f_name.value!="")
{
 var str=document.advanced.f_name.value;
  
  var pos1 = str.indexOf (">");
   
  if (pos1>-1)
  {
  
  alert("invalid character > in name field");
  return false;
  }
  var pos2 =str.indexOf("<");
  if (pos2>-1)
  {
  
  alert("invalid character < in name field");
  return false;
  }
  var pos3 =str.indexOf("%20");
  if (pos3>-1)
  {
  
  alert("invalid character %20 in name field");
  return false;
  }
  
  
   var pos4 =str.indexOf("'");
  if (pos4>-1)
  {
  
  alert("invalid character ' in name field");
  return false;
  }
   var pos5 =str.indexOf("=");
  if (pos5>-1)
  {
  
  alert("invalid character = in name field");
  return false;
  }
   var pos6 =str.indexOf("*");
  if (pos6>-1)
  {
  
  alert("invalid character * in name field");
  return false;
  }
   var pos7 =str.indexOf("%");
  if (pos7>-1)
  {
  
  alert("invalid character % in name field");
  return false;
  }
   var pos8 =str.indexOf("@");
  if (pos8>-1)
  {
  
  alert("invalid character @ in name field");
  return false;
  }
  
  
  }
   
   
   
  
 
  
   if (pass == 1)
  {
    return true;
  }
  else
  {
    alert(msg);
    return false;
  }
  
 
  

}

// validators ------------------------------------------------------------------

	
function isEmpty (s) {
	var p = /\S+/;
	return !p.test(s);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}


function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return true;
    else
        return false;
}
