function init()
{
document.enqform.name.focus();
}
function validate()
{
var enq_name=Trim(document.enqform.name.value);
var enq_mail=Trim(document.enqform.mail.value);
var address=Trim(document.enqform.address.value);
var telephone=Trim(document.enqform.telephone.value);
var org=Trim(document.enqform.org.value);

	if(enq_name.length==0)
	{
		alert("Please fill up your name.");
		document.enqform.name.focus();
		return false;
	}
	else if(!specialCheck(enq_name))
		{
		 alert("Invalid entry in the Name field");
 		 document.enqform.name.select();
		 return false;
		}
		else if(org.length==0)
	{
		alert("Please fill your organisation");
		document.enqform.org.focus();
		return false;
	}
	else if(address.length==0)
	{
		alert("Please fill your address");
		document.enqform.address.focus();
		return false;
	}
	else if(telephone=="")
	{
		alert("Please fill your Telephone Number");
		document.enqform.telephone.focus();
		return false;
	}
	else if(checkInternationalPhone(telephone)==false && telephone!=""){
			alert("Please Enter a Valid Telephone Number");
			document.enqform.telephone.value="";
			document.enqform.telephone.focus();
			return false;
		}
	//else if(enq_mail.length==0)
	//{
		//alert("Please fill up your email ID.");
		//document.enqform.mail.focus();
		//return false;
	//}
	//else if(enq_mail.indexOf('@')==-1||enq_mail.indexOf('.')==-1)
	//{
		//alert("Your email address is in invalid format.\nPlease write in a proper format eg. xyz@email.com.");
		//document.enqform.mail.select();
		//return false;
	//}
	else
		return true;
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function calladd(param1)
		{
		document.frm.method = "post";
		document.frm.action = param1;
		document.frm.submit();
		}
		
function calledit(param2)
{	var s;
	var ml = document.frm;
	var len = ml.elements.length;
	total = 0;
	for (var i=0; i<len; i++)
	{	    
		var e = ml.elements[i];
		if (e.name == "sel" &&  e.checked) 
		{
			total = total + 1;
			s = e.value;
		}
	}
	if (total == 1)
	{
			if (confirm("Are you sure want to Edit this Record?"))
		{	  
			document.frm.method ="post";
			document.frm.action=param2;
			document.frm.submit();   
		}				
	}
	else
	{
		alert(" You must select atleast one Record to Edit");
	}
}

		
	function calldel(param3)
	{
		ml = document.frm;
		len = ml.elements.length;
		total = 0;
	
		for (i=0; i<len; i++)
		{	    
			e = ml.elements[i];
			if (e.name == "sel" &&  e.checked) 
			{
				total = total + 1;
				s = e.value;
			}
		}
		if ( total == 1)
		{
				if (confirm("Are you sure want to Delete this Record?"))
				{

					document.frm.method ="post";
					document.frm.action=param3+"?del=del";
					document.frm.submit();   
				}				
		}
		else
		{
			alert(" You must select One Record to Delete");
		}
	}

function LTrim(str)
        
        {
                var whitespace = new String(" \t\n\r");
                var s = new String(str);
                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...
                    var j=0, i = s.length;
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;

                    s = s.substring(j, i);
                }
                return s;
        }


function RTrim(str)
              {
                var whitespace = new String(" \t\n\r");
                var s = new String(str);
                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

                    var i = s.length - 1;       // Get length of string
                   
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;
                   
                    s = s.substring(0, i+1);
                }
                return s;
        }

function Trim(str)
             {
                return RTrim(LTrim(str));
        }
	
function focusField()
{
document.frm.name.focus();
}

function validName() {
  var name=Trim(document.frm.name.value);
  if(name=="")
  {
  alert("Please enter the sellers name");
  document.frm.name.focus();
  return false;
  }
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-, ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
//var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s));
//return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function specialCheck(xField)
{
var i, check;
	check = true;
	i = xField.length;
	
	for( j =0;j<=i;j++ )
	{
		pos = xField.charAt(j);
		if ( pos == "~" || pos == "'" || pos == "!" || pos == "$" )
		{
		check = false;
		}
		else if ( pos == "@" || pos == "#" || pos == "%" || pos == "^")
		{
		check = false;
		}
		else if ( pos == "*" || pos == "{" || pos == "}" || pos == ";")
		{
		check = false;
		}
		else if ( pos == ":" ||  pos == "|" || pos == "<")
		{
		check = false;
		}
		else if ( pos == "1" || pos == "2" || pos == "3" || pos == "4")
		{
		check = false;
		}
		else if ( pos == "5" ||  pos == "6" || pos == "7")
		{
		check = false;
		}
		else if ( pos == "8" ||  pos == "9" || pos == "0")
		{
		check = false;
		}
	}
return check;		
}	