

function validateCode(categoryid,method,key,param){	

	var code = $('code').value;
	if (param == null || param == ''){ param=''; 	}
	var request = '?categoryid='+categoryid+'&method='+method+'&'+key+'='+code+''+param;
	new Ajax.Request(request, {
		onSuccess: function(transport) {
			if (transport.responseText.match('0')){
				var validateMsg = ' The customer code is available';
				var validateClass = 'validation-passed';
				$('submit_button').enable();
				 $('valid').value = true;
			}else{
				var validateMsg = ' The customer code is invalid/used';
				var validateClass = 'validation-advice';
				$('submit_button').disable();
				 $('valid').value = false;	//must be added to the form
			}			
			
			try {
				$('code-validate').value;
				$('code-validate').style.display = 'none';
			}catch(e){
				//do nothing
			}
			var validateHtml = '<span class="'+validateClass+'" id="code-validate" style="display:none;">'+validateMsg+'</span>';			
			new Insertion.After($('code_button'), validateHtml);
			new Effect.Appear($('code-validate'), {duration : 1 });
			
		}
	});
}

function showMsg(elmID){
	$(elmID).show();
	new Effect.Highlight(elmID, {startcolor:'#ffffff', endcolor:'#99ff99'});
}

/*
function updateSalesRecordDetail(saleid,categoryid, elmID){
	var updateBut = 'update_'+elmID;
	var cancelBut = 'cancel_'+elmID;
	var editBut = 'edit_'+elmID;
	var request = encodeURL('?method=edit&saleid='+saleid+'&categoryid='+categoryid+'&'+elmID+'='+$(elmID).value);
	new Ajax.Request('sales'+request, {	  
	  	method: 'post',	
	 	contentType:  'application/x-www-form-urlencoded',  
	    encoding:     'UTF-8', 
	  	onSuccess: function(transport) {	 
	  	$('success-msg').show(); 	     
	     new Effect.Highlight('success-msg', {startcolor:'#ffffff', endcolor:'#99ff99'});
	  }
	});
		$(elmID).disabled = 'disabled';
		$(updateBut).toggle();
		$(cancelBut).toggle();
		$(editBut).toggle();
}
*/


/*
function toggleUpdate(elmID,action){
	var updateBut = 'update_'+elmID;
	var cancelBut = 'cancel_'+elmID;
	var editBut = 'edit_'+elmID;
	if (action == 'edit'){
		$(elmID).disabled = '';		
		$(updateBut).toggle();
		$(cancelBut).toggle();
		$(editBut).toggle();
		$(elmID).focus()
		
	}
	if (action == 'cancel'){
		$(elmID).disabled = 'disabled';
		$(updateBut).toggle();
		$(cancelBut).toggle();
		$(editBut).toggle();
	}
}
*/

/* Multiple Company Names */
var rowCount = 0;
var rowHtml = '';
var rowElm = '';
var lastRowElm ='';

function addCompanyNameRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'name'+rowCount;		
	rowHtml = '<tr id="'+rowElm+'"><td colspan="2" style="font-size:80%;color:#555;">Entry '+rowCount+': <input type="text" name="customerData(name)" id="name_'+rowCount+'" style="width:85%;" value="" class="required" title="Please enter a company name" /></td></tr>';
	if (rowCount == 1){
		lastRowElm = 'name_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmCompanyNameButton();	
}

function rmCompanyNameRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'name'+rowCount;
	checkAddRmCompanyNameButton();
}

function checkAddRmCompanyNameButton(){
	if (rowCount > 9){
		//if row count is 9, disable the button
		$('add_more').hide();
		$('add_more_img').hide();
	}else{
		$('add_more').show();
		$('add_more_img').show();
	}	
	if (rowCount < 2){
		//if row count less than 2, disable the "remove" button
		$('remove').hide();
		$('remove_img').hide();
	}else{
		$('remove').show();
		$('remove_img').show();
	}
}

