//**************************Displaying Div according to the selection ***************************//
//here you place the ids of every element you want.
var ids=new Array('textfield','radio','checkbox','select1','file','text', 'textarea', 'password','select', 'multiselect', 'hidden');
function Submitform(id)
{
	var blnSelect = false;
	var blnText = false;
	hideallids(id);
	//document.frmCommon.label.value="";
	//document.frmCommon.instruction.value="";
	if(id=='textfield') 
	{
		showdiv('textfield');
		if (document.frmText.group2[0].checked)
		{
			showdiv('text');
			blnText = true;
		}
		if (document.frmText.group2[1].checked)
		{
			showdiv('textarea');
			blnText = true;
		}
		if (document.frmText.group2[2].checked)
		{
			showdiv('hidden');
			blnText = true;
		}
		if (document.frmText.group2[3].checked)
		{
			showdiv('password');
			blnText = true;
		}
		
		if (blnText == false)
		{
			document.frmSelect.group2[0].checked=true;
			showdiv('text');
		}
	}
	if(id=='text') 
	{
		showdiv('textfield');
		showdiv('text');
	}
	if(id=='textarea') 
	{
		showdiv('textfield');
		showdiv('textarea');
	}
	if(id=='password') 
	{
		showdiv('textfield');
		showdiv('password');
	}
	if(id=='hidden') 
	{
		showdiv('textfield');
		showdiv('hidden');
	}
	if(id=='select1')
	{
		showdiv('select1');
		if (document.frmSelect.group3[0].checked)
		{
			document.frmSelect.group3[0].checked=true;
			showdiv('select');
			blnSelect = true;
		}
		if (document.frmSelect.group3[1].checked)
		{
			document.frmSelect.group3[1].checked=true;
			showdiv('multiselect');
			blnSelect = true;
		}
		
		if (blnSelect == false)
		{
			document.frmSelect.group3[0].checked=true;
			showdiv('select');
		}
	}
	if(id=='select') 
	{
		showdiv('select1');
		showdiv('select');
	}
	if(id=='multiselect') 
	{
		showdiv('select1');
		showdiv('multiselect');
	}
	showdiv(id);
	document.frmCommon.label.focus();
}
function hideallids(){
	//loop through the array and hide each element by id
	
	for (var i=0;i<ids.length;i++){
		
		hidediv(ids[i]);
	}	
	  
}
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';

	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
//********************************************************************************************************//

//*******************Function for adding values from input to table list ********************************//

function IsIDAdded(ID)
{
	//frm = document.controlfieldradio;
	//MyDestinationList = frm.MyDestinationradio;
	
	var ret=false;
	for (var i=0;i<MyDestinationList.length;i++)
	{
		if (ID==MyDestinationList.options[i].value)
		{
			alert('This Value already exist, please write another');
				ret=true;
		}
		
	}
	return ret;
}
// Radio Options list Remove function creating MyDestinationList table object
function RemoveRadioList()
{
		frm = document.controlfieldradio;
		MyDestinationList = frm.MyDestinationradio;
		RemoveFromTheList();
}
// CheckBox Options list Remove function creating MyDestinationList table object
function RemoveCheckList()
{
		frm = document.controlfieldcheck;
		MyDestinationList = frm.MyDestinationcheck;
		RemoveFromTheList();
}
// SelectBox Options list Remove function creating MyDestinationList table object
function RemoveSelectList()
{
		frm = document.controlfieldselect;
		MyDestinationList = frm.MyDestinationselect;
		RemoveFromTheList();
}
// MultiSelect Options list Remove function creating MyDestinationList table object
function RemoveMultiSelectList()
{
		frm = document.controlfieldmultiselect;
		MyDestinationList = frm.MyDestinationmultiselect;
		RemoveFromTheList();
}
// Adding option to MyDestinationList Table
function AddToTheList(type) 
{
	//For Radio Creating MyDestinationList object and stroing option in controlvalue variable
	if(type=='radio')
	{
		frm = document.controlfieldradio;
		MyDestinationList = frm.MyDestinationradio;
		var controlvalue=frm.controlvalueradio.value;
	}
	//For Checkbox Creating MyDestinationList object and stroing option in controlvalue variable
	if(type=='checkbox')
	{
		frm = document.controlfieldcheck;
		MyDestinationList = frm.MyDestinationcheck;
		var controlvalue=frm.controlvaluecheck.value;
	}
	//For Select Creating MyDestinationList object and stroing option in controlvalue variable
	if(type=='select')
	{
		frm = document.controlfieldselect;
		MyDestinationList = frm.MyDestinationselect;
		var controlvalue=frm.controlvalueselect.value;
	}
	//For MultiSelect Creating MyDestinationList object and stroing option in controlvalue variable
	if(type=='multiselect')
	{
		frm = document.controlfieldmultiselect;
		MyDestinationList = frm.MyDestinationmultiselect;
		var controlvalue=frm.controlvaluemultiselect.value;
	}
	var NonSelected = true;
	var DidAdd = false;
	//Adding option record to the MyDestinationList Table
	if (controlvalue.length>0)
	{
		if (!IsIDAdded(controlvalue))
		{
			MyDestinationList.options[MyDestinationList.length] = new Option(controlvalue,controlvalue);
			DidAdd=true;
			
		}
		// Removing the option from the input controlvalue field
		if(type=='radio')
		{
			frm.controlvalueradio.value="";
		}
		if(type=='checkbox')
		{
			frm.controlvaluecheck.value="";
		}
		if(type=='select')
		{
			frm.controlvalueselect.value="";
		}
		if(type=='multiselect')
		{
			frm.controlvaluemultiselect.value="";
		}
	}
	else
	{
		alert('Please enter the Control Value');
	}
	if (DidAdd)
	{
		for (var i=0;i<MyDestinationList.length;i++)
		{
			MyDestinationList.className='';
		}
	}
}

