// JavaScript Document
//*============================================================================================#*/ 
//* Function for adding a Filter to an Input Field                                             #*/ 
//* : [filterInputType  ] Type of filter 0=>Alpha, 1=>Num, 2=>AlphaNum                         #*/ 
//* : [evnt      ] The Event Object                                                            #*/ 
//* : [setDecimal] To allow Decimal Point set this to true                                     #*/ 
//* : [setCustom ] Custom Characters that are to be allowed ==this is ditermind at the calling #*/
//*                  page                                                                       */   
//==============================================================================================*/ 
function filterInput(filterInputType, evt, allowDecimal, allowCustom){ 

    var keyCode, Char, inputField, filter = ''; 
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '; 
    var num   = '0123456789'; 
    // Get the Key Code of the Key pressed if possible else - allow 
    if(window.event){ 
        keyCode = window.event.keyCode; 
        evt = window.event; 
    }else if (evt)keyCode = evt.which; 
    else return true; 
    // Setup the allowed Character Set 
    if(filterInputType == 0) filter = alpha; 
    else if(filterInputType == 1) filter = num; 
    else if(filterInputType == 2) filter = alpha + num; 
    if(allowCustom)filter += allowCustom; 
    if(filter == '')return true; 
	
    // Get the Element that triggered the Event 
    inputField = evt.srcElement ? evt.srcElement : evt.target || evt.currentTarget; 
    // If the Key Pressed is a CTRL key like Esc, Enter, Home etc - allow 
    if((keyCode==null) || (keyCode==0) || (keyCode==8) || (keyCode==9) || (keyCode==13) || (keyCode==27) )return true; 
    // Get the Pressed Character 

    Char = String.fromCharCode(keyCode); 
	
    // If the Character is a number - allow 
	//alert(Char);
	//alert(filter.indexOf(Char));
    if((filter.indexOf(Char) > -1))
		{
		return true; 
		}
     //Else if Decimal Point is allowed and the Character is '.' - allow 
    else if(filterInputType == 1 && allowDecimal && (Char == '.') && inputField.value.indexOf('.') == -1)
	{return true;}
    else
	{return false;}
		
	
}
function check_textfield_maxlength(obj){
var field_textfield_mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
if (obj.getAttribute && obj.value.length==field_textfield_mlength)
   {
    obj.value=obj.value.substring(0,field_textfield_mlength);
	alert("Text has reached the maximum limit");
   }
}
function showType(){
	var table = document.getElementById("mytable");
	var tbody = table.getElementsByTagName("TBODY")[0];
	var lastTR = document.getElementById("mytable").rows[table.rows.length - 1];
	var tr = document.createElement("TR");
	var td = document.createElement("TD");
	var ntype = document.getElementById("category").value;
      var maxlen = table.rows.length-9;
	//alert(ntype);
	if (ntype == "3"){
		if (table.rows.length > 9){
			for (var i=1;i<=maxlen;i++){
				table.deleteRow(table.rows.length-2);
			}
		}
		//var boldfont = document.createElement("b");
		var font = document.createElement("FONT");
		font.setAttribute("color", "black");
		font.setAttribute("face", "verdana");
		font.setAttribute("size", "1");
		font.appendChild(document.createTextNode("Our Product  :"));
		//boldfont.appendChild(font);
		//td.appendChild(boldfont);
        	td.appendChild(font);
		tr.appendChild(td);
		var td = document.createElement("TD");
		var input = document.createElement("SELECT");
		input.setAttribute("name", "type");
		var option = document.createElement("OPTION");
		option.setAttribute("value", "14");
		option.appendChild(document.createTextNode("Fire Insurance"));
		var option2 = document.createElement("OPTION");
		option2.setAttribute("value", "15");
		option2.appendChild(document.createTextNode("Miscellanuos Insurance Marketing Corporate/Direct/Broking"));
        	var option3 = document.createElement("OPTION");
		option3.setAttribute("value", "16");
		option3.appendChild(document.createTextNode("Engineering & Project Bonds Insurance"));
        	var option4 = document.createElement("OPTION");
		option4.setAttribute("value", "17");
		option4.appendChild(document.createTextNode("Personal Accident & Misc Agency Insurance"));
		var option5 = document.createElement("OPTION");
		option5.setAttribute("value", "18");
		option5.appendChild(document.createTextNode("FWIG/FWCS & Liability Insurance"));
		var option6 = document.createElement("OPTION");
		option6.setAttribute("value", "19");
		option6.appendChild(document.createTextNode("Motor Non Franchise Insurance"));
		var option7 = document.createElement("OPTION");
		option7.setAttribute("value", "20");
		option7.appendChild(document.createTextNode("Marine Insurance"));
		var option8 = document.createElement("OPTION");
		option8.setAttribute("value", "21");
		option8.appendChild(document.createTextNode("Medical Insurance"));
		var option9 = document.createElement("OPTION");
		option9.setAttribute("value", "22");
		option9.appendChild(document.createTextNode("Professional Indemnity, Products, CGL"));
		input.appendChild(option);
		input.appendChild(option2);
		input.appendChild(option3);
		input.appendChild(option4);
		input.appendChild(option5);
		input.appendChild(option6);
		input.appendChild(option7);
		input.appendChild(option8);
		td.appendChild(input);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tbody.appendChild(lastTR);
	}else if (ntype == "6"){
		if (table.rows.length > 9){
			for (var i=1;i<=maxlen;i++){
				table.deleteRow(table.rows.length-2);
			}
		}
		//var boldfont = document.createElement("b");
		var font = document.createElement("FONT");
		font.setAttribute("color", "black");
		font.setAttribute("face", "verdana");
		font.setAttribute("size", "1");
		font.appendChild(document.createTextNode("HR Enquiries  :"));
		//boldfont.appendChild(font);
		//td.appendChild(boldfont);
        	td.appendChild(font);
		tr.appendChild(td);
		var td = document.createElement("TD");
		var input = document.createElement("SELECT");
		input.setAttribute("name", "type");
		var option = document.createElement("OPTION");
		option.setAttribute("value", "29");
		option.appendChild(document.createTextNode("Employment"));
		var option2 = document.createElement("OPTION");
		option2.setAttribute("value", "30");
		option2.appendChild(document.createTextNode("CSR"));
        	var option3 = document.createElement("OPTION");
		option3.setAttribute("value", "31");
		option3.appendChild(document.createTextNode("Others"));
        	input.appendChild(option);
		input.appendChild(option2);
		input.appendChild(option3);
		td.appendChild(input);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tbody.appendChild(lastTR);
	}else if (ntype == "4"){
		if (table.rows.length > 9){
			for (var i=1;i<=maxlen;i++){
				table.deleteRow(table.rows.length-2);
			}
		}
		//var boldfont = document.createElement("b");
		var font = document.createElement("FONT");
		font.setAttribute("color", "black");
		font.setAttribute("face", "verdana");
		font.setAttribute("size", "1");
		font.appendChild(document.createTextNode("How would you describe yourself  :"));
		//boldfont.appendChild(font);
		//td.appendChild(boldfont);
       	td.appendChild(font);
		tr.appendChild(td);
		tbody.appendChild(tr);
		var tr = document.createElement("TR");
		var td = document.createElement("TD");
		//td.setAttribute("colspan", "2");
		td.colSpan="2";
		var input = document.createElement("SELECT");
		input.setAttribute("name", "type");
		var option = document.createElement("OPTION");
		option.setAttribute("value", "23");
		option.appendChild(document.createTextNode("I'm dealing with or going/would like to deal with Insurance Agent"));
		var option2 = document.createElement("OPTION");
		option2.setAttribute("value", "24");
		option2.appendChild(document.createTextNode("I'm dealing with or going/would like to deal with Insurance Motor Vehicle dealer"));
        	var option3 = document.createElement("OPTION");
		option3.setAttribute("value", "25");
		option3.appendChild(document.createTextNode("I'm working in a Japanese related company or I'm a Japanese Individual"));
        	var option4 = document.createElement("OPTION");
		option4.setAttribute("value", "26");
		option4.appendChild(document.createTextNode("I'm represent my company (non-Japanese) & would like to deal with the company"));
		var option5 = document.createElement("OPTION");
		option5.setAttribute("value", "27");
		option5.appendChild(document.createTextNode(" I am an individual, and would like to deal direct with the company"));
        	input.appendChild(option);
		input.appendChild(option2);
		input.appendChild(option3);
		input.appendChild(option4);
		input.appendChild(option5);
		td.appendChild(input);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tbody.appendChild(lastTR);
	}else if (ntype == "2"){
		if (table.rows.length > 9){
			for (var i=1;i<=maxlen;i++){
				table.deleteRow(table.rows.length-2);
			}
		}
		//var boldfont = document.createElement("b");
		var font = document.createElement("FONT");
		font.setAttribute("color", "black");
		font.setAttribute("face", "verdana");
		font.setAttribute("size", "1");
		font.appendChild(document.createTextNode("Claims Enquiries  :"));
		//boldfont.appendChild(font);
		//td.appendChild(boldfont);
        	td.appendChild(font);
		tr.appendChild(td);
		var td = document.createElement("TD");
		var input = document.createElement("SELECT");
		input.setAttribute("name", "type");
		var option = document.createElement("OPTION");
		option.setAttribute("value", "2");
		option.appendChild(document.createTextNode("Motor-Own damage-Windscreen"));
		var option2 = document.createElement("OPTION");
		option2.setAttribute("value", "3");
		option2.appendChild(document.createTextNode("Motor-Own damage-Theft"));
        	var option3 = document.createElement("OPTION");
		option3.setAttribute("value", "4");
		option3.appendChild(document.createTextNode("Motor-Own damage-Accident Repair"));
		var option4 = document.createElement("OPTION");
		option4.setAttribute("value", "5");
		option4.appendChild(document.createTextNode("Motor-TPPD"));
		var option12 = document.createElement("OPTION");
		option12.setAttribute("value", "6");
		option12.appendChild(document.createTextNode("Motor-TPBI"));
		var option5 = document.createElement("OPTION");
		option5.setAttribute("value", "7");
		option5.appendChild(document.createTextNode("Non Motor-Fire"));
		var option6 = document.createElement("OPTION");
		option6.setAttribute("value", "8");
		option6.appendChild(document.createTextNode("Non Motor-Engineering"));
		var option7 = document.createElement("OPTION");
		option7.setAttribute("value", "9");
		option7.appendChild(document.createTextNode("Non Motor-Misc Acct"));
		var option8 = document.createElement("OPTION");
		option8.setAttribute("value", "10");
		option8.appendChild(document.createTextNode("Non Motor-PA / WCI"));
		var option9 = document.createElement("OPTION");
		option9.setAttribute("value", "11");
		option9.appendChild(document.createTextNode("Non Motor-Marine"));
		var option10 = document.createElement("OPTION");
		option10.setAttribute("value", "12");
		option10.appendChild(document.createTextNode("Non Motor-Liability"));
		var option11 = document.createElement("OPTION");
		option11.setAttribute("value", "13");
		option11.appendChild(document.createTextNode("Non Motor-Medical"));
        	input.appendChild(option);
		input.appendChild(option2);
		input.appendChild(option3);
		input.appendChild(option4);
		input.appendChild(option12);
		input.appendChild(option5);
		input.appendChild(option6);
		input.appendChild(option7);
		input.appendChild(option8);
		input.appendChild(option9);
		input.appendChild(option10);
		input.appendChild(option11);
		td.appendChild(input);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tbody.appendChild(lastTR);
	}
	else{
		if (table.rows.length > 9){
			for (var i=1;i<=maxlen;i++){
				table.deleteRow(table.rows.length-2);
			}
		}
	}
}
var alphanumeric = "`~!@#-_=|]}[{:/?.,";
alphanumeric += " \ ";
//This function is to reset the input field to be space

