
///////////////----------OnKeyPress Event code to restrinct Kayboard input starts----------//////////
var KEY_NULL = null;
var KEY_NONE = 0;
var KEY_BCKSPC = 8;
var KEY_TAB = 9;
var KEY_ENTER = 13;
var KEY_ESC = 27;


function validData(e,field) {
	var key;
	var keychar;	

	
	if (window.event) {
		key = window.event.keyCode;
	}
	else if (e) {
		key = e.which;
	}
	else {
		return true;
	}
	keychar = String.fromCharCode(key);
 //characters which are allowed 
	switch(field)
	{
		case "name":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'. "
			break;	
		case "text":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'. "
			break;	
		case "email":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890@_."
			break;	
		case "design":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ()'.:[]-&,;{}\@#%^*?/_"
			break;	
		case "city":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&. ()"
			break;	
		case "num":
			chars = "0123456789";
			break;
		case "nameSpl":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\"abcdefghijklmnopqrstuvwxyz1234567890()'.:[]-&,;{}@#%^*?/_ "
			break;	
		case "phone":
			chars = "1234567890-+"
			break;	
		case "bcity":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz& "
			break;	
		case "num":
			chars = "0123456789"
			break;
		case "web":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890@_./\-%:?=&#"
			break;
		case "mobile":
			chars = "1234567890-+()"
			break;
		case "strurl":
			chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890.&:// "
			break;					
	}
	// Control keys (no @#document.getElementById% "magic numbers")
	if (
	(key == KEY_NULL) || 
	(key == KEY_NONE) || 
	(key == KEY_BCKSPC) || 
	(key == KEY_TAB) || 
	(key == KEY_ENTER) || 
	(key == KEY_ESC) || 
	((chars).indexOf(keychar) > -1)) 
    {
		return true;
	}
	/*else if (e1 == 'dec') 
    { // Decimal point allowed
		if (keychar == '.') 
        {
			if (this.value.indexOf('.') == -1)
            { // Can only have a single decimal point
				return true;
			}
		}
	} */
	return false;
}

//////////////----------OnKeyPress Event code to restrinct Kayboard input ends----------//////////

function textCounter(field,cntfield,maxlimit) 
{
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
    cntfield.value = maxlimit - field.value.length;
}
/* Function to delete leading and trailing spaces*/
function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}


function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;
    elements.push(element);
  }

  return elements;
}

function IsChar(sText)
{
	var ValidChars = "0123456789 -+";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = "false";
			//alert ("please enter numeric only.");						
		}
	}
	
	return IsNumber;   
}//number validation


function limitText(limitField, limitCount, limitNum) 
{			
	if (limitField.value.length > limitNum) 
	{
		limitField.value = limitField.value.substring(0, limitNum);
	}
	else 
	{
		limitCount.value = limitNum - limitField.value.length;
	}
}


function alt_null()
{
	document.getElementById("alt_company").innerHTML = "";	
	document.getElementById("alt_keyperson").innerHTML ="";
	document.getElementById("alt_address").innerHTML ="";
	document.getElementById("alt_tel").innerHTML ="";
	document.getElementById("alt_fax").innerHTML ="";
	document.getElementById("alt_email").innerHTML ="";
	document.getElementById("alt_weburl").innerHTML = "";
	document.getElementById("alt_enq").innerHTML ="";	
//document.getElementById("alt_enq1").innerHTML ="";	
	
}
function emailCheck (emailStr) {

alt_null();	
	var err1;
   	err1=0;
	
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;

}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
   }
}
//return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
document.getElementById("alt_email").innerHTML ="Please enter valid email address";
document.frmenq.txtcount.value="";
return false;
}

// If we've gotten this far, everything's valid!
//return true;

if(true)
{
document.frmenq.txtcount.value="1";

}
}