function RemoveFromTheList() 
{
	var NonSelected = true;
	if ( MyDestinationList.selectedIndex >= 0)
	{
		MyDestinationList.options[MyDestinationList.selectedIndex] = null;
		NonSelected = false;
		return false;
	}
	if (NonSelected)
	{
		if(MyDestinationList.length<1)
		{
			alert('There is no Value in list to be Removed');
			return false;
		}
		alert('Please select the Value to be deleted');
		return false;
	}
			
	
	
}
//Assigning the class of mouseover, mouseout and onclick
function DoHL()
{
var e=window.event.srcElement;
while (e.tagName!="TR"){e=e.parentElement;}
if (e.className!='SL') e.className='HL';
}
function DoLL()
{
var e=window.event.srcElement;
while (e.tagName!="TR"){e=e.parentElement;}
if (e.className!='SL')	e.className='';
}
function DoSL()
{
var TB=e=window.event.srcElement;
while (TB.tagName!="TABLE")
{TB=TB.parentElement;}
for (var i=0;i<TB.rows.length;i++){TB.rows[i].className='';}
while (e.tagName!="TR"){e=e.parentElement;}
e.className='SL';
}
//****************************************************************************************************//
//***********************TextField validation *******************************************************//
function chktxtform()
{
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	document.controlfieldtext.textlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable
	if (document.frmCommon.label_seating[0].checked)
		document.controlfieldtext.textlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		document.controlfieldtext.textlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction to the hidden variable
	document.controlfieldtext.textinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position to the hidden variable
	if (document.frmCommon.instruction_seating[0].checked)
		document.controlfieldtext.textinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		document.controlfieldtext.textinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	//document.controlfieldtext.textinstructionpos.value=document.frmCommon.instruction_seating.value;
	
	//return false;
	//Make sure Size is numeric
	if (isNumber(document.controlfieldtext.textsize, "Size") == false)
		{
			document.controlfieldtext.textsize.value="";
			return false;
		}
	//Make sure MaxLength is numeric
	if (isNumber(document.controlfieldtext.textmaxlen, "maxLength") == false)
		{
			document.controlfieldtext.textmaxlen.value="";
			return false;
		}
}
//****************************************************************************************************//
//***********************TextArea Field validation *******************************************************//
function chktxtareaform()
{
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	document.controlfieldtextarea.textarealabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	if (document.frmCommon.label_seating[0].checked)
		document.controlfieldtextarea.textarealabelpos.value=document.frmCommon.label_seating[0].value;
	else
		document.controlfieldtextarea.textarealabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	document.controlfieldtextarea.textareainstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//document.controlfieldtextarea.textareainstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		document.controlfieldtextarea.textareainstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		document.controlfieldtextarea.textareainstructionpos.value=document.frmCommon.instruction_seating[1].value;
	//Make sure Rows is numeric
	if (isNumber(document.controlfieldtextarea.textarearows, "Rows") == false)
		{
			document.controlfieldtextarea.textarearows.value="";
			return false;
		}
	//Make sure Cols is numeric
	if (isNumber(document.controlfieldtextarea.textareacols, "Cols") == false)
		{
			document.controlfieldtextarea.textareacols.value="";
			return false;
		}
	//Make sure character limit is numeric
	if (isNumber(document.controlfieldtextarea.charlimit, "Character limit") == false)
		{
			document.controlfieldtextarea.charlimit.value="";
			return false;
		}
}
//***********************Password Field validation *******************************************************//
function chkpwdform()
{
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	document.controlfieldpwd.pwdlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//document.controlfieldpwd.pwdlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		document.controlfieldpwd.pwdlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		document.controlfieldpwd.pwdlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	document.controlfieldpwd.pwdinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//document.controlfieldpwd.pwdinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		document.controlfieldpwd.pwdinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		document.controlfieldpwd.pwdinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	//Make sure Size is numeric
	if (isNumber(document.controlfieldpwd.pwdsize, "Size") == false)
		{
			document.controlfieldpwd.pwdsize.value="";
			return false;
		}
	//Make sure maxLength is numeric
	if (isNumber(document.controlfieldpwd.pwdlen, "maxLength") == false)
		{
			document.controlfieldpwd.pwdlen.value="";
			return false;
		}
}

