// JavaScript Document
function setCategoryParameter(value){
  postDataGetXml('../modules/pcb/scripts/ajax_getCategoryParameterForm.php','value='+value, viewCategoryParameterForm);
}
function viewCategoryParameterForm(value){
	htmlText = value.getElementsByTagName("htmlText");
	var num;
	var idSelect = document.getElementById('ajax_category_parameters');
	//alert("is called");
	var html = "";
	for (num = 0; num < htmlText.length; num++) {
			idSelect.innerHTML = htmlText[num].firstChild.data;
			
	}
	
}
function addOtherFile(idTable, text1, text2){
    fileIndex++;
	document.getElementById("numOfFiles").value = (fileIndex+1);
	var table = document.getElementById(idTable);
	//var tbody = document.getElementById(idTable).getElementsByTagName('tbody');
	//var tr1 = document.createElement('tr');
	//var tr2 = document.createElement('tr');
	var tr1 = document.getElementById(idTable).insertRow(-1); 
	var tr2 = document.getElementById(idTable).insertRow(-1); 
	var td1_1 = document.createElement('td');
	var td1_2 = document.createElement('td');
	var td2_1 = document.createElement('td');
	var td2_2 = document.createElement('td');
    
	
	//var iRowCount = oRows.length;

	//alert('Your table has ' + iRowCount + ' rows.');

	
	var inputText = document.createElement('input');
	inputText.setAttribute("type", "text");
	inputText.setAttribute("name", "filename[]");
	inputText.setAttribute("style", "width: 250px");
	inputText.style.width = "250px";
	
	var inputFile = document.createElement('input');
	inputFile.setAttribute("type", "file");
	inputFile.setAttribute("name", "file_"+fileIndex);
	inputFile.setAttribute("size", "45");
	inputFile.style.width = "220px";
	
	var textContent1 = document.createTextNode(text1);
	var textContent2 = document.createTextNode(text2);
	
	td1_1.appendChild(textContent1);
	td1_2.appendChild(inputText);
	
	td2_1.appendChild(textContent2);
	td2_2.appendChild(inputFile);
	
	tr1.appendChild(td1_1);
	tr1.appendChild(td1_2);
	tr2.appendChild(td2_1);
	tr2.appendChild(td2_2);

	//table.appendChild(tr1);
	//table.appendChild(tr2);
	
	
}

function getCheckedValue(name){
	var retString = false;
	var retValue;
	var retArray = new Array();
	if(document.forms['reguest'][name].type==undefined){
		for(var i=0; i<document.forms['reguest'][name].length; i++){
	   		if (document.forms['reguest'][name][i].checked){
				if(document.forms['reguest'][name][i].type=='radio'){
					retString = true;
					retValue = document.forms['reguest'][name][i].value;
				}else{
					retString = false;
					//alert(retArray);
					retArray[i] = document.forms['reguest'][name][i].value;
				}
			}
	   }
    }else{
		retString = true;
		retValue = document.forms['reguest'][name].value;
	}

	if(retString == true){
//		alert("A "+name);
		return retValue;
	}else{
 	//	alert("B "+retArray);
	    return retArray;
	}
}

function getTotalFind(){
   events = getCheckedValue('event');
   locations = getCheckedValue('location');
   participants = getCheckedValue('participants');
   rooms = getCheckedValue('rooms');
   var params = new Array();
   var k = 0;
   var paramString = '';
   for(var i=document.forms['reguest']['paramMin'].value; i<=document.forms['reguest']['paramMax'].value; i++){
   		if(document.forms['reguest']['params['+i+']']!=null){
			paramString += '&params['+i+']='+getCheckedValue('params['+i+']');
		}
   }
   
   //alert('event='+events+'&location='+locations+'&participants='+participants+'&rooms='+rooms+''+paramString);
   postDataGetXml('modules/pcb/scripts/ajax_getTotalFindForm.php','event='+events+'&location='+locations+'&participants='+participants+'&rooms='+rooms+''+paramString, viewTotalSubmit);
}

