var exist=0;
	var varRowCount ;
	var varNewRowCount ;
	var tableBody ;
	var trElement ; 
	var tdElement;
	var cellContents;
	var textBox;
	var colorFlag=true;
	var clr;
	var t,tb,tr,td;
function initialize(){
	if(document.getElementById('Rooms')!=null){
		varRowCount = document.getElementById('Rooms').rows.length;
		varRowCount--;
		varNewRowCount = varRowCount + 1;
		tableBody = document.getElementById('RoomsData');
	}
}
function defrag(total,type){
var deleted=0;
	for(i=exist;i>total;i--){
		for(t=1;t<=type;t++){
			tableBody.removeChild(document.getElementById(t+'_'+i));
			deleted++;
		}
		tableBody.removeChild(document.getElementById('spacer'+i));
	}
	exist=exist-(deleted/type);
	//exist=parseInt(total);
	deleted=0;
}

function drawForm(total,type){
	if(document.getElementById('Rooms')==null)
		alert();
	defrag(total,type);
//alert(exist);
var added=0;
	 for(i=exist+1;i<=total;i++){
			trElement = document.createElement('tr');
			trElement.setAttribute("id",'spacer'+i);
			tdElement = document.createElement('td');
			cellContents = document.createTextNode("Room ("+i+")");
			trElement.setAttribute("align","center");
			tdElement .appendChild(cellContents);
			tdElement .style.fontFamily='Verdana';
			tdElement .style.fontSize='12px';
			tdElement .style.color='white';
			tdElement .style.fontWeight= "bold";
			trElement.appendChild(tdElement);
			trElement.setAttribute("bgcolor","gray",false);
		    tableBody.appendChild(trElement);
		    
		for(tpe=1;tpe<=type;tpe++){
			trElement = document.createElement('tr');
			trElement.setAttribute("id",tpe+'_'+i);
			if (colorFlag) clr="#f4f5f7"; else clr="";
			trElement.setAttribute("bgcolor",clr,false);
			colorFlag=!colorFlag;
			//=========================================================
			t=document.createElement('table');
			tb=document.createElement('tbody');
			setRoomField("Title:","Title",tpe,i);
			setRoomField("First Name:","FName",tpe,i);
			setRoomField("Second Name:","SName",tpe,i);
			//=========================================================
			tdElement = document.createElement('td');
			tdElement.appendChild(t);
			trElement.appendChild(tdElement);
			tableBody.appendChild(trElement);
			added++;
		}
	}
	exist=exist+(added/type);
	//exist=parseInt(total);
	addedd=0;
	//alert(exist);
}

function setRoomField(name,field,typ,order){
	tr=document.createElement('tr');
	td=document.createElement('td');
	
	td = document.createElement('td');
	drawFieldStyle(name,false);
	//cellContents = document.createTextNode(name);
	//td.appendChild(cellContents);
	//td.setAttribute("style","color:white;font-family:verdana;text-align:center");
	td.style.fontFamily='Verdana';
	td.style.fontSize='x-small';
	td.style.color='#000066';
	tr.appendChild(td);
		     
	td = document.createElement('td');
	textBox = document.createElement('input');
	textBox.type = 'text';
	textBox.name = field+"_"+typ+"_"+order;
	textBox.id = field+"_"+typ+"_"+order;
	//BORDER-RIGHT: rgb(97,141,212) 1px solid; BORDER-TOP: rgb(97,141,212) 1px solid; FONT: 9pt vedana; BORDER-LEFT: rgb(97,141,212) 1px solid; COLOR: rgb(245,142,58); BORDER-BOTTOM: rgb(97,141,212) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)
	textBox.className='field';
	//textBox.value= field+"_"+typ+"_"+order;
	td.appendChild(textBox);
	tr.appendChild(td);
	tr.appendChild(td);
	tb.appendChild(tr);
	t.appendChild(tb);
}
function drawFieldStyle(name,isrequired){
	var table1,body1,row1,cell1,table,body,row,cell
	table1=document.createElement('table');
	body1=document.createElement('tbody');
	row1=document.createElement('tr');
	cell1=document.createElement('td');
		table1.style.color='#f5663a';
		cell1.setAttribute('height','20');
		
		table=document.createElement('table');
		body=document.createElement('tbody');
		row=document.createElement('tr');
		cell=document.createElement('td');
			table.setAttribute('width','163');
			row.style.color='#f5663a';
			//cell.style.color='#f5663a';
			var contents = document.createTextNode(name);
			cell.style.fontColor='#3399ff'
			cell.appendChild(contents);
		row.appendChild(cell);
		body.appendChild(row);
		table.appendChild(body);
	
	cell1.appendChild(table);
	row1.appendChild(cell1);
	body1.appendChild(row1);
	table1.appendChild(body1);
	//alert(table1.innerHTML);
	td.appendChild(table1);
}