//****************************************************************************************************//
//***********************HiddenField validation *******************************************************//
function chkhiddenform()
{
	//Transfer form label value to the hidden variable
	if (document.frmCommon.label.value != "")
		document.controlfieldhidden.hiddenlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable
	if (document.frmCommon.label_seating.value != "")
		document.controlfieldhidden.hiddenlabelpos.value='Left';
		
	//Transfer form field instruction value to the hidden variable  
	document.controlfieldhidden.hiddeninstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction value to the hidden variable  
	document.controlfieldhidden.hiddeninstructionpos.value='Left';
	//Make sure Default Value is not blank
	if (isBlank(document.controlfieldhidden.textlabel, "Default Value") == false)
		{
			return false;
		}
}

//**********************Transfering values from MyDestination Table to SelectedOptionList*************//
function SelectedOptionList()
{//var formname="controlfield";
//alert(type); 

	if(MyDestinationList.length>0)
		{
			var SelectedList = "";
			for(var i = 0; i < MyDestinationList.length; i++) 
			{
				SelectedList += (MyDestinationList.options[i].value + "~");	
				
			}
			SelectedList = SelectedList.substring(0, SelectedList.length-1);
			frm.SelectedContactsList.value = SelectedList;
			frm.chkoption.value=SelectedList;
			
		}
	
}
//***********************Radio Field validation *******************************************************//
function chksaveradioform()
{	
	frm = document.controlfieldradio;
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	
	//frm = document.controlfieldradio;
	//Transfer form label value to the hidden variable  
	frm.radiolabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.radiolabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.radiolabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.radiolabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.radioinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction value to the hidden variable
	//frm.radioinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.radioinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.radioinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	MyDestinationList = frm.MyDestinationradio;
	if(document.controlfieldradio.saveradio.value=="1")
	{
	 //var type="radio";
	SelectedOptionList()
		
	}
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvalueradio.focus();
		return false;
	}
	
}
function chkeditradioform()
{	
	frm = document.controlfieldradio;
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	
	//frm = document.controlfieldradio;
	
	//Transfer form label value to the hidden variable  
	frm.radiolabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.radiolabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.radiolabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.radiolabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.radioinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.radioinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.radioinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.radioinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	
	MyDestinationList = frm.MyDestinationradio;
	if(document.controlfieldradio.editradio.value=="1")
	{
		SelectedOptionList()
		
	}
	
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvalueradio.focus();
		return false;
	}
	
}


//******************************CheckBox validation***********************************************//
function chksavecheckboxform()
{
	frm = document.controlfieldcheck;
	MyDestinationList = frm.MyDestinationcheck;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	frm.checkboxlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.checkboxlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.checkboxlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.checkboxlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.checkboxinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating[1].value;
   if(document.controlfieldcheck.savecheckbox.value=="1")
	{
		SelectedOptionList()
	}
		
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvaluecheck.focus();
		return false;
	}
	
}
function chkeditcheckboxform()
{	
	frm = document.controlfieldcheck;
	MyDestinationList = frm.MyDestinationcheck;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
   //Transfer form label value to the hidden variable  
	frm.checkboxlabel.value=document.frmCommon.label.value;
   //Transfer form label position value to the hidden variable  
	//frm.checkboxlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.checkboxlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.checkboxlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.checkboxinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.checkboxinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	if(frm.editcheckbox.value=="1")
	{
		SelectedOptionList()
		
	}
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvaluecheck.focus();
		return false;
	}
	
}