function getTotalFindStep1(){
   
   participants = getCheckedValue('expected_attendees');
   
   
   var category = new Array();
   var k = 0;
   var categoryString = '';
   for(var i=0; i<9; i++){
   		//alert(document.forms['reguest']['category['+i+']'].checked);
		if(document.forms['reguest']['category['+i+']']!=null){
			if(document.forms['reguest']['category['+i+']'].checked){
			   categoryString += '&categories['+k+']='+getCheckedValue('category['+i+']');
			   k++;
			}
		}
   }
   
  // alert('&participants='+participants+''+categoryString);
  // alert('modules/pcb/scripts/ajax_getTotalFindFormStep1.php?participants='+participants+''+categoryString);
   postDataGetXml('modules/pcb/scripts/ajax_getTotalFindFormStep1.php','participants='+participants+''+categoryString, viewTotalSubmit);
}
function viewTotalSubmit(value){
	var requestForm;
	requestForm = value.getElementsByTagName("total");
    //alert(value);
	var num;
	var total = 0;
	var submitButton = document.getElementById('sendButton2');
	var nextButton = document.getElementById('nextButton');
	//alert("is called");
	var html = "";
	for (num = 0; num < requestForm.length; num++) {
			total = requestForm[num].firstChild.data;
			
	}
	//alert(total);
	if(total>0){
		nextButton.className = 'sendButton';
		nextButton.disabled = false;
	}else{
		nextButton.className = 'submitDisabled';
		nextButton.disabled = true;
	}
	//alert(total);
	//submitButton.value = 'Continue ('+total+')';
	//alert()
	submitButton.innerHTML = total;
}
function getAdvanceSearch(){
   var params = new Array();
   var k = 0;
   
   var table = document.getElementById('resultsTable');
   var numOfRows = (table.rows.length-1);
    for(var i=0; i<numOfRows; i++){
	   table.deleteRow(table.rows.length-1);
	}
	var row = table.insertRow(table.rows.length);
	var cell0= row.insertCell(0);
	cell0.setAttribute('colSpan', '4');
	cell0.setAttribute('align', 'center');
	cell0.innerHTML = "<span class=\"nameList\">Searching...</span><br>";
	var oImg=document.createElement("img");
    oImg.setAttribute('src', 'images/design/ajax-loader.gif');
	oImg.setAttribute('alt', 'Loading');
	cell0.appendChild(oImg);
	
   var paramString = '';
   for(var i=document.forms['reguest']['paramMin'].value; i<=document.forms['reguest']['paramMax'].value; i++){
   		if(document.forms['reguest']['params['+i+']']!=null){
			paramString += '&params['+i+']='+getCheckedValue('params['+i+']');
		}
   }
   
  // alert('event='+events+'&location='+locations+'&participants='+participants+'&rooms='+rooms+''+paramString);
   postDataGetXml('modules/pcb/scripts/ajax_getAdvanceSearch.php', paramString, viewAdvanceSearch);
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

function viewAdvanceSearch(value){
    
	var table = document.getElementById('resultsTable');
//	alert('Test' + 	table.rows.length);
    var numOfRows = (table.rows.length-1);
    for(var i=0; i<numOfRows; i++){
	   table.deleteRow(table.rows.length-1);
	}
	    
	member = value.getElementsByTagName("member");
   	id = value.getElementsByTagName("id");
	stars = value.getElementsByTagName("stars");
	name = value.getElementsByTagName("name");
	category = value.getElementsByTagName("category");
	detail = value.getElementsByTagName("detail");
	var num;
	//alert(member.length + ' ' + member.childNodes.length)
	if(id.length==0){
		var row = table.insertRow(table.rows.length);
		var cell0= row.insertCell(0);
		cell0.setAttribute('colSpan', '4');
		cell0.setAttribute('align', 'center');
		cell0.innerHTML = "<span class=\"nameList\">Sorry, no members for your parameters.</span>";
	}
    for (num = 0; num < id.length; num++) {
			//alert(member[num].firstChild.data);
		var row = table.insertRow(table.rows.length);

		if((num%2)==1){
			//row.className = "odd";
			table.rows[(table.rows.length-1)].className="odd";
		}
		
		var cell0= row.insertCell(0);
		var cell1= row.insertCell(1);
		var chkbox = document.createElement('input');   
		chkbox.type = "checkbox";
		chkbox.name = "members[]";
		chkbox.value = id[num].firstChild.data;
		chkbox.setAttribute('checked', 'checked');
		cell0.appendChild(chkbox);
		cell1.innerHTML = "<span class=\"nameList\">"+name[num].firstChild.data+"</span>";
		if(stars[num].firstChild.data == 6){
			var oImg=document.createTextNode("Business Hotel");
		}else{
		for(var k=0; k<stars[num].firstChild.data; k++){
			var oImg=document.createElement("img");
		    oImg.setAttribute('src', 'images/design/ic-star.gif');
			oImg.setAttribute('alt', 'Stars');
			oImg.setAttribute('height', '10px');
			oImg.setAttribute('width', '11px');
			
		}
		}
		cell1.appendChild(oImg);
		var cell2= row.insertCell(2);
		cell2.setAttribute("align", "center");
        cell2.innerHTML = category[num].firstChild.data;
		var cell3= row.insertCell(3);
		cell3.setAttribute("align", "center");
        cell3.innerHTML = "<a href=\""+detail[num].firstChild.data+"\">view</a>";	
	}
}
function getParamToForm(form){
	var reguestString = document.forms['reguest'];
	for(var i=document.forms['reguest']['paramMin'].value; i<=document.forms['reguest']['paramMax'].value; i++){
   		if(document.forms['reguest']['params['+i+']']!=null){
			// paramString += '&params['+i+']='+getCheckedValue('params['+i+']');
			var hidden = document.createElement('input');   
			hidden.type = "hidden";
			hidden.name = "paramGenerate["+i+"]";
			hidden.value = getCheckedValue('params['+i+']');
			reguestString.appendChild(hidden);
		}
	 }
}

function isEmail(mail) {
    re = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,7}$/;
    return mail.search(re) == 0;
}

	function confirmSubmitQuickSend(text)
		{
		var agree=confirm(text);
		if (agree){
			window.location.href = '?page=39';
			return true ;
		}else{
			return false ;
		}
	}
	
	// Confirm submit form
	function confirmSubmit(text)
	{
	var agree=confirm(text);
	if (agree)
		return true ;
	else
		return false ;
	}
	// zakazani ENTER na formulari
	function stopRKey(evt) {
		
		  var evt = (evt) ? evt : ((event) ? event : null);
		  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
		}
	
	document.onkeypress = stopRKey; 

