var elmId = '';
var elmTxtId = '';
function checkNO(elmId, elmTxtId){
	if ($(elmId).checked == true){
			$(elmTxtId).disabled = false;
			$(elmTxtId).className = 'required';
			if (elmTxtId == "cbNO"){$('business_others').title = 'Please enter your business nature';}
			if (elmTxtId == "kf_search_txt"){$('kf_search_txt').title = 'Please enter your source';}
			if (elmTxtId == "kf_newspaper_txt"){$('kf_newspaper_txt').title = 'Please enter your source';}
			if (elmTxtId == "kf_others_txt"){$('kf_others_txt').title = 'Please enter your source';}
	}else{
			$(elmTxtId).disabled = true;
			$(elmTxtId).value = '';
			$(elmTxtId).className = null;		
			$(elmTxtId).title = '';
	}
}
		
var objPart = null;
var prodName = '_prod';
var delimiter = ',';
var show1CatArrayA = new Array();
var show1CatArrayB = new Array();
var show1CatArrayC = new Array();

var show2CatArrayA = new Array();
var show2CatArrayB = new Array();
var show2CatArrayC = new Array();

var show3CatArrayA = new Array();
var show3CatArrayB = new Array();
var show3CatArrayC = new Array();

var show4CatArrayA = new Array();
var show4CatArrayB = new Array();
var show4CatArrayC = new Array();

var businessArrayA = new Array();
var businessArrayB = new Array();
var businessArrayC = new Array();

var partElm = new Array();
var cbArray = new Array();
var divID = null;
var showNum = null;

function showPart(elmID, partElm, showNum) {
	if ($(elmID).checked == true){
		if (objPart) objPart.style.display = 'none';
		objPart=$(elmID+prodName);
		objPart.style.display = 'block';
		$(partElm).className = partElm+' validate-one-required-table';
		objPart = null;			
		partElm = null;
	}else{
		if (objPart) objPart.style.display = 'block';
		objPart=$(elmID+prodName);
		objPart.style.display = 'none';
		objPart = null;		
		$(partElm).className = partElm;
		divID = partElm+'_div';
		cbArray = $(divID).getElementsByClassName(partElm);	
		for (var i=0;i<cbArray.length;i++){
			cbArray[i].checked = false;
		}
		/*
		if (showNum == "1"){
			clearArray(show1CatArrayA);
			clearArray(show1CatArrayB);
			$('show1_others').value = "";
		}*/
		if (showNum == "2"){
			clearArray(show2CatArrayA);
			clearArray(show2CatArrayB);
			$('show2_others').value = "";
		}
		if (showNum == "3"){
			clearArray(show3CatArrayA);
			clearArray(show3CatArrayB);
			$('show3_others').value = "";
		}
		if (showNum == "4"){
			clearArray(show4CatArrayA);
			clearArray(show4CatArrayB);
			$('show4_others').value = "";
		}
		partElm = null;	
		divID=null;
	}
} 

function clearArray(clearArray){
	for (i=0; i<clearArray.length; i++){
		clearArray.pop();
	}
}


function getValue(inputCatArray){
	tempArray = new Array();
	for (i=0; i<inputCatArray.length; i++){
		exist = false;
		for (j=0; j<tempArray.length; j++){
			if (tempArray[j] == inputCatArray[i]){
				exist = true;
			}
		}
		if (!exist){
			tempArray.push(inputCatArray[i]);
		}
	}

	return tempArray.join(delimiter);

}