//*******************************************************************************************************//
//******************************Select Box validation***********************************************//
function chksaveselectform()
{
	frm = document.controlfieldselect;
	MyDestinationList = frm.MyDestinationselect;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	frm.selectlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.selectlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.selectlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.selectlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.selectinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.selectinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.selectinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.selectinstructionpos.value=document.frmCommon.instruction_seating[1].value;
   if(frm.saveselect.value=="1")
	{
		SelectedOptionList()
	}
	
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvalueselect.focus();
		return false;
	}
	
}

function chkeditselectform()
{
	frm = document.controlfieldselect;
	MyDestinationList = frm.MyDestinationselect;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
   //Transfer form label value to the hidden variable  
	frm.selectlabel.value=document.frmCommon.label.value;
   //Transfer form label position value to the hidden variable  
	//frm.selectlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.selectlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.selectlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.selectinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.selectinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.selectinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.selectinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	if(frm.editselect.value=="1")
	{	SelectedOptionList()
		
	}
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvalueselect.focus();
		return false;
	}
	
}

//*******************************************************************************************************//
//******************************MultiSelect Box validation***********************************************//
function chksavemultiselectform()
{
	frm = document.controlfieldmultiselect;
	MyDestinationList = frm.MyDestinationmultiselect;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	frm.multiselectlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.multiselectlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.multiselectlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.multiselectlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.multiselectinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	
   //Make sure Size is numeric
	if (isNumber(frm.multiselectsize, "Size") == false)
		{
			frm.multiselectsize.value="";
			return false;
		}
	 if(frm.savemultiselect.value=="1")
	{
		SelectedOptionList()
	}
	
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvaluemultiselect.focus();
		return false;
	}
	
}

function chkeditmultiselectform()
{
	frm = document.controlfieldmultiselect;
	MyDestinationList = frm.MyDestinationmultiselect;
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	frm.multiselectlabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//frm.multiselectlabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		frm.multiselectlabelpos.value=document.frmCommon.label_seating[0].value;
	else
		frm.multiselectlabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	frm.multiselectinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		frm.multiselectinstructionpos.value=document.frmCommon.instruction_seating[1].value;
   //Make sure Size is numeric
	if (isNumber(frm.multiselectsize, "Size") == false)
		{
			frm.multiselectsize.value="";
			return false;
		}
	if(frm.editmultiselect.value=="1")
	{
		SelectedOptionList()
		
	}
	if(frm.chkoption.value=="")
	{
		alert('Please add options from Control table');
		frm.controlvaluemultiselect.focus();
		return false;
	}
	
}