function  validateRequestForm(form){
	
	//if(confirmSubmit("Are you sure you wish send the Request Proposal?")){
	
		/*form.name.style.background = '#ffffff';
		form.name.style.border = '1px solid #a0a0a0';
		form.company.style.background = '#ffffff';
		form.company.style.border = '1px solid #a0a0a0';
		form.email.style.background = '#ffffff';
		form.email.style.border = '1px solid #a0a0a0';
		form.email.style.background = '#ffffff';
		form.email.style.border = '1px solid #a0a0a0';*/
		
		/*var reguestString = document.forms['reguest'];
		for(var i=document.forms['reguest']['paramMin'].value; i<=document.forms['reguest']['paramMax'].value; i++){
	   		if(document.forms['reguest']['params['+i+']']!=null){
				// paramString += '&params['+i+']='+getCheckedValue('params['+i+']');
				var hidden = document.createElement('input');   
				hidden.type = "hidden";
				hidden.name = "paramGenerate["+i+"]";
				hidden.value = getCheckedValue('params['+i+']');
				reguestString.appendChild(hidden);
			}
		 }*/
		 //alert(paramString);
		//alert(form.code_cpt.value.length + " A")
		var actualFormLang = form.actlang.value;
		var organizationAlert = new Array();
		organizationAlert[1] = 'Please, fill in your Organization.';
		organizationAlert[2] = 'Prosím, vyplňte pole Organizace.';
		
		var captchaAlert = new Array();
		captchaAlert[1] = 'Please, fill in code from image.';
		captchaAlert[2] = 'Prosím, opište kód z obrázku.';
		
		var first_nameAlert = new Array();
		first_nameAlert[1] = 'Please, fill in your First name.';
		first_nameAlert[2] = 'Prosím, vyplňte jméno.';
		
		var last_nameAlert = new Array();
		last_nameAlert[1] = 'Please, fill in your Last name.';
		last_nameAlert[2] = 'Prosím, vyplňte příjmení.';
		
		var cityAlert = new Array();
		cityAlert[1] = 'Please, fill in your City.';
		cityAlert[2] = 'Prosím, vyplňte město.';
		
		var countryAlert = new Array();
		countryAlert[1] = 'Please, fill in your Country.';
		countryAlert[2] = 'Prosím, vyplňte stát.';
		
		var telephoneAlert = new Array();
		telephoneAlert[1] = 'Please, fill in your Telephone.';
		telephoneAlert[2] = 'Prosím, vyplňte telefon.';
		
		var countrytelephoneAlert = new Array();
		countrytelephoneAlert[1] = 'Please, fill in your Telephone.';
		countrytelephoneAlert[2] = 'Prosím, vyplňte telefon.';
		
		var emailAlert = new Array();
		emailAlert[1] = 'Please, fill in your E-mail.';
		emailAlert[2] = 'Prosím, vyplňte Váš e-mail.';
		
		var validateemailAlert = new Array();
		validateemailAlert[1] = 'Please, fill validate E-mail.';
		validateemailAlert[2] = 'Prosím, vyplňte e-mail ve správné podobě.';
		
		var meeting_nameAlert = new Array();
		meeting_nameAlert[1] = 'Please, fill in your Meeting name.';
		meeting_nameAlert[2] = 'Prosím, vyplňte název akce.';
		
		var expected_attendeesAlert = new Array();
		expected_attendeesAlert[1] = 'Please, fill in your Expected Attendees.';
		expected_attendeesAlert[2] = 'Prosím, vyplňte předpokládaný počet účastníků.';
		
		var preferred_datesAlert = new Array();
		preferred_datesAlert[1] = 'Please, fill in your Preferred Dates.';
		preferred_datesAlert[2] = 'Prosím, vyplňte preferovaný datum.';
		
		var preferred_datesAlert = new Array();
		preferred_datesAlert[1] = 'Please, fill in your Preferred Dates.';
		preferred_datesAlert[2] = 'Prosím, vyplňte preferovaný datum.';
		
	  if(form.organization.value == ""){
			alert(organizationAlert[actualFormLang]);
			form.organization.focus();
			return false;
		}else if(form.code_cpt.value.length == 0){
			alert(captchaAlert[actualFormLang]);
			form.code_cpt.focus();
			return false;
		}else if(form.first_name.value == ""){
			alert(first_nameAlert[actualFormLang]);
			form.first_name.focus();
			return false;
		}else if(form.last_name.value == ""){
			alert(last_nameAlert[actualFormLang]);
			form.last_name.focus();
			return false;
		
		}else if(form.city.value == ""){
			alert(cityAlert[actualFormLang]);
			form.city.focus();
			return false;
		
		}else if(form.country.value == "0"){
			alert(countryAlert[actualFormLang]);
			form.country.focus();
			return false;
		}else if(form.telephone.value == ""){
			alert(telephoneAlert[actualFormLang]);
			form.telephone.focus();
			return false;
		}else if(form.countrytelephone.value == ""){
			alert(countrytelephoneAlert[actualFormLang]);
			form.countrytelephone.focus();
			return false;
			
		}else if(form.email.value == ""){
			alert(emailAlert[actualFormLang]);
			form.email.focus();
			return false;
		}else if(!isEmail(form.email.value)){
			alert(validateemailAlert[actualFormLang]);
			form.email.focus();
			return false;
		
		}else if(form.meeting_name.value == ""){
			alert(meeting_nameAlert[actualFormLang]);
			form.meeting_name.focus();
			return false;
		
		}else if(form.expected_attendees.value == ""){
			alert(expected_attendeesAlert[actualFormLang]);
			form.expected_attendees.focus();
			return false;
		
		}else if(form.preferred_dates.value == ""){
			alert(preferred_datesAlert[actualFormLang]);
			form.preferred_dates.focus();
			return false;
		}else if(form.code_cpt.value.length == 0){
			alert(captchaAlert[actualFormLang]);
			form.code_cpt.focus();
			return false;
		}else{
		   
		   return true;
		}
	//}else{
	//	
	//	return false ;
	//}
}
function addRoomsRow(widthInput){
	var tbl = document.getElementById('meetingrooms');
	
	var row = document.createElement("tr");
	var cell_1 = document.createElement("td");
	var input_1 = document.createElement("input");
	input_1.type = "text";
	input_1.name = "meetroomsname[]";
	input_1.style.width = "100px";
//	input_1.setAttribute('style', 'width:100px;');

	cell_1.appendChild(input_1);	
	row.appendChild(cell_1);	
	for(var i=0; i<allMeetingRooms.length; i++){
		var cell = document.createElement("td");
		var input = document.createElement("input");
		input.type = "text";
		input.name = "meetrooms_"+ allMeetingRooms[i] +"[]";
		input.style.width = widthInput+"px";
		
		cell.appendChild(input);	
		row.appendChild(cell);	
	}
	tbl.appendChild(row);	
}