function appendOther(){
	/*
	$('show1CatA').value = '';	//small category
	$('show1CatB').value = '';	//category description
	$('show1CatC').value = '';	// large category
	*/
	
	$('show2CatA').value = '';
	$('show2CatB').value = '';
	$('show2CatC').value = '';
	
	$('show3CatA').value = '';
	$('show3CatB').value = '';
	$('show3CatC').value = '';
	
	$('show4CatA').value = '';
	$('show4CatB').value = '';
	$('show4CatC').value = '';
	
	$('businessCatA').value = '';
	$('businessCatB').value = '';
	$('businessCatC').value = '';
		
	var seperator = '';
	
	if (!$('business_others').value.blank()){
		seperator = (getValue(businessArrayA) != '') ? "," : "";
		$('businessCatA').value += getValue(businessArrayA)+seperator+'14';
		$('businessCatB').value += getValue(businessArrayB)+seperator+$('business_others').value;
		$('businessCatC').value += getValue(businessArrayC)+$('business_others').value;
	}else {
		$('businessCatA').value += getValue(businessArrayA);
		$('businessCatB').value += getValue(businessArrayB);
		$('businessCatC').value += getValue(businessArrayC);
	}
	/*		
	if (!$('show1_others').value.blank()){
		seperator = (getValue(show1CatArrayA) != '') ? "," : "";
		$('show1CatA').value += getValue(show1CatArrayA)+seperator+$('show1_others').value;
		$('show1CatB').value += getValue(show1CatArrayB)+seperator+$('show1_others').value;
	}else {
		$('show1CatA').value += getValue(show1CatArrayA);
		$('show1CatB').value += getValue(show1CatArrayB);
	}
	*/
	if (!$('show2_others').value.blank()){
		seperator = (getValue(show2CatArrayA) != '') ? "," : "";
		$('show2CatA').value += getValue(show2CatArrayA)+seperator+$('show2_others').value;
		$('show2CatB').value += getValue(show2CatArrayB)+seperator+$('show2_others').value;
	}else {
		$('show2CatA').value += getValue(show2CatArrayA);
		$('show2CatB').value += getValue(show2CatArrayB);
	}
	
	if (!$('show3_others').value.blank()){
		seperator = (getValue(show3CatArrayA) != '') ? "," : "";
		$('show3CatA').value += getValue(show3CatArrayA)+seperator+$('show3_others').value;
		$('show3CatB').value += getValue(show3CatArrayB)+seperator+$('show3_others').value;
	}else {
		$('show3CatA').value += getValue(show3CatArrayA);
		$('show3CatB').value += getValue(show3CatArrayB);
	}
	
	if (!$('show4_others').value.blank()){
		seperator = (getValue(show4CatArrayA) != '') ? "," : "";
		$('show4CatA').value += getValue(show4CatArrayA);
		$('show4CatB').value += getValue(show4CatArrayB)+seperator+$('show4_others').value;
		$('show4CatC').value += getValue(show4CatArrayC)+seperator+$('show4_others').value;
	}else {
		$('show4CatA').value += getValue(show4CatArrayA);
		$('show4CatB').value += getValue(show4CatArrayB);		
		$('show4CatC').value += getValue(show4CatArrayC);
	}
	
	/*$('show1CatC').value += getValue(show1CatArrayC);*/
	$('show2CatC').value += getValue(show2CatArrayC);
	$('show3CatC').value += getValue(show3CatArrayC);
	

}

function checkItem(currentElement, arrayInput, arrayOutput){
	if (currentElement.checked){
		for (i=0; i<arrayInput.length; i++){
			arrayOutput.push(arrayInput[i]);
		}

	}else {
		for (i=0; i<arrayInput.length; i++){
			for (j=0; j<arrayOutput.length; j++){
				if (arrayOutput[j] == arrayInput[i]){
					var temp = arrayOutput[0];
					arrayOutput[0] = arrayOutput[j];
					arrayOutput[j] = temp;
					arrayOutput.shift();
					break;
				}
			}
		}
	}
}

var rowCount = 0;
var rowHtml = '';
var rowElm = '';
var lastRowElm ='';


// Invite friend
function addInviteRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'invite'+rowCount;	
	
	rowHtml = '<tr id="'+rowElm+'"><td><div class="form-row"><div class="field-label"><label for="recipientName'+rowCount+'"><span class="asterisk">*</span> Recipient '+rowCount+' Name</label></div><div class="field-widget"><input type="text" name="recipientName" size="25" value="" id="recipientName'+rowCount+'" class="required" title="Please enter the recipient name" /></div></div></td><td><div class="form-row"><div class="field-label"><label for="recipientEmail'+rowCount+'"><span class="asterisk">*</span> Recipient '+rowCount+' Email</label></div><div class="field-widget"><input type="text" name="recipientEmail" size="25" value="" id="recipientEmail'+rowCount+'" class="required validate-email" title="Please enter a valid email" /></div></div></td></tr>';
	
	if (rowCount == 1){
		lastRowElm = 'invite_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmButton();

}

function rmInviteRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'invite'+rowCount;
	checkAddRmButton();
}