//*******************************************************************************************************//
//***********************File Field validation *******************************************************//
function chkfileform()
{
	//Make sure Form Label is not blank
	if (isBlank(document.frmCommon.label, "Form Label") == false)
		{
			return false;
		}
	//Transfer form label value to the hidden variable  
	document.contolfieldfile.filelabel.value=document.frmCommon.label.value;
	//Transfer form label position value to the hidden variable  
	//document.contolfieldfile.filelabelpos.value=document.frmCommon.label_seating.value;
	if (document.frmCommon.label_seating[0].checked)
		document.contolfieldfile.filelabelpos.value=document.frmCommon.label_seating[0].value;
	else
		document.contolfieldfile.filelabelpos.value=document.frmCommon.label_seating[1].value;
	//Transfer form field instruction value to the hidden variable
	document.contolfieldfile.fileinstruction.value=document.frmCommon.instruction.value;
	//Transfer form field instruction position value to the hidden variable
	//document.contolfieldfile.fileinstructionpos.value=document.frmCommon.instruction_seating.value;
	if (document.frmCommon.instruction_seating[0].checked)
		document.contolfieldfile.fileinstructionpos.value=document.frmCommon.instruction_seating[0].value;
	else
		document.contolfieldfile.fileinstructionpos.value=document.frmCommon.instruction_seating[1].value;
	//Make sure Size is numeric
	if (isNumber(document.contolfieldfile.filesize, "Size") == false)
		{
			document.contolfieldfile.filesize.value="";
			return false;
		}
	
}
//****************************************************************************************************//
//***********************Delete Field validation *******************************************************//
function chkdeletefield(fieldid, sectionid)
{ 
	var id=fieldid;
	var result= confirm("Are you sure you want to delete this field")
	
	if(result !=0)
	{
		location="form.cfm?fieldid="+id+"&deletefield=1&sectionid="+sectionid;
	
	}
}
//****************************************************************************************************//
//***********************Edit Field validation *******************************************************//
function chkeditfield(fieldid, type)
{ 
	document.myform.fid.value==type;
	alert(tp);
		location="form.cfm?"
	
}
//****************************************************************************************************//
//*************************Checking FormConnection Page *********************************************//
function chkformconnection()
{
	frm = document.myformconnection;
	if(frm.email.checked)
	{
		var emailid = frm.emails.value;
		if(emailid == "")
		{
			alert('Enter email-id');
			frm.emails.focus();
			return false;
		}
		var spChar = ",";
		var emails = new Array();
		for(i=0; i<emailid.length; i++)
		{
			if(emailid.charAt(i) == spChar)
			{
				emails = emailid.split(",");
			}
		}
		if(emails.length > 0)
		{
			for(x=0; x<emails.length; x++)
			{
				if(isEmail(emails[x], "emails") == false)
				{
					frm.emails.focus();
					return false;
				}
			}
		}
		else
		{
			if (isEmail(frm.emails.value, "Emails") == false)
			{
				frm.emails.focus();
				return false;
			}
		}
		
		
		if(frm.group1[1].checked == true)
		{
			if(frm.thanksmessage.value == "")
			{
				alert('Enter Thank You message');
				frm.thanksmessage.focus();
				return false;
			}
		}
		if(frm.group1[2].checked == true)
		{
			if(frm.internalURL.value == "")
			{
				alert('Enter Nav ID of the internal link');
				frm.internalURL.focus();
				return false;
			}
		}
		if(frm.group1[3].checked == true)
		{
			if(frm.externalURL.value == "")
			{
				alert('Enter external website URL');
				frm.externalURL.focus();
				return false;
			}
		}
	}
	
	else
	{
		if(!(frm.database.checked))
		{
			if(frm.group1[4].checked == false)
			{
			alert('Select at least one of the 2 options for receiving data collected through your form');
			return false;
			}
			else
			{
				if(frm.postURL.value == "")
				{
					alert('Enter external server path');
					frm.postURL.focus();
					return false;
				}
			}
		}
		else
		{
			if(frm.group1[1].checked == true)
			{
				if(frm.thanksmessage.value == "")
				{
					alert('Enter Thank You message');
					frm.thanksmessage.focus();
					return false;
				}
			}
			if(frm.group1[2].checked == true)
			{
				if(frm.internalURL.value == "")
				{
					alert('Enter Nav ID of the internal link');
					frm.internalURL.focus();
					return false;
				}
			}
			if(frm.group1[3].checked == true)
			{
				if(frm.externalURL.value == "")
				{
					alert('Enter external website URL');
					frm.externalURL.focus();
					return false;
				}
			}
		}
	}
	
}
//Post option selected Disabling others
function disableothers()
{
	frm = document.myformconnection;
	frm.email.checked=false;
	frm.database.checked=false;
	frm.emails.value ="";
	frm.thanksmessage.value ="";
	frm.internalURL.value ="";
	frm.externalURL.value ="";
	frm.postURL.focus();
	
}

//Post option selected Disabling others
function resetother()
{
	frm = document.myformconnection;
	frm.thanksmessage.value ="";
	frm.internalURL.value ="";
	frm.externalURL.value ="";
	frm.postURL.value="";
	
	if(frm.group1[1].checked == true)
		frm.thanksmessage.focus();
	if(frm.group1[2].checked == true)
		frm.internalURL.focus();
	if(frm.group1[3].checked == true)
		frm.externalURL.focus();		
	
}

//Data collection option reset the postvalue
function chkpostvalue()
{
	frm = document.myformconnection;
	if(frm.group1[4].checked == true)
	{
		frm.group1[0].checked = true;
	}
	frm.group1.checked == false;
	frm.group1[0].checked == false;
	if (frm.email.checked == false)
		frm.emails.value ="";
}
function addsection(id,objid)
{
	//winOpen("addsection.cfm?formid="+id,"object",650,700);
	window.location = "addsection.cfm?formid="+id+"&uObjID="+objid;
}
//Setting page opening new addsection page
function editsection(id, sid, objid)
{
	//winOpen("addsection.cfm?formid="+id+"&sectionid="+sid,"object",650,700);
	window.location = "addsection.cfm?formid="+id+"&sectionid="+sid+"&uObjID="+objid;
}