/* multiple Telephones */
var telrowCount = 0;
var telrowHtml = '';
var telrowElm = '';
var tellastRowElm ='';
function addTelRow(){	
	tellastRowElm = telrowElm;
	telrowCount++;
	telrowElm = 'tel'+telrowCount;		
	telrowHtml = '<tr id="'+telrowElm+'"><td colspan="2" style="font-size:80%;color:#555;">Entry '+telrowCount+': (<input type="text" name="customerData(tel_country)" style="width:20%;" />) <input type="text" name="customerData(tel_area)" style="width:20%;" /> - <input type="text" name="customerData(tel)" class="required" style="width:40%;" /></td></tr>';
	if (telrowCount == 1){
		tellastRowElm = 'tel_top';
	}	
	new Insertion.After(tellastRowElm, telrowHtml);	
	checkAddRmTelButton();	
}

function rmTelRow(){	
	$(telrowElm).remove();
	telrowCount--;
	telrowElm = 'tel'+telrowCount;
	checkAddRmTelButton();
}

function checkAddRmTelButton(){
	if (telrowCount > 9){
		//if row count is 9, disable the button
		$('teladd_more').hide();
		$('teladd_more_img').hide();
	}else{
		$('teladd_more').show();
		$('teladd_more_img').show();
	}	
	if (telrowCount < 2){
		//if row count less than 2, disable the "remove" button
		$('telremove').hide();
		$('telremove_img').hide();
	}else{
		$('telremove').show();
		$('telremove_img').show();
	}
}

/* multiple Fax */
var faxrowCount = 0;
var faxrowHtml = '';
var faxrowElm = '';
var faxlastRowElm ='';
function addFaxRow(){	
	faxlastRowElm = faxrowElm;
	faxrowCount++;
	faxrowElm = 'fax'+faxrowCount;		
	faxrowHtml = '<tr id="'+faxrowElm+'"><td colspan="2" style="font-size:80%;color:#555;">Entry '+faxrowCount+': (<input type="text" name="customerData(fax_country)" style="width:20%;" />) <input type="text" name="customerData(fax_area)" style="width:20%;" /> - <input type="text" class="required" name="customerData(fax)" style="width:40%;" /></td></tr>';
	if (faxrowCount == 1){
		faxlastRowElm = 'fax_top';
	}	
	new Insertion.After(faxlastRowElm, faxrowHtml);	
	checkAddRmFaxButton();	
}

function rmFaxRow(){	
	$(faxrowElm).remove();
	faxrowCount--;
	faxrowElm = 'fax'+faxrowCount;
	checkAddRmFaxButton();
}

function checkAddRmFaxButton(){
	if (faxrowCount > 9){
		//if row count is 9, disable the button
		$('faxadd_more').hide();
		$('faxadd_more_img').hide();
	}else{
		$('faxadd_more').show();
		$('faxadd_more_img').show();
	}	
	if (faxrowCount < 2){
		//if row count less than 2, disable the "remove" button
		$('faxremove').hide();
		$('faxremove_img').hide();
	}else{
		$('faxremove').show();
		$('faxremove_img').show();
	}
}

/* multiple product in create invoice */
var product_rowCount = 0;
var product_rowHtml = '';
var product_rowElm = '';
var product_lastRowElm ='';
var productArray = new Array();
var specialArray = new Array();

function productListPush(productid, productName, description, hkd, usd, show){
	newproduct = new Array(productid, productName, description, hkd, usd, show);
	productArray.push(newproduct);
}

function specialListPush(sid, sName, description){
	newSpecial = new Array(sid, sName, description);
	specialArray.push(newSpecial);
}