function checkAddRmButton(){
	if (rowCount > 9){
		//if row count is 10, disable the "invite more" 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();
	}
}

function rld() {
	document.location.reload()
}


// Invite Buyer
function addInviteBuyerRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'invite'+rowCount;	
	
	rowHtml = '<tr id="'+rowElm+'"><td valign="top"></td><td valign="top"><span class="asterisk">*</span>(Buyer\'s Name)<input type="text" name="recipientName" size="25" value="" id="recipientName'+rowCount+'" class="required" title="Please enter buyer\'s name"/><!-- replace:recipientName --></td><td valign="top">&nbsp;<span class="asterisk">*</span>(Buyer\'s Email)<input type="text" name="recipientEmail" size="25" value="" id="recipientEmail'+rowCount+'" class="required validate-email" title="Please enter buyer\'s email"/></td></tr>'
	if (rowCount == 1){
		lastRowElm = 'invite_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmBuyerButton();
	
}

function rmInviteBuyerRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'invite'+rowCount;
	checkAddRmBuyerButton();
}

function checkAddRmBuyerButton(){
	if (rowCount > 8){
		//if row count is 9, disable the "invite more" button
		$('add_more').hide();
		$('add_more_img').hide();
	}else{
		$('add_more').show();
		$('add_more_img').show();
	}
	
	if (rowCount < 1){
		//if row count less than 2, disable the "remove" button
		$('remove').hide();
		$('remove_img').hide();
	}else{
		$('remove').show();
		$('remove_img').show();
	}
}

// Add registration buyer
function addBuyerRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'buyer'+rowCount;	
	
	rowHtml = '<tr id="'+rowElm+'"><td colspan="2"><table cellpadding="2" cellspacing="0" style="border: 1px solid #ddd;"><td><tr><td colspan="2" style="padding-left: 5px; background-color:#eee;"><strong>Buyer '+rowCount+' Detail:</strong></td></tr><tr><td colspan="2"><div class="form-row"><div class="field-label"><label for="title'+rowCount+'"><span class="asterisk">*</span> Title '+rowCount+'</label>: <span class="form_sub_title_2">(Please select a title)</span></div><select name="formData(title)" class="required" title="Please select a title"><option></option><option value="Dr.">Dr.</option><option value="Mr.">Mr.</option><option value="Mrs.">Mrs.</option><option value="Ms.">Ms.</option></select></div></td></tr><tr><td><div class="form-row"><div class="field-label"><label for="firstname_1"><span class="asterisk">*</span> First Name '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(firstname_1)" style="width:250px;" value="" class="required" title="Please enter Buyer '+rowCount+' First Name" /></div></div></td><td><div class="form-row"><div class="field-label"><label for="lastname_1"><span class="asterisk">*</span> Last Name '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(lastname_1)" style="width:250px;" value="" class="required" title="Please enter Buyer '+rowCount+' Last Name" /></div></div></td></tr><tr><td colspan="2"><div class="form-row"><div class="field-label"><label for="position_1"><span class="asterisk">*</span> Position '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(position_1)" style="width:350px;" value="" class="required" title="Please enter Buyer '+rowCount+' position" /></div></div></td></tr><tr><td colspan="2"><div class="form-row"><div class="field-label"><label for="email"><span class="asterisk">*</span> Email '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(email)" style="width:350px;" value="" class="required validate-email" title="Please enter a valid email address" /></div></div></td></tr><tr><td colspan="2"><br /></td></tr></table></td></tr>';
	if (rowCount == 1){
		lastRowElm = 'buyer_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmRBuyerButton();
	
}

function rmBuyerRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'buyer'+rowCount;
	checkAddRmRBuyerButton();
}

function checkAddRmRBuyerButton(){
	if (rowCount > 9){
		//if row count is 9, disable the "invite more" 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();
	}
}

function clearForms()
{
  var i;
  for (i = 0; (i < document.forms.length); i++) {
    document.forms[i].reset();
  }
}

