function fnKeyDownHandler(getdropdown, e)
  {
    fnSanityCheck(getdropdown);
    var vEventKeyCode = FindKeyCode(e);
    if(vEventKeyCode == 46)
    {
    fnDelete(getdropdown);
    }
    if(vEventKeyCode == 8 || vEventKeyCode==127)
    {
    if(e.which)
    {
    }
    else
    {
      e.keyCode = '';
      if(window.event.keyCode)
      {
      window.event.keyCode = '';
      }
    }
    return true;
    }

  }

  function fnDelete(getdropdown)
  {
    if(getdropdown.options.length != 0)
     {
    if (getdropdown.options.selectedIndex == vEditableOptionIndex_A)
     {
      getdropdown.options[getdropdown.options.selectedIndex].text = '';
      getdropdown.options[getdropdown.options.selectedIndex].value = ''; 
     }
    }
  }


 function FindKeyCode(e)
  {
    if(e.which)
    {
    keycode=e.which;  
    }
    else
    {
    keycode=e.keyCode; 
    }

    return keycode;
  }

  function FindKeyChar(e)
  {
    keycode = FindKeyCode(e);
    if((keycode==8)||(keycode==127))
    {
    character="backspace"
    }
    else if((keycode==46))
    {
    character="delete"
    }
    else
    {
    character=String.fromCharCode(keycode);
    }

    return character;
  }

  function fnSanityCheck(getdropdown)
  {
    if(vEditableOptionIndex_A>(getdropdown.options.length-1))
    {
    alert("PROGRAMMING ERROR: The value of variable vEditableOptionIndex_... cannot be greater than (length of dropdown - 1)");
    return false;
    }
  }

  var vEditableOptionIndex_A = 10;
  var vEditableOptionText_A = "--?--";
  var vPreviousSelectIndex_A = 0;
  var vSelectIndex_A = 0;
  var vSelectChange_A = 'MANUAL_CLICK';
  function fnChangeHandler_A(getdropdown)
  {
    fnSanityCheck(getdropdown);
    vPreviousSelectIndex_A = vSelectIndex_A;
    vSelectIndex_A = getdropdown.options.selectedIndex;
    if ((vPreviousSelectIndex_A == (vEditableOptionIndex_A)) && (vSelectIndex_A != (vEditableOptionIndex_A))&&(vSelectChange_A != 'MANUAL_CLICK'))
    {
      getdropdown[(vEditableOptionIndex_A)].selected=true;
      vPreviousSelectIndex_A = vSelectIndex_A;
      vSelectIndex_A = getdropdown.options.selectedIndex;
      vSelectChange_A = 'MANUAL_CLICK';
    }
  }

  function fnKeyPressHandler_A(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    keycode = FindKeyCode(e);
    keychar = FindKeyChar(e);

    if ((keycode>47 && keycode<59)||(keycode>62 && keycode<127) ||(keycode==32))
    {
      var vAllowableCharacter = "yes";
    }
    else
    {
      var vAllowableCharacter = "no";
    }

    if(getdropdown.options.length != 0)
      if (getdropdown.options.selectedIndex == (vEditableOptionIndex_A))
      {

        var vEditString = getdropdown[vEditableOptionIndex_A].text;
        if((vAllowableCharacter == "yes")||(keychar=="backspace"))
        {
          if (vEditString == vEditableOptionText_A)
            vEditString = "";
        }
        if (keychar=="backspace")
        {
          vEditString = vEditString.substring(0,vEditString.length-1);
          vSelectChange_A = 'MANUAL_CLICK';
        }

        if (vAllowableCharacter == "yes")
        {
          vEditString+=String.fromCharCode(keycode);
          var i=0;
          var vEnteredChar = String.fromCharCode(keycode);
          var vUpperCaseEnteredChar = vEnteredChar;
          var vLowerCaseEnteredChar = vEnteredChar;


          if(((keycode)>=97)&&((keycode)<=122))
            vUpperCaseEnteredChar = String.fromCharCode(keycode - 32);


          if(((keycode)>=65)&&((keycode)<=90))
            vLowerCaseEnteredChar = String.fromCharCode(keycode + 32);

          if(e.which)           {
            for (i=0;i<=(getdropdown.options.length-1);i++)
            {
              if(i!=vEditableOptionIndex_A)
              {
                var vReadOnlyString = getdropdown[i].text;
                var vFirstChar = vReadOnlyString.substring(0,1);
                if((vFirstChar == vUpperCaseEnteredChar)||(vFirstChar == vLowerCaseEnteredChar))
                {
                  vSelectChange_A = 'AUTO_SYSTEM';
                  break;
                }
                else
                {
                  vSelectChange_A = 'MANUAL_CLICK';
                }
              }
            }
          }
        }

        getdropdown.options[vEditableOptionIndex_A].text = vEditString;
        getdropdown.options[vEditableOptionIndex_A].value = vEditString; //Use this line only if want to change the internal value too; else this line is not required.

        return false;
      }
    return true;
  }

  function fnKeyUpHandler_A(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    if(e.which) 
    {
      if(vSelectChange_A == 'AUTO_SYSTEM')
      {
        getdropdown[(vEditableOptionIndex_A)].selected=true;
      }

      var vEventKeyCode = FindKeyCode(e);
      if((vEventKeyCode == 37)||(vEventKeyCode == 39))
      {
        getdropdown[vEditableOptionIndex_A].selected=true;
      }
    }
  }

	function finalize(){ 
		
		var phone_num = document.contactus.phone1.value+document.contactus.phone2.value+document.contactus.phone3.value;
		
		if (isEmpty(document.contactus.fname.value))
			return false;
		else if (isEmpty(document.contactus.lname.value)) 	
			return false;
		else if (isEmpty(document.contactus.company.value)) 	
			return false;
        else if (checkDropdown(document.contactus.bs_type.selectedIndex) == 0) 	
			return false;	
        else if (checkDropdown(document.contactus.channel.selectedIndex) == 0) 	
			return false;							
		else if (isEmpty(document.contactus.email.value)) 	
			return false;
		else if (document.contactus.giftbox.checked)
			{		
			if (isEmpty(document.contactus.address.value)) 	
			return false;
			else if (isEmpty(document.contactus.city.value)) 	
			return false;
        	else if (checkDropdown(document.contactus.province.selectedIndex) == 0) 	
			return false; 
			else if (isEmpty(document.contactus.pcode.value)) 	
			return false;
			else if (isEmpty(phone_num)) 	
			return false;
			else return true;
			}
			
		else return true;
	}


	function validate(field_id, error) {
		
		lable_id = field_id;
		error_mess = error;
		
		switch (lable_id)
		{
			// Reqiestor Information
			case f_name:
				name = document.contactus.fname.value;
				
				if (isEmpty(name)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case l_name:
				name = document.contactus.lname.value;
				
				if (isEmpty(name)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case comp:
				var cname = document.contactus.company.value;
				
				if (isEmpty(cname)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case addr:
				if (isEmpty(document.contactus.address.value)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case r_city:
				//name = document.contactus.lname.value;
				
				if (isEmpty(document.contactus.city.value)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case p_code:
				//name = document.contactus.lname.value;
				
				if (isEmpty(document.contactus.pcode.value)) 
				{  process(); }					
													
				else {blank(); }
				
			break;
			
			case r_email:
				if (isEmpty(document.contactus.email.value)) 
					{   process();	}
					
				else if (isEmail(document.contactus.email.value))
					{ blank();	}
				
				else { process();}
				
			break;

			case phone:
				var phone_num = document.contactus.phone1.value+document.contactus.phone2.value+document.contactus.phone3.value;
				
				if (isEmpty(phone_num)) 
					{   process();	}
				else {blank()};
					
				 
				 		for (i = 0; i < phone_num.length; i++)
    			 		{   
        					// Check that current character is number or letter.
        					var c = phone_num.charAt(i);

       						 if (! isDigit(c) ) {
					 			error_mess = 'Digits Only!';
        						process();
								break;
					 		}
							else blank();
    			 		}	
								
			break;			
			
			case fax:
				var fax_num = document.contactus.fax1.value+document.contactus.fax2.value+document.contactus.fax3.value;
				
				if (isEmpty(fax_num)) 
					{   process();	}
				else {blank()};
					
				 
				 		for (i = 0; i < fax_num.length; i++)
    			 		{   
        					// Check that current character is number or letter.
        					var c = fax_num.charAt(i);

       						 if (! isDigit(c) ) {
					 			error_mess = 'Digits Only!';
        						process();
								break;
					 		}
							else blank();
    			 		}	
								
			break;		
			
		} 
		
	} //end of validate function
	
    function checkDropdown(choice) 
    {
       return choice;
    }
   
	function isEmpty(s)
	{   
		//document.write("isempty: " + s);
		return ((s == null) || (s.length == 0 ))
	}	
	
	function chkForDigit (s, message){
		//alert ("1");
		for (i = 0; i < s.length; i++)
    	{   //alert ("2");
				// Check that current character is number or letter.
				var c = s.charAt(i);
	
				 if (isDigit(c) ) {
				 //alert ("3");
					error_mess = message;
					process();
					break;
				}
				else blank();
		}	
	}
	// Returns true if character c is a digit 
	// (0 .. 9).

	function isDigit (c)
	{   return ((c >= "0") && (c <= "9"))
	}
	
	
	function blank() {
		lable_id.innerText = ' ';
		//global_flag = true;
	}
	
	function process() 
	{	lable_id.innerText = error_mess; }

	
	function isWhitespace (s)
	{   var i;
		var whitespace = " \t\n\r";
	
		// Is s empty?
		if (isEmpty(s)) return true;
	
		// Search through string's characters one by one
		// until we find a non-whitespace character.
		// When we do, return false; if we don't, return true.
	
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
	
			if (whitespace.indexOf(c) == -1) return false;
		}
	
		// All characters are whitespace.
		return true;
	}

	
	// isEmail (STRING s [, BOOLEAN emptyOK])
	// 
	// Email address must be of form a@b.c -- in other words:
	// * there must be at least one character before the @
	// * there must be at least one character before and after the .
	// * the characters @ and . are both required
	//
	// For explanation of optional argument emptyOK,
	// see comments of function isInteger.

	function isEmail (s)
	{   					   
	   
		// is s whitespace?
		if (isWhitespace(s))
		{
			error_mess = 'ERROR: Email address must not have spaces between them!';
			return false; 
		}
		else
			{blank();}
		
		
		// there must be >= 1 character before @, so we
		// start looking at character position 1 
		// (i.e. second character)
		var i = 1;
		var sLength = s.length;
	
		// look for @
		while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++;
		}
	
		if ((i >= sLength) || (s.charAt(i) != "@"))
		{
			 //return false;
			 error_mess = 'ERROR: missing character before/after "@"!';
			 return false;
		}
		else i += 2;
	
		// look for .
		while ((i < sLength) && (s.charAt(i) != "."))
		{ i++;
		}
	
		// there must be at least one character after the .
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
		{
			error_mess ='ERROR: missing character before/after "." !';
			return false;
		}
		else 
		{ 
			return true;
		}
	}
	
	function showvalues()
	{
	alert (document.contactus.title.options[document.contactus.title.selectedIndex].value);
	}
	
	function copyData(from,to) { to.value = from.value; }
	
	function showDetails(sDest, vari) {
   dest = document.all[sDest]
   if (vari.checked) {
   dest.style.display = "block";
   dest.style.zIndex = "4";
   }
   else dest.style.display = "none";
   
}