$(document).ready(function(){
	$("input#add_rows").click(function () {
		  //alert('jirka')
		  $('table#meetingrooms tr:last').clone().insertAfter("table#meetingrooms tr:last");
		  $('table#meetingrooms tr:last td input').attr("value",'');
		  
		    $("#meetingrooms").tableDnD(
				    { dragHandle: "dragHandle",
				      onDragClass: "myDragClass"}
				    );
	
	  });
});

function addRoomInformation(){
	
	n = n + 1;
	var table = document.getElementById('roomInfo');
	var tr = document.createElement("tr");
	tr.setAttribute('id', 'rooms_'+n);
	var tbody = document.createElement("tbody");
	var tr2 = document.createElement("tr");
	tr2.setAttribute('id', 'roomsinfo_'+n);
	var td1 = document.createElement("td");
	var td2 = document.createElement("td");
	var td3 = document.createElement("td");
	var td4 = document.createElement("td");
	var td5 = document.createElement("td");
	var td6 = document.createElement("td");
	
	var input1 = document.createElement("input");
	var img1 = document.createElement("img");
	var input2 = document.createElement("input");
	var input3 = document.createElement("input");
	var input4 = document.createElement("input");
	var input5 = document.createElement("input");
	var strong6 = document.createElement("strong");
	var span6 = document.createElement("strong");
	
	input1.setAttribute('type', 'text');
	input1.setAttribute('name', 'roomDay[]');
	input1.setAttribute('id', 'roomday_'+n);
	input1.setAttribute('value',preferred_dates);
	input1.setAttribute('size', '12');
	
	img1.setAttribute('src', 'images/design/ic-calendar.gif');
	img1.setAttribute('width', '16');
	img1.setAttribute('height', '15');
	img1.setAttribute('border', '0');
	img1.setAttribute('onclick', 'return showCalendar("roomday_'+n+'", "D, d.m.y");');
	img1.onclick = function(){return showCalendar("roomday_"+n, "D, d.m.y")};
	img1.setAttribute('alt', 'Click for calendar');
	img1.setAttribute('title', 'Click for calendar');
	
	input2.setAttribute('type', 'text');
	input2.setAttribute('name', 'roomSingles[]');
	input2.setAttribute('id', 'roomSingles_'+n);
	input2.setAttribute('onchange', 'calculateTotal('+n+')');
	input2.onchange = function(){calculateTotal(n)};
	input2.setAttribute('size', '8');
	
	input3.setAttribute('type', 'text');
	input3.setAttribute('name', 'roomDoubles[]');
	input3.setAttribute('id', 'roomDoubles_'+n);
	input3.setAttribute('onchange', 'calculateTotal('+n+')');
	input3.onchange = function(){calculateTotal(n)};
	input3.setAttribute('size', '8');
	
	input4.setAttribute('type', 'text');
	input4.setAttribute('name', 'roomSuites[]');
	input4.setAttribute('id', 'roomSuites_'+n);
	input4.setAttribute('onchange', 'calculateTotal('+n+')');
	input4.onchange = function(){calculateTotal(n)};
	input4.setAttribute('size', '10');
	
	input5.setAttribute('type', 'text');
	input5.setAttribute('name', 'roomStaff[]');
	input5.setAttribute('id', 'roomStaff_'+n);
	input5.setAttribute('onchange', 'calculateTotal('+n+')');
	input5.onchange = function(){calculateTotal(n)};
	input5.setAttribute('size', '10');
	
	span6.setAttribute('id', 'total_'+n);
	
	strong6.appendChild(span6);
	
	td1.appendChild(input1);
	td1.appendChild(img1);
	td2.appendChild(input2);
	td3.appendChild(input3);
	td4.appendChild(input4);
	td5.appendChild(input5);
	td6.appendChild(strong6);
	
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);
	tr.appendChild(td5);
	tr.appendChild(td6);
	
	tbody.appendChild(tr);
	table.appendChild(tbody);
	
	var tbody2 = document.createElement("tbody");
	var content1_2 = document.createTextNode("Note:");
	var tr2 = document.createElement("tr");
	tr2.setAttribute('id', 'roomsinfo_'+n);
	var td1_2 = document.createElement("td");
	td1_2.setAttribute('colSpan', '6');
	var input1_2 = document.createElement("input");
	input1_2.setAttribute('type','text');
	input1_2.setAttribute('name','roomInfo[]');
	input1_2.setAttribute('size','60');
	input1_2.setAttribute('class','note');
	input1_2.setAttribute('className','note');
	td1_2.appendChild(content1_2);
	td1_2.appendChild(input1_2);
	tr2.appendChild(td1_2);
	
	tbody2.appendChild(tr2);
	table.appendChild(tbody2);
}
function calculateTotal(i){
	
	var total = document.getElementById('total_'+i);
	total.innerHTML = Number(document.getElementById('roomSingles_'+i).value) + Number(document.getElementById('roomDoubles_'+i).value) + Number(document.getElementById('roomSuites_'+i).value) + Number(document.getElementById('roomStaff_'+i).value);
	/*alert('modules/pcb/scripts/ajax_getTotalFindByRoomForm.php?numRooms='+(Number(document.getElementById('roomSingles_'+i).value) + Number(document.getElementById('roomDoubles_'+i).value) + Number(document.getElementById('roomSuites_'+i).value) + Number(document.getElementById('roomStaff_'+i).value)))*/
	postDataGetXml('modules/pcb/scripts/ajax_getTotalFindByRoomForm.php', 'numRooms='+(Number(document.getElementById('roomSingles_'+i).value) + Number(document.getElementById('roomDoubles_'+i).value) + Number(document.getElementById('roomSuites_'+i).value) + Number(document.getElementById('roomStaff_'+i).value)), viewTotalSubmit);
	
	// total Singles
	
	
	var totalsingles = document.getElementById('totalsingles');
	var numTotalSingles = 0;
	
	for(var k = 1; k<=n; k++){
		numTotalSingles = numTotalSingles + Number(document.getElementById('roomSingles_'+k).value);
	}
	totalsingles.innerHTML = numTotalSingles;
	
	// total Doubles
	var totaldoubles = document.getElementById('totaldoubles');
	var numTotalDoubles = 0;
	
	for(var k = 1; k<=n; k++){
		numTotalDoubles = numTotalDoubles + Number(document.getElementById('roomDoubles_'+k).value);
	}
	totaldoubles.innerHTML = numTotalDoubles;
	
	// total Suites
	var totalsuites = document.getElementById('totalsuites');
	var numTotalSuites = 0;
	
	for(var k = 1; k<=n; k++){
		numTotalSuites = numTotalSuites + Number(document.getElementById('roomSuites_'+k).value);
	}
	totalsuites.innerHTML = numTotalSuites;
	
	// total Staff
	var totalstaff = document.getElementById('totalstaff');
	var numTotalStaff = 0;
	
	for(var k = 1; k<=n; k++){
		numTotalStaff = numTotalStaff + Number(document.getElementById('roomStaff_'+k).value);
	}
	totalstaff.innerHTML = numTotalStaff;
	
	//total Total
	
	var totaltotal = document.getElementById('totaltotal');
	totaltotal.innerHTML = numTotalSingles + numTotalDoubles + numTotalSuites + numTotalStaff;
}
function addEventInformation(){
	//alert(set_ups_names.length);
   m = m + 1;
	var table = document.getElementById('eventInfo');
	var tbody = document.createElement("tbody");
	var tr = document.createElement("tr");
	tr.setAttribute('id', 'event_'+n);
	
	var tr2 = document.createElement("tr");
	tr2.setAttribute('id', 'eventinfo_'+n);
	
	var td1 = document.createElement("td");
	var td2 = document.createElement("td");
	var td3 = document.createElement("td");
	var td4 = document.createElement("td");
	var td5 = document.createElement("td");
	var td6 = document.createElement("td");
	var td7 = document.createElement("td");
	
	var input1 = document.createElement("input");
	var img1 = document.createElement("img");
	var input2 = document.createElement("input");
	var input3 = document.createElement("input");
	var input4 = document.createElement("select");
	var input5 = document.createElement("input");
	var input6 = document.createElement("input");
	var input7 = document.createElement("select");
	
	input1.setAttribute('type', 'text');
	input1.setAttribute('name', 'eventDay[]');
	input1.setAttribute('value',preferred_dates);
	input1.setAttribute('id', 'eventday_'+m);
	input1.setAttribute('size', '12');
	
	img1.setAttribute('src', 'images/design/ic-calendar.gif');
	img1.setAttribute('width', '16');
	img1.setAttribute('height', '15');
	img1.setAttribute('border', '0');
	img1.setAttribute('onclick', 'return showCalendar("eventday_'+m+'", "D, d.m.y");');
	img1.onclick = function(){return showCalendar("eventday_"+m, "D, d.m.y")};
	img1.setAttribute('alt', 'Click for calendar');
	img1.setAttribute('title', 'Click for calendar');
	
	input2.setAttribute('type', 'text');
	input2.setAttribute('name', 'eventStartTime[]');
	input2.setAttribute('class', 'inputSmall');
	input2.setAttribute('className', 'inputSmall');
	input2.setAttribute('size', '8');
	
	input3.setAttribute('type', 'text');
	input3.setAttribute('name', 'eventEndTime[]');
	input3.setAttribute('class', 'inputSmall');
	input3.setAttribute('className', 'inputSmall');
	input3.setAttribute('size', '8');
	
	input4.setAttribute('name', 'eventSet-Up_'+(m-1));
	input4.setAttribute('id', 'eventSet-Up_'+(m-1));
	input4.setAttribute('size', '1');
	input4.setAttribute('onchange', 'getTotalFindByEvent()');
	input4.onchange = function(){getTotalFindByEvent()};
	for(var k = 0; k < set_ups_names.length; k++){
		var opt =document.createElement('option');
		opt.setAttribute('value', set_ups_id[k]);
		opt.appendChild(document.createTextNode(set_ups_names[k]));
		input4.appendChild(opt);
	}
	
	input5.setAttribute('type', 'text');
	input5.setAttribute('name', 'eventArea[]');
	input5.setAttribute('class', 'inputSmall');
	input5.setAttribute('className', 'inputSmall');
	input5.setAttribute('size', '6');
	
	input6.setAttribute('type', 'text');
	input6.setAttribute('name', 'eventAttendees[]');
	input6.setAttribute('id', 'eventAttendees_'+(m-1));
	input6.setAttribute('onchange', 'getTotalFindByEvent()');
	input6.onchange = function(){getTotalFindByEvent()};
	input6.setAttribute('size', '6');
	input6.setAttribute('class', 'inputSmall');
	input6.setAttribute('className', 'inputSmall');
	
	input7.setAttribute('name', 'eventFunction_'+(m-1));
	input7.setAttribute('id', 'eventFunction_'+(m-1));
	input7.setAttribute('size', '1');
	
	for(var k = 0; k < event_fu_names.length; k++){
		var opt =document.createElement('option');
		opt.setAttribute('value', event_fu_names[k]);
		opt.appendChild(document.createTextNode(event_fu_names[k]));
		input7.appendChild(opt);
	}
	
	td1.appendChild(input1);
	td1.appendChild(img1);
	td2.appendChild(input2);
	td3.appendChild(input3);
	td4.appendChild(input7);
	td5.appendChild(input4);
	td6.appendChild(input5);
	td7.appendChild(input6);
	
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);
	tr.appendChild(td5);
	tr.appendChild(td6);
	tr.appendChild(td7);
	
	tbody.appendChild(tr);
	table.appendChild(tbody);
	
	var tbody2 = document.createElement("tbody");
	var tr2 = document.createElement("tr");
	tr2.setAttribute('id', 'eventinfo_'+n);
	var td1_2 = document.createElement("td");
	td1_2.setAttribute('colSpan', '7');
	var content1_2 = document.createTextNode("Note:");
	var input1_2 = document.createElement("input");
	input1_2.setAttribute('type', 'text');
	input1_2.setAttribute('name', 'eventInfo[]');
	input1_2.setAttribute('size', '60');
	input1_2.setAttribute('class', 'note');
	input1_2.setAttribute('className', 'note');
	td1_2.appendChild(content1_2);
	td1_2.appendChild(input1_2);
	tr2.appendChild(td1_2);
	tbody2.appendChild(tr2);
	table.appendChild(tbody2);
}