//Setting page opening auto-section field's page
function editautosection(sid)
{
	//winOpen("form.cfm?sectionid="+sid,"object",650,700);
	window.location = "form.cfm?sectionid="+sid;
}

//Setting page opening new addform page
function addform(id)
{
	//winOpen("form.cfm?formid="+id,"object",650,700);
	window.location = "form.cfm?formid="+id;
}
//Addsection page validation
function chkaddsection()
{
	frm = document.addsectionform;
	if(frm.sectionheading.value == "")
	{
		alert('Please write the Section name');
		frm.sectionheading.focus();
		return false;
	}
}
//***********************Delete Section validation *******************************************************//
function chkdeletesection(formid, sectionid)
{ 
	var id=formid;
	var sid=sectionid;
	var result= confirm("Are you sure you want to delete this Section")
	
	if(result !=0)
	{
		location="settings.cfm?formid="+id+"&sectionid="+sid+"&deletefield=1"
	
	}
	

}
//Checking the blank field
function isBlank(obj,displayName)
{
	var str="";
	str=obj.value;
	var len=str.length;
	var i;
	for(i=0;i<len;++i)
	{
		if(str.charAt(i)!=" ")
		{
			return true;
		}
	}
	alert(displayName+" cannot be left blank");
	obj.focus();
	return false;
}
// Checking numeric value
function isNumber(obj,displayName)
{
	var str=lTrim(obj.value);
	for(i=0;i<str.length;i++)
	{
		if(str.charAt(i)<'0'||str.charAt(i)>'9')
		{	
			if((str.charAt(0))=="-")
			{
				i=i+1;
					continue;
			}
			alert(displayName+" should be numeric.");
			obj.focus();
			return false;
		}
	}
	return true;
}
function Trim(s)
{
	var tempStr1, s1 ,tmpStr2 ;
	s1 = s;
	tempStr1 = lTrim(s1);
	tempStr2 = rTrim(tempStr1);
	return tempStr2 ;
}	
	
function rTrim(s)
{
	var temp="";
	tempStr="";
	temp=s;
	var len=s.length;
	
	if(len>0)
	{
		for(i=len;i > 0;i--)
		{
			if(temp.charAt(i-1)!=" ")
				break;
		}
		
		k=0;
		for(j=0;j<i;j++)
		{
			tempStr=tempStr+temp.charAt(j);
			k=k+1;
		}
		return tempStr;
	}
	else
		return tempStr;
}