function addProductRow(){	
	product_lastRowElm = product_rowElm;
	product_rowCount++;
	product_rowElm = 'product_'+product_rowCount;		
	product_rowHtml = '<tr id="'+product_rowElm+'"><td style="font-size:80%;color:#555;"><select style="font-family: arial;" name="orderData(salesproductid)">';
	for (i=0; i<productArray.length; i++){
		currProd = productArray[i];
		/*
		// currProd
		//	[0] = productid
		//	[1] = productName
		//  [2] = description
		//	[3] = hkd
		//	[4] = usd
		//	[5] = show
		*/
		product_rowHtml += '<option style="width:300px;" value="'+currProd[0]+'">'+currProd[5]+' - '+currProd[1]+' - '+currProd[2]+' (HKD'+currProd[3]+'/USD'+currProd[4]+')</option>';
	}
	
	product_rowHtml += '</select></td><td><input type="text" name="orderData(quantity)" id="quantity_'+product_rowCount+'" class="required" style="width:100%;" title="Required" /></td><td style="padding-left:5px;font-size:80%;"><select style="font-family: arial;" name="orderData(specialchargeid)"><option value="-1" /> N/A</option>';
	for (i=0; i<specialArray.length; i++){
		currSpecial = specialArray[i];
		/*
		// curr special charge
		//	[0] = specialchargeid
		//	[1] =  name
		//	[2]	= description
		*/
		product_rowHtml += '<option value="'+currSpecial[0]+'" /> '+currSpecial[1]+' - '+currSpecial[2]+'</option>';
	}
	
	product_rowHtml += '</td><td><input type="text" size="10" name="orderData(description)" title="Required" class="required"/></td><td><input type="text" size="10" name="orderData(description_second)" title="Required" class="required" /></td><td><input type="text" size="10" name="orderData(description_third)" /></td><td>&nbsp;</td></tr>';
	if (product_rowCount == 1){
		product_lastRowElm = 'product_top';
	}	
	new Insertion.After(product_lastRowElm, product_rowHtml);	
	checkAddRmProductButton();	
}

function rmProductRow(){	
	$(product_rowElm).remove();
	product_rowCount--;
	product_rowElm = 'product_'+product_rowCount;
	checkAddRmProductButton();
}

function checkAddRmProductButton(){
	if (product_rowCount > 9){
		//if row count is 9, disable the button
		$('product_add_more').hide();
		$('product_add_more_img').hide();
	}else{
		$('product_add_more').show();
		$('product_add_more_img').show();
	}	
	if (product_rowCount < 1){
		//if row count less than 2, disable the "remove" button
		$('product_remove').hide();
		$('product_remove_img').hide();
	}else{
		$('product_remove').show();
		$('product_remove_img').show();
	}
}


/* Multiple customer detail rows */
var rowCount = 0;
function addCustomerDetailRow(keyword, required){	

	var require_class = '';
	if (required == 1){
		require_class = ' required';
	}
	var addRowId = keyword+'_add_more_img';
	rowCount++;	
	if (keyword == 'tel' || keyword == 'fax'){
		rowHtml = '<p style="padding-bottom: 3px;">(<input size="5" type="text" id="'+keyword+'" name="customerData('+keyword+'_country)" value="" />) - <input size="5" type="text" id="'+keyword+'" name="customerData('+keyword+'_area)" value="" /> - <input size="20" class="'+require_class+'" type="text" id="'+keyword+'" name="customerData('+keyword+')" value="" /></p>';
	}else {
		rowHtml = '<p style="padding-bottom: 3px;"><input class="customer_detail_text'+require_class+'" type="text" id="'+keyword+'_'+rowCount+'" name="customerData('+keyword+')" value="" /></p>';
	}
	new Insertion.Before(addRowId, rowHtml);	
	checkCustomerDetailRowButton(keyword);	
}

function checkCustomerDetailRowButton(keyword){
	var add_more = 'add_more';
	var add_more_img = keyword+'_add_more_img';	
	if (rowCount > 9){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}
}

/* Multiple customer detail rows TextArea */
var rowCount = 0;
function addCustomerDetailRowTextArea(keyword){	

	var addRowId = keyword+'_add_more_img';
	rowCount++;	
	rowHtml = '<p style="padding-bottom: 3px;"><textarea class="customer_detail_text" type="text" id="'+keyword+'_'+rowCount+'" name="customerData('+keyword+')" /></textarea></p>';

	new Insertion.Before(addRowId, rowHtml);	
	checkCustomerDetailRowButtonTextArea(keyword);	
}

function checkCustomerDetailRowButtonTextArea(keyword){
	var add_more = 'add_more';
	var add_more_img = keyword+'_add_more_img';	
	if (rowCount > 9){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}
}