function addEventInformationNew(){
	var totTR = $('#eventInfo tr').lenght;
	alert(totTR)
	$('#eventInfo tr:last').clone().insertAfter("#eventInfo tr:last");
}


/* Total by event type */

function getTotalFindByEvent(){
   var maxRoomsSetUp = new Array();
   var ajaxLink = "";
   for(var k = 0; k < set_ups_id.length; k++){
      maxRoomsSetUp[set_ups_id[k]] = 0;
   }
   for(var o=0; o<m; o++){
	   var sel = document.getElementById('eventSet-Up_'+o);
	   var valAtt = document.getElementById('eventAttendees_'+o).value;
	   
	   if(!valAtt>0){
	   		valAtt = 0;
	   }
	   //alert(sel.options[sel.selectedIndex].value + " " + document.getElementById('eventAttendees_'+o).value);
	   //alert(sel.options[sel.selectedIndex].value + " < "+valAtt)
	   if(maxRoomsSetUp[sel.options[sel.selectedIndex].value]<valAtt){
		   maxRoomsSetUp[sel.options[sel.selectedIndex].value] = valAtt;
	   }
	  
   }
   for(var k = 0; k < set_ups_id.length; k++){
	  //alert(set_ups_names[k] + ": " +maxRoomsSetUp[set_ups_id[k]]);
	  ajaxLink += "maxRoomsSetUp["+set_ups_id[k]+"]="+maxRoomsSetUp[set_ups_id[k]];
	  if((k+1) < set_ups_id.length){
		  	ajaxLink += "&";
	  }
  }
 //alert(ajaxLink);
   //alert('event='+events+'&location='+locations+'&participants='+participants+'&rooms='+rooms+''+paramString);
 //  alert('modules/pcb/scripts/ajax_getTotalFindByEventForm.php'+ajaxLink)
  postDataGetXml('modules/pcb/scripts/ajax_getTotalFindByEventForm.php', ajaxLink, viewTotalSubmit);
}
function getTotalFindByCategory(){
	
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