function lTrim(s)
{
	var temp="";
	tempStr="";
	temp=s;
	var len=s.length;
	
	if(len>0)
	{
		for(i=0;i<len;i++)
		{
			if(temp.charAt(i)!=" ")
				break;
		}
		
		k=0;
		for(j=i;j<len;j++)
		{
			tempStr=tempStr+temp.charAt(j);
			k=k+1;
		}
		return tempStr;
	}
	else
		return tempStr;
}
//Bulk mail checking validations
function isEmail (obj,displayName) 
{ 
var theStr=lTrim(obj);
var atIndex = theStr.indexOf('@'); 
var dotIndex = theStr.indexOf('.', atIndex); 
var flag = true; 
theSub = theStr.substring(0, dotIndex+1) 

if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
{ 
	alert("Not a valid email id");
	//obj.focus();
	flag = false; 
} 
else { flag = true; } 
return(flag); 
}
//Email  Checking validations
function isValidEmail (obj,displayName) 
{ 
var theStr=lTrim(obj.value);
var atIndex = theStr.indexOf('@'); 
var dotIndex = theStr.indexOf('.', atIndex); 
var flag = true; 
theSub = theStr.substring(0, dotIndex+1) 

if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
{ 
	alert("Not a valid email id");
	obj.focus();
	flag = false; 
} 
else { flag = true; } 
return(flag); 
}
//Character Validation
function IsCharacter(obj,displayName)
{
	var s=""; 
	s=lTrim(obj.value);
	splChars=new Array("@","#","$","%","^","&","*","!","\'","(",")","_","=","+","[","]","{","}","|","\\","<",">",".","/","?","\"","0","1","2","3","4","5","6","7","8","9");
	if(s.length>0)
	{
	for(i=0;i<s.length;i++)
		for(j=0;j<splChars.length;j++)
		{
			if(s.charAt(i)==splChars[j])
			{
				alert(displayName+" cannot have special characters like @,#,$,%,1,2,3 etc.");
				obj.focus();
				return false;
			}
		}
	return true;
	}
	else
	{ 
		alert(displayName+" cannot be left blank");
		obj.focus();
		return false;
	}
}
//AlphaNumeric Validation
function IsAlphaNumber(obj,displayName)
{
	var str=lTrim(obj.value);
	var flag=false;
	if(str.length>0)
	{
			for(i=0;i<str.length;i++)
			{	
				if((str.charAt(0))=="-")
				{
					i=i+1;
						continue;
				}
				if(str.charAt(i)<'0'||str.charAt(i)>'9')
				{
					flag=true;	
				}
			}
			if(flag)
				return true;
			else
			{
				alert(displayName+" should be non-numeric.");
				obj.focus();
				return false;
			}
	}
	else
		return true;
	return flag;
}
//CheckBox Validations
function isChecked(obj,displayName)
{
	var flag=false; 
	for (counter = 0; counter < obj.length; counter++)
	{
		if (obj[counter].checked)
		{flag=true;}
		
	}
	
	if(flag)
		return true;
	else
	{
		alert("Please select atleast one option of "+displayName);
		return false;
	}
	
}
//SelectBox Validations
function isSelected(obj,displayName)
{	var flag=false; 
	for (var i = 0; i < obj.length; i++)
	{
		if (!obj.options[i].selected)
		{flag=true;}
	}
	if(flag)
		return true;
	else
	{
		alert("Please select atleast one option of "+displayName);
		return false;
	}
}
/* win_open(where,x,y)*/
function winOpen(f_sWhere)
{
	if (arguments.length > 1)
	{
		sWin = arguments[1];
	}
	else
	{
		sWin = 1;
	}
	
	if (arguments.length <= 2)
	{
		iX = 700;
		iY = 550;
	}
	else
	{
		iX = arguments[2];
		iY = arguments[3];
	}
	
	win = window.open(f_sWhere,"Object"+sWin,"scrollbars=1,width="+iX+",height="+iY);
	win.focus();
}

function maxLength(obj,displayname,num)
{
	var str="";
	var  num=num;
	str=lTrim(obj.value);

	if(str.length > num)
	{
		alert(displayname+" should not have more than "+num+" characters.");
		obj.focus();
		return false;
	}
	return true;
}

//new validation functions for multiple languages

function isNumber_new(obj,displayName,str1)
{
	var str=lTrim(obj.value);
	for(i=0;i<str.length;i++)
	{
		if(str.charAt(i)<'0'||str.charAt(i)>'9')
		{	
			if((str.charAt(0))=="-")
			{
				i=i+1;
					continue;
			}
			alert(displayName+" "+str1);
			obj.focus();
			return false;
		}
	}
	return true;
}

function IsCharacter_new(obj,displayName,str1,str2)
{
	var s=""; 
	s=lTrim(obj.value);
	splChars=new Array("@","#","$","%","^","&","*","!","\'","(",")","_","=","+","[","]","{","}","|","\\","<",">",".","/","?","\"","0","1","2","3","4","5","6","7","8","9");
	if(s.length>0)
	{
	for(i=0;i<s.length;i++)
		for(j=0;j<splChars.length;j++)
		{
			if(s.charAt(i)==splChars[j])
			{
				alert(displayName+" "+str1+" @,#,$,%,1,2,3 etc.");
				obj.focus();
				return false;
			}
		}
	return true;
	}
	/*else
	{ 
		alert(displayName+str2);
		obj.focus();
		return false;
	}*/
}

function isBlank_new(obj,displayName,str1)
{
	var str="";
	str=obj.value;
	var len=str.length;
	var i;
	for(i=0;i<len;++i)
	{
		if(str.charAt(i)!=" ")
		{
			return true;
		}
	}
	alert(displayName+" "+str1);
	obj.focus();
	return false;
}

function IsAlphaNumber_new(obj,displayName,str1)
{
	var str=lTrim(obj.value);
	var flag=false;
	if(str.length>0)
	{
			for(i=0;i<str.length;i++)
			{	
				if((str.charAt(0))=="-")
				{
					i=i+1;
						continue;
				}
				if(str.charAt(i)<'0'||str.charAt(i)>'9')
				{
					flag=true;	
				}
			}
			if(flag)
				return true;
			else
			{
				alert(displayName+" "+str1);
				obj.focus();
				return false;
			}
	}
	else
		return true;
	return flag;
}