/* Multiple payments row */
var p_rowCount = 0;
var paymentRowElm = '';
function addPaymentsRow(){	
	var defaultText = '';
	var addRowId = 'payments_add_more_img';
	p_rowCount++;	
	paymentRowElm = 'payment_'+p_rowCount;
	if(p_rowCount == 1){
		defaultText = 'Deposit due on presentation';
	}
	payment_option = '<option>Deposit due on presentation</option><option>1<sup>st</sup> Deposit payment </option><option>2<sup>nd</sup> Deposit payment </option><option>3<sup>rd</sup> Deposit payment </option><option>4<sup>th</sup> Deposit payment </option>';
	rowHtml = '<p id="'+paymentRowElm+'" style="padding-bottom:3px;font-size: 80%;color:#555;"><select style="width:200px;font-family:arial;" id="payments_name'+p_rowCount+'" name="paymentData(name)">'+payment_option+'</select> Date:<input size="10" class="" type="text" id="payments_date'+p_rowCount+'" name="paymentData(action_date)" readonly="readonly"/> Amount:<input size="10" type="text" id="payments_amount'+p_rowCount+'" name="paymentData(amount)" class="required validate-digits"/></p><script type="text/javascript">Calendar.setup({inputField: "payments_date'+p_rowCount+'",ifFormat: "%Y-%m-%d",button: "payments_date'+p_rowCount+'",singleClick:false,showsTime:true});</script>';
	new Insertion.Before(addRowId, rowHtml);	
	checkPaymentsRowButton();	
}

function checkPaymentsRowButton(){
	var add_more = 'payments_add_more';
	var add_more_img = 'payments_add_more_img';	
	var remove = 'payments_remove';
	var remove_img = 'payments_remove_img';	
	if (p_rowCount > 9){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}else{
		$(add_more).show();
		$(add_more_img).show();
	}	
	if (p_rowCount < 1){
		//if row count less than 2, disable the "remove" button
		$(remove).hide();
		$(remove_img).hide();
	}else{
		$(remove).show();
		$(remove_img).show();
	}
}

function rmPaymentsRow(){	
	paymentRowElm = 'payment_'+p_rowCount;
	$(paymentRowElm).remove();
	p_rowCount--;
	paymentRowElm = 'payment_'+p_rowCount;
	checkPaymentsRowButton();
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	windowWidth=600;
	myWidth = (document.documentElement.clientWidth - windowWidth)/2;
	myHeight = document.documentElement.clientHeight;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height="+myHeight+",left="+myWidth+",top=100 ');");
}

function checkDocType(){
	var docInputHTML ='';
	$('docInput').style.display = 'none';
	if ($('docType').value == 'cancel'){
		docInputHTML = '<p style="padding:5px;font-size:80%;">Letter Date:<input readonly="readonly" type="text" name="additionalData(letDate)" id="letDate"/><br /> Cancellation Request Date:<input readonly="readonly"  type="text" name="additionalData(reqDate)" id="reqDate"/><br /> Effective Date:<input  readonly="readonly" id="effDate" type="text" name="additionalData(effDate)"/><script type="text/javascript">Calendar.setup({inputField: "reqDate",ifFormat: "%B %d, %Y",button: "reqDate",singleClick:false});Calendar.setup({inputField: "effDate",ifFormat: "%B %d, %Y",button: "effDate",singleClick:false});Calendar.setup({inputField: "letDate",ifFormat: "%B %d, %Y",button: "letDate",singleClick:false});</script></p>';
	}
	if ($('docType').value == 'confirm'){
		docInputHTML = '<p style="padding:5px;font-size:80%;">Letter Date:<input readonly="readonly"  type="text" name="additionalData(letDate)" id="letDate"/> <script type="text/javascript">Calendar.setup({inputField: "letDate",ifFormat: "%B %d, %Y",button: "letDate",singleClick:false});</script></p>';;
	}
	$('docInput').update(docInputHTML);
	new Effect.Appear($('docInput'), {duration : 1 });
}

function calInvoiceDiscount(){
	$('discount_eval'). value = 0;
	var total = 0;
	var final = 0;
	for (i=0; i<price_size; i++){
		subtotalId = 'subtotal_'+i;
		total += Number($F(subtotalId));
	}
	if (isNaN(total)){
		$('total').update('<span style="color:#ff0000;font-size:10px;font-weight:bold;">Error.</span>');
		$('submit_button').disable();
	}else{
		$('total').update(total.toFixed(2));
		$('submit_button').enable();
	}
		
	var discount_rate = Number($F('discount_rate'));
	final = total * (discount_rate/100);	
	if (isNaN(final) || isNaN($F('discount_rate'))){
		$('discount_eval').value = 'ERROR';
		$('eval_msg').update('<span id="eval_msg_content" style="padding-left:10px;color:#ff0000;font-size:10px;font-weight:bold;">The product/discount amount entered in invalid. Please try again.</span>');
		$('submit_button').disable();
	}else {
		$('discount_eval').value = final.toFixed(2);
		$('eval_msg').update();
		$('submit_button').enable();
	}
	
}