function resetForm()

{	//this is to reset the field
   document.getElementById("MyForm").reset();
   //this is to empty the value of the field after hiting the Submit button
   document.getElementById("MyForm").elements["user_name"].value = "";
   document.getElementById("MyForm").elements["user_email"].value = "";
   document.getElementById("MyForm").elements["user_contact"].value = "";
   document.getElementById("MyForm").elements["user_contact2"].value = "";
   document.getElementById("MyForm").elements["ex_customer"].value = "";
   document.getElementById("MyForm").elements["user_address"].value = "";
   document.getElementById("MyForm").elements["user_postcode"].value = "";
   document.getElementById("MyForm").elements["enquiry"].value = "";
   document.getElementById("MyForm").elements["con_method"].value = "";

//this is to reset the listbox to display General Enquiries / NCD
//and to hide the sub catogory after hitting the reset button
var category_table = document.getElementById("mytable");
var category_type = document.getElementById("category").value;
var category_maxlen = category_table.rows.length-9;
if (category_type == "1")
   {
		if (category_table.rows.length > 9)
		{
			for (var i=1;i<=category_maxlen;i++)
			{
				category_table.deleteRow(category_table.rows.length-2);
			}
		}
   }	
} 
function checkmaxlength(obj){

var field_mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
if (obj.getAttribute && obj.value.length>field_mlength)
   {
    obj.value=obj.value.substring(0,field_mlength);
	alert("Text has reached the maximum limit");
   }
  //return filterInput(2, event, false, '@_-,`/.');
}