function isChecked_new(obj,displayName,str1)
{
	var flag=false; 
	for (counter = 0; counter < obj.length; counter++)
	{
		if (obj[counter].checked)
		{flag=true;}
		
	}
	if (!obj.length){if (obj.checked){flag=true;}}
		
	if(flag)
		return true;
	else
	{
		alert(str1+" "+displayName);
		return false;
	}
	
}
//SelectBox Validations
function isSelected_new(obj,displayName,str1)
{	var flag=false; 
	for (var i = 0; i < obj.length; i++)
	{
		if (obj.options[i].selected)
		{flag=true;}
	}
	if(flag)
		return true;
	else
	{
		alert(str1+" "+displayName);
		return false;
	}
}

//Email  Checking validations
function isValidEmail_new(obj,displayName,str1) 
{ 
var theStr=lTrim(obj.value);
var atIndex = theStr.indexOf('@'); 
var dotIndex = theStr.indexOf('.', atIndex); 
var flag = true; 
theSub = theStr.substring(0, dotIndex+1) 
if (theStr != "")
{
	if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
	{ 
		alert(str1);
		obj.focus();
		flag = false; 
	} 
	else { flag = true; }
}
else { flag = true; } 
return(flag); 
}

function maxLength_new(obj,displayname,num,str1,str2)
{
	var str="";
	var  num=num;
	str=lTrim(obj.value);

	if(str.length > num)
	{
		alert(displayname+" "+str1+" "+num+" "+str2);
		obj.focus();
		return false;
	}
	return true;
}

function AjaxRequest(url, type, edit)
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
             http_request.overrideMimeType('text/xml');                
        }		
	} 
	else if (window.ActiveXObject) { // IE	
	http_request = new ActiveXObject("Microsoft.XMLHTTP");
	/*if (http_request.overrideMimeType) {
             http_request.overrideMimeType('text/xml');                
        }*/	
	}
	if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }	
	http_request.onreadystatechange = function() { alertContents(http_request, type, edit); };
    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContents(http_request, type, edit) 
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            //alert(http_request.responseText);
			hidediv("divStayTopLeft");
			xmldoc = http_request.responseXML;
			var stat = xmldoc.getElementsByTagName("status").item(0);
			var statusvalue = stat.firstChild.data;
			if(statusvalue == 1)
			{
				if(edit==0){
					if(type==1)
						hidediv("email")
					else
						hidediv("Temail")
					}
				else{
					if(type==1)
						showdiv("email")
					else
						showdiv("Temail")
					
				}
				//alert("Comment Successfully Added");
			}
			else
			{ var str = '';
			  str = str + '<table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" align="center" bgcolor="c0c0c0"><tr>';
			  str = str + '<td width="60%">Send form data using this email id</td>';
			  str = str + '<td colspan="2"><input type="Radio" name="Smail" value="1">&nbsp;&nbsp;&nbsp;&nbsp;<input type="Radio" name="Smail" value="0" checked></td>';
			  str = str + '</tr></table>';
			 
			    if(type==1)
				{
					var divsemail=document.getElementById("email");
					divsemail.innerHTML = str;
					showdiv("email");
				}
				else
				{
					var divsemail=document.getElementById("Temail");
					divsemail.innerHTML = str;
					showdiv("Temail");
				}
			}
        } else {
            alert('There was a problem with the request.');
        }
    }

}
function resetdiv(formid,type, edit)
{
	var str='';
	if(type==1)
	{
		if (edit==0)
		{
			var divsemail=document.getElementById("email");
			divsemail.innerHTML = str;
			showdiv("email");
		}
		else{
			hidediv("email");
		}
	}
	else
	{
		if (edit==0)
		{
			var divsemail=document.getElementById("Temail");
			divsemail.innerHTML = str;
			showdiv("Temail");
		}
		else{
			hidediv("Temail");
		}
	}
}

function checkEmailSetting(formid,type,edit)
{
	showdiv("divStayTopLeft");
	AjaxRequest('checkEmailSetting.cfm?formid='+formid, type, edit);
}

function JSFX_FloatTopLeft()
{
	var startX = 500, startY = 500;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 40);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}