// Add shuttle reservation buyer
function addBusBuyerRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'buyer'+rowCount;	
	
	rowHtml = '<tr id="'+rowElm+'"><td colspan="2"><table cellpadding="2" cellspacing="0" style="border: 1px solid #ddd;"><td><tr><td colspan="2" style="padding-left: 5px; background-color:#eee;"><strong>Buyer '+rowCount+' Detail:</strong></td></tr><tr><td colspan="2"><div class="form-row"><div class="field-label"><label for="title'+rowCount+'"><span class="asterisk">*</span> Title '+rowCount+'</label>: <span class="form_sub_title_2">(Please select a title)</span></div><select name="formData(title)" class="required" title="Please select a title"><option></option><option value="Dr.">Dr.</option><option value="Miss">Miss</option><option value="Mr.">Mr.</option><option value="Mrs.">Mrs.</option><option value="Ms.">Ms.</option></select></div></td></tr><tr><td><div class="form-row"><div class="field-label"><label for="firstname_1"><span class="asterisk">*</span> First Name '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(firstname_1)" style="width:335px;" value="" class="required" title="Please enter Buyer '+rowCount+' First Name" /></div></div></td><td><div class="form-row"><div class="field-label"><label for="lastname_1"><span class="asterisk">*</span> Last Name '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(lastname_1)" style="width:335px;" value="" class="required" title="Please enter Buyer '+rowCount+' Last Name" /></div></div></td></tr><tr><td colspan="2"><div class="form-row"><div class="field-label"><label for="email"><span class="asterisk">*</span> Email '+rowCount+'</label>:</div><div class="field-widget"><input type="text" name="formData(email)" style="width:700px;" value="" class="required validate-email" title="Please enter a valid email address" /></div></div></td></tr><tr><td colspan="2"><br /></td></tr></table></td></tr>';
	if (rowCount == 1){
		lastRowElm = 'buyer_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmBusRBuyerButton();
	
}

function rmBusBuyerRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'buyer'+rowCount;
	checkAddRmBusRBuyerButton();
}

function checkAddRmBusRBuyerButton(){
	if (rowCount > 4){
		//if row count is 9, disable the "invite more" 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();
	}
}


// Shuttle Bus Time set

function setOptions(opt,chosen) {
	var bus_date = '';
	var selbox ='';
	if (opt == '1'){
		selbox = document.dataForm.ctomopttwo;	
	}else{
		selbox = document.dataForm.mtocopttwo;	
	}
	selbox.options.length = 0;
	
	if (chosen == "") {
	  selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' '); 
	}
	
	if (chosen == "0") {
		bus_date = 'N/A';
		selbox.options[selbox.options.length] = new Option('N/A','N/A');
	}
	if (chosen == "1") {
		bus_date = '17 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('08:00','08:00');
	  	selbox.options[selbox.options.length] = new Option('08:40','08:40');
	  	selbox.options[selbox.options.length] = new Option('09:35','09:35');
	  	selbox.options[selbox.options.length] = new Option('10:35','10:35');
	  	selbox.options[selbox.options.length] = new Option('11:35','11:35');
	  	selbox.options[selbox.options.length] = new Option('13:35','13:35');
	  	selbox.options[selbox.options.length] = new Option('14:35','14:35');
	  	selbox.options[selbox.options.length] = new Option('15:35','15:35');
	  	selbox.options[selbox.options.length] = new Option('16:35','16:35');
	  	selbox.options[selbox.options.length] = new Option('17:35','17:35');
	  	selbox.options[selbox.options.length] = new Option('18:35','18:35');
	  	selbox.options[selbox.options.length] = new Option('19:05','19:05');
	}
	if (chosen == "2") {
		bus_date = '18 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('08:00','08:00');
	  	selbox.options[selbox.options.length] = new Option('08:40','08:40');
	  	selbox.options[selbox.options.length] = new Option('09:35','09:35');
	  	selbox.options[selbox.options.length] = new Option('10:35','10:35');
	  	selbox.options[selbox.options.length] = new Option('11:35','11:35');
	  	selbox.options[selbox.options.length] = new Option('13:35','13:35');
	  	selbox.options[selbox.options.length] = new Option('14:35','14:35');
	  	selbox.options[selbox.options.length] = new Option('15:35','15:35');
	  	selbox.options[selbox.options.length] = new Option('16:35','16:35');
	  	selbox.options[selbox.options.length] = new Option('17:35','17:35');
	  	selbox.options[selbox.options.length] = new Option('18:35','18:35');
	  	selbox.options[selbox.options.length] = new Option('19:05','19:05');		
	}
	if (chosen == "3") {
		bus_date = '19 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('08:00','08:00');
	  	selbox.options[selbox.options.length] = new Option('08:40','08:40');
	  	selbox.options[selbox.options.length] = new Option('09:35','09:35');
	  	selbox.options[selbox.options.length] = new Option('10:35','10:35');
	  	selbox.options[selbox.options.length] = new Option('11:35','11:35');
	  	selbox.options[selbox.options.length] = new Option('13:35','13:35');
	  	selbox.options[selbox.options.length] = new Option('14:35','14:35');
	  	selbox.options[selbox.options.length] = new Option('15:35','15:35');	
	}
	if (chosen == "4") {
		bus_date = '20 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('08:00','08:00');
	  	selbox.options[selbox.options.length] = new Option('08:40','08:40');
	  	selbox.options[selbox.options.length] = new Option('09:35','09:35');	
	}
	if (chosen == "5") {
		bus_date = '18 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('16:00','16:00');
	  	selbox.options[selbox.options.length] = new Option('17:00','17:00');
	  	selbox.options[selbox.options.length] = new Option('18:00','18:00');	
	}
	if (chosen == "6") {
		bus_date = '19 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('16:00','16:00');
	  	selbox.options[selbox.options.length] = new Option('17:00','17:00');
	  	selbox.options[selbox.options.length] = new Option('18:00','18:00');	
	}
	if (chosen == "7") {
		bus_date = '20 October';
		selbox.className = 'required';
		selbox.options[selbox.options.length] = new Option('Please select a time','');
	  	selbox.options[selbox.options.length] = new Option('16:00','16:00');
	  	selbox.options[selbox.options.length] = new Option('17:00','17:00');
	  	selbox.options[selbox.options.length] = new Option('18:00','18:00');	
	}
	
	if (opt == '1'){
		$('date_ctom').value = bus_date;
	}
	if (opt == '2'){
		$('date_mtoc').value = bus_date;
	}
	bus_date = '';
}