function checkInvoiceDiscount(){
	if (isNaN($F('discount_eval'))){
		$('discount_eval').value = 'ERROR';
		$('eval_msg').update('<span id="eval_msg_content" style="padding-left:10px;color:#ff0000;font-size:10px;font-weight:bold;">The product/discount amount entered in invalid. Please try again.</span>');
		$('submit_button').disable();
	}else {
		$('eval_msg').update();
		$('submit_button').enable();
	}
}

function calInvoiceSubtotal(){
	var total = 0;
	for (i=0; i<price_size; i++){
		priceId = 'price_'+i;
		rateId = 'special_rate_'+i;
		total = Number($F(priceId)) + Number($F(priceId))*Number($F(rateId));
		subtotalId = 'subtotal_'+i;
		$(subtotalId).value = total.toFixed(2);
	}	
}

function calAfInvoiceDiscount(){
	$('discount_eval'). value = 0;
	var final = 0;
	var discount_rate = Number($F('discount_rate'));
	final = Number($F('amount')) * (discount_rate/100);
	$('discount_eval').value = final.toFixed(2);
}

/* Multiple country breakdown data row */
var cb_rowCount = 0;
var cbRowElm = '';
function addCbRow(reqName,refNo){	
	if (refNo == null) refNo = '';
	cb_rowCount++;	
	var cBlockElm = 'cb_'+cb_rowCount;
	var inputElm = 'refNo_'+cb_rowCount;
	var inputSugElm = 'refNoSug_'+cb_rowCount;	
	var addRowId = 'cb_add_more_img';
	
	rowHtml = '<p style="padding:5px;" id="'+cBlockElm+'">('+cb_rowCount+') <input class="required" type="text" size="50" id="'+inputElm+'" name="'+reqName+'" autocomplete="off" class="input" value="'+refNo+'" /><br /><div id="'+inputSugElm+'" class="autocomplete" style="display: none; position:relative;"></div></p>';
	new Insertion.Before(addRowId, rowHtml);	
	new Ajax.Autocompleter(inputElm, inputSugElm, 'email?method=getHints', {paramName: "refNo", minChars: 3} );
	checkCbRowButton();	
}

function checkCbRowButton(){
	var add_more = 'cb_add_more';
	var add_more_img = 'cb_add_more_img';	
	var remove = 'cb_remove';
	var remove_img = 'cb_remove_img';	
	if (cb_rowCount > 30){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}else{
		$(add_more).show();
		$(add_more_img).show();
	}	
	if (cb_rowCount < 1){
		//if row count less than 2, disable the "remove" button
		$(remove).hide();
		$(remove_img).hide();
	}else{
		$(remove).show();
		$(remove_img).show();
	}
}

function rmCbRow(){	
	cBlockElm = 'cb_'+cb_rowCount;
	$(cBlockElm).remove();
	cb_rowCount--;
	cbRowElm = 'cb_'+cb_rowCount;
	checkCbRowButton();
}

/**Country breakdown confirm page, generate js cal for each email ref**/
function cbGenCal(numRef){
	for (i=0;i<numRef;i++){
		dateFromElm = 'dateFrom_'+i;
		dateToElm = 'dateTo_'+i;
		fromTrigger = 'from_trigger_'+i;
		toTrigger = 'to_trigger_'+i;
		
		Calendar.setup(
		{
			inputField: dateFromElm,	//IDoftheinputfield
			ifFormat: "%Y-%m-%d",		//thedateformat
			button: fromTrigger,		//IDofthebutton
			singleClick:true
		}
		);
		Calendar.setup(
		{
			inputField: dateToElm,	//IDoftheinputfield
			ifFormat: "%Y-%m-%d",		//thedateformat
			button: toTrigger,		//IDofthebutton
			singleClick:true
		}
		);
	}
	
}