function validate()
{
	alt_null();	
	var err;
   	err=0;
	frm = document.frmenq;
	
	//alert(document.frmenq.txtcount.value);
	
	/*if(frm.address.value == "")
	{			
		document.getElementById("alt_address").innerHTML= "Please enter address";
		err =1 ;
	}	*/	
	
	
		
	
	
	/*
	if(frm.fax.value == "")
	{			
		document.getElementById("alt_fax").innerHTML= "Please enter fax no.";
		err =1 ;
	}*/
		
	

	
	
	
	if(frm.email.value == "")
	{			
		document.getElementById("alt_email").innerHTML= "Please enter email address";
		err =1 ;
	}	
	if(trim(frm.email.value)!="")
	  	{
			var email=frm.email.value;
			var emailstr=email.toLowerCase();
			emailCheck(emailstr);
			
		}
	if(document.frmenq.txtcount.value=="")
	{
				err =1 ;
	}
	if(frm.txturl.value != "")
	{
	
		
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(frm.txturl.value)) {
        document.getElementById("alt_weburl").innerHTML= "Please enter proper url";
	 //  alert("hai");
		err =1 ;
    }
		
	}	
	if(frm.address1.value == "")
	{			
		document.getElementById("alt_enq").innerHTML= "Please enter enquiry details";
		err =1 ;
	}	
	if(frm.address1.value != "")
	{			
		
		var mytext=trim(frm.address1.value);
		pop=frm.address1.value;
		var ValidChars = " ";
		Char = pop.charAt(0);
		if (ValidChars.indexOf(Char) != -1) 
		{
			document.getElementById("alt_enq").innerHTML= "Please enter proper enquiry details";
			frm.address1.focus();
			frm.address1.select();
			err=1;
		}
	}		   
	if(frm.tel.value == "")
	{			
		document.getElementById("alt_tel").innerHTML= "Please enter telephone no.";
		err =1 ;
	}	
	if(frm.address.value != "")
	{			
		var mytext=trim(frm.address.value);
		pop=frm.address.value;
		var ValidChars = " ";
		Char = pop.charAt(0);
		if (ValidChars.indexOf(Char) != -1) 
		{
			document.getElementById("alt_address").innerHTML= "Please enter proper address";
			frm.address.focus();
			frm.address.select();
			err=1;
		}
	}	
	if(frm.keyperson.value == "")
	{			
		document.getElementById("alt_keyperson").innerHTML= "Please enter key person";
		frm.keyperson.focus();
		err =1 ;
	}	
	
	if(frm.keyperson.value != "")
	{			
		var mytext=trim(frm.keyperson.value);
		pop=frm.keyperson.value;
		var ValidChars = " ";
		Char = pop.charAt(0);
		if (ValidChars.indexOf(Char) != -1) 
		{
			document.getElementById("alt_keyperson").innerHTML= "Please enter proper key person name";
			frm.keyperson.focus();
			frm.keyperson.select();
			err=1;
		}
	}	
	if(frm.company.value == "")
	{			
		document.getElementById("alt_company").innerHTML= "Please enter company name";
		frm.company.focus();
		err =1 ;
	}
	
	if(frm.company.value != "")
	{
		var mytext=trim(frm.company.value);
		pop=frm.company.value;
		var ValidChars = " ";
		Char = pop.charAt(0);
		if (ValidChars.indexOf(Char) != -1) 
		{
			document.getElementById("alt_company").innerHTML= "Please enter proper company name";
			frm.company.focus();
			frm.company.select();
			err=1;
		}	
	}
	
	if(err==1)
	{
		return false;
	}	
}
function search()
{
if(document.formSearch.txtSearch.value=="")
document.formSearch.txtSearch.value="Search Product";

}

function productsearch()
{
//if(document.formSearch.txtSearch.value=="")
document.formSearch.txtSearch.value="";

}
function GetXmlHttpObject()
{ 
     var objXMLHttp=null
     if (window.XMLHttpRequest)
     {
          objXMLHttp=new XMLHttpRequest()
     }
     else if (window.ActiveXObject)
     {
          objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
     }
     return objXMLHttp
}
var xmlHttp=null;
function product(product,search,flag)
{
	//alert(product);
	
	xmlHttp=GetXmlHttpObject()
	//alert(product);

	    if(xmlHttp==null)
	    {
	        alert("Browser does not support HTTP Request");
	        return false;
	    }
		
	    var url="productdetail.asp";
		//alert(url);
	    url=url+"?product="+product+"&searchFlag="+flag+"&searchText="+search;  
		//alert(url);
	    xmlHttp.onreadystatechange=stateChanged; 
	    xmlHttp.open("GET",url,true);
	    xmlHttp.send(null);
	
	function stateChanged() 
	{ 
	    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	    { 
			str = xmlHttp.responseText;
			
			document.getElementById("datamsg").innerHTML=str;
			
	    } 
	}

}