function validateForm(frm,type,total,myprovider)
{
	
  if(myprovider!=3)
  {
	
	if(document.form.FirstName.value=="")
			{
		alert("First name of the lead name is required .");
		document.form.FirstName.focus();
		return false
			}

	if(document.form.SecondName.value=="")
			{
		alert("Last name of the lead name is required .");
		document.getElementById("SecondName").focus();
		return false
			}
	
	/*if(myprovider==2)
	{
		if(document.form.Adultsno.value=='')
		{
			alert("Please enter Adults Number");
			document.form.Adultsno.focus();
			return false;
		

		if(eval(document.form.Adultsno.value)>document.form.MaxAdults.value)
		{
		
			alert('Adults Number Cannot exceed '+ document.form.MaxAdults.value);
			document.form.Adultsno.value=document.form.MaxAdults.value;
			document.form.Adultsno.focus();
			return false;
		}
		}
	*/
	
	if(myprovider==1)
	{
	var title;
	for(i=1;i<=total;i++){
		for(tpe=1;tpe<=type;tpe++){
			title=document.getElementById("Title_"+tpe+"_"+i).value;
			if(title.length>4){
				alert("Title must be less than four characters");
				document.getElementById("Title_"+tpe+"_"+i).focus();
				return false
			}
			if(document.getElementById("FName_"+tpe+"_"+i).value==""){
				alert("Field required");
				document.getElementById("FName_"+tpe+"_"+i).focus();
				return false
			}
			if(document.getElementById("SName_"+tpe+"_"+i).value==""){
				alert("Field required");
				document.getElementById("SName_"+tpe+"_"+i).focus();
				return false
			}
			//alert(frm["FName_"+tpe+"_"+i]==null);
		}
	}
	}
	else if(myprovider==2)
	{
		//Jakob--all data must be entered
		mypos=17;
		
		
		for(i=1;i<=document.form.MaxAdults.value;i++)
		{
			mypos=mypos+1;
			//alert(document.form.item(mypos).name)
			if(document.form.item(mypos).value=="")
			{
				alert("Field required");
				document.form.item(mypos).focus();
				return false;
			}
			
			mypos=mypos+1;
			
			//alert(document.form.item(mypos).name)
			if(document.form.item(mypos).value=="")
			{
				alert("Field required");
				document.form.item(mypos).focus();
				return false;
			}
			mypos=mypos+1;
		}
		
	}
	}
	 if(myprovider==3)
	{
		//Tourico--all data must be entered
		mypos=0;		
		
		
		for(i=0;i<=document.form.myinputs.value;i++)
		{
			if(mypos<document.form.myinputs.value)
			{
			//alert(mypos)
			//alert(document.form.item(mypos).name)
			
			
			if(document.form.item(mypos).value=="")
			{
				alert("First name is required");
				document.form.item(mypos).focus();
				return false;
			}
			
			mypos=mypos+2;			
			
			if(document.form.item(mypos).value=="")
			{
				alert("Last name is required");
				document.form.item(mypos).focus();
				return false;
			}
			mypos=mypos+5;	
			
			//alert(mypos)
			//alert(document.form.item(mypos).name)
			//alert(document.form.item(mypos).value)
			if(document.form.item(mypos).value!=0)
				mypos=mypos+eval(document.form.item(mypos).value);
			
			
			mypos=mypos+1;	
			//alert(mypos)
			//alert(document.form.item(mypos).name)
			//alert(document.form.item(mypos).value)
			if(document.form.item(mypos).value!=0)
				mypos=mypos+eval(document.form.item(mypos).value)*2;
				
			//alert('afterboard:'+mypos)
			//alert(document.form.item(mypos).name)
			//alert(document.form.item(mypos).value)
				
			mypos=mypos+3;
			//alert('Exist loop:'+mypos)
		}
		}
	}
	//return false;
	
}