/* Advanced Search - Multiple keywords row */
var asKeyword_rowCount = 0;
var asKeywordRowElm = '';
function addAsKeywordRow(){	
	asKeyword_rowCount++;	
	var asKeywordBlockElm = 'asKeyword_'+asKeyword_rowCount;
	var addRowId = 'asKeyword_add_more_img';	
	rowHtml = '<p style="padding:5px;" id="'+asKeywordBlockElm+'">('+asKeyword_rowCount+') <input size="50" class="required" type="text" id="keyword_'+asKeyword_rowCount+'" name="keywords" value="" /></p>';
	new Insertion.Before(addRowId, rowHtml);		
	checkAsKeywordRowButton();	
}

function checkAsKeywordRowButton(){
	var add_more = 'asKeyword_add_more';
	var add_more_img = 'asKeyword_add_more_img';	
	var remove = 'asKeyword_remove';
	var remove_img = 'asKeyword_remove_img';	
	if (asKeyword_rowCount > 30){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}else{
		$(add_more).show();
		$(add_more_img).show();
	}	
	if (asKeyword_rowCount <= 1){
		//if row count less than 2, disable the "remove" button
		$(remove).hide();
		$(remove_img).hide();
	}else{
		$(remove).show();
		$(remove_img).show();
	}
}

function rmAsKeywordRow(){	
	asKeywordBlockElm = 'asKeyword_'+asKeyword_rowCount;
	$(asKeywordBlockElm).remove();
	asKeyword_rowCount--;
	asKeywordRowElm = 'asKeyword_'+asKeyword_rowCount;
	checkAsKeywordRowButton();
}


/* Advanced Search - Multiple Categories row */
var asCat_rowCount = 0;
var asCatRowElm = '';
var asCatListArray = new Array();

function asCatListPush(categoryid, categoryName){
	newCat = new Array(categoryid, categoryName);
	asCatListArray.push(newCat);
}


function addAsCatRow(){	
	asCat_rowCount++;	
	var asCatBlockElm = 'asCat_'+asCat_rowCount;
	var addRowId = 'asCat_add_more_img';
	catOptions = '';	
	for(i=0;i<asCatListArray.length;i++){
		currCat = asCatListArray[i];
		catOptions += '<option style="width:300px;" value="'+currCat[0]+'">'+currCat[1]+'</option>';
	}
	rowHtml = '<p style="padding:3px;" id="asCat_'+asCat_rowCount+'">('+asCat_rowCount+') <select name="categoryids" >'+catOptions+'</select></p>';
	new Insertion.Before(addRowId, rowHtml);		
	checkAsCatRowButton();	
}

function checkAsCatRowButton(){
	var add_more = 'asCat_add_more';
	var add_more_img = 'asCat_add_more_img';	
	var remove = 'asCat_remove';
	var remove_img = 'asCat_remove_img';	
	if (asCat_rowCount > 30){
		//if row count is 9, disable the button
		$(add_more).hide();
		$(add_more_img).hide();
	}else{
		$(add_more).show();
		$(add_more_img).show();
	}	
	if (asCat_rowCount < 1){
		//if row count less than 2, disable the "remove" button
		$(remove).hide();
		$(remove_img).hide();
	}else{
		$(remove).show();
		$(remove_img).show();
	}
}

function rmAsCatRow(){	
	asCatBlockElm = 'asCat_'+asCat_rowCount;
	$(asCatBlockElm).remove();
	asCat_rowCount--;
	asCatRowElm = 'asCat_'+asCat_rowCount;
	checkAsCatRowButton();
}

/** Advanced search: Check cat selection button **/
function checkCat(catElm){
	var flag = false;
	if(catElm == 'catNA'){
		if ($('catNA').checked == true){
			flag = true;
			$('catSelect').checked = false;
			$('catAll').checked = false;		
		}
	}	
	if(catElm == 'catAll'){
		if ($('catAll').checked == true){
			flag = true;
			$('catNA').checked = false;
			$('catSelect').checked = false;
		}
	}
	
	if (flag == true){
		clearCat();	
	}
}

function selectCat(){
	if ($('catSelect').checked == true){
		$('catAddElm').show();	
		$('catNA').checked = false;
		$('catAll').checked = false;
	}else{
		clearCat();	
	}
}

function clearCat(){
	$('catAddElm').hide();
	if (asCat_rowCount>=1){
		finalCount = asCat_rowCount;
		for (i=0;i<finalCount;i++){
			rmAsCatRow();
		}
	}
}