var checked=0;

function checkEcardPass(){		
		var hashcode = '5069c0b464ec157966315b41f9ab4538';
		hash = hex_md5($F('passcode'));
		if(checked == 1){
			if (hashcode == hash){						
				$('submit_button').enable();
				$('submit_button').value = 'SEND';
				$('pass_msg').update('<span style="text-decoration:underline;font-size:10px;color:#009900;font-weight:bold;">Passcode Valid</span>');
				$('passed').value ='1';
			}else{					
				$('submit_button').disable();
				$('submit_button').value = 'Sorry! Your passcode is invalid.';
				$('pass_msg').update('<span style="text-decoration:underline;font-size:10px;color:#ff0000;font-weight:bold;">Passcode Invalid!</span>');
			}
		}
		checked=1;
}

// Add e-invitation buyer
function addInviteBuyerRow(){	
	lastRowElm = rowElm;
	rowCount++;
	rowElm = 'buyer'+rowCount;	
	
	rowHtml = '<tr id="'+rowElm+'"><td colspan="2"><table cellpadding="2" cellspacing="0" style="width:100%;border: 1px solid #ddd;"><td><tr><td colspan="2" style="padding-left: 5px; background-color:#eee;"><strong>Buyer '+rowCount+' Detail:</strong></td></tr><tr><td><div class="field-label"><label for="buyer_name"><span class="asterisk">*</span> Buyer Name '+rowCount+'</label>:</div><div><input type="text" name="formData(buyer_name)" style="width:180px;" value="" class="required" title="Please enter Buyer '+rowCount+' First Name" /></div></td><td><div class="field-label"><label for="email"><span class="asterisk">*</span> Buyer Email '+rowCount+'</label>:</div><div><input type="text" name="formData(email)" style="width:180px;" value="" class="required" title="Please enter Buyer '+rowCount+' Email" /></div></td></tr><tr><td colspan="2"><br /></td></tr></table></td></tr>';
	if (rowCount == 1){
		lastRowElm = 'buyer_top';
	}	
	new Insertion.After(lastRowElm, rowHtml);	
	checkAddRmInviteBuyerButton();
	
}

function rmInviteBuyerRow(){	
	$(rowElm).remove();
	rowCount--;
	rowElm = 'buyer'+rowCount;
	checkAddRmInviteBuyerButton();
}

function checkAddRmInviteBuyerButton(){
	if (rowCount > 9){
		//if row count is 9, disable the "invite more" 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();
	}
}