/* 
Author :	Balu John Thomas
Support:	balujohn@angelsvista.com
*/

function gebid(id)
{	
	return document.getElementById(id);
}
function toggleDisplay(id)
{
	var elem = gebid(id);
	if(elem.style.display == '')
		elem.style.display = 'none';
	else
		elem.style.display = '';
}
function removeDisplay(id)
{
	var elem = gebid(id);
	elem.style.display='none';
}

//Function to validate E-mail address
function isValidEmail(str)
{	
	var regExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;	
	return regExp.test(str);
}

function validate()
{
	f = document.f1;
	var msg = "Hey You have missed the following items";
	var isValid = true;		
		if(f.name.value == "")
		{
			msg += "\n * Your Name";
			isValid = false;
		}
		if(f.events.value == "")
		{
			msg += "\n * Event Name";
			isValid = false;
		}
		if(f.number.value == "")
		{
			msg += "\n * Phone Number";
			isValid = false;
		}
		
		if(f.email.value == "")
		{
			msg += "\n * Email Address";
			isValid = false;
		}
		else
		{
			if(!isValidEmail(f.email.value))
			{ 	
				if(isValid)
					msg = "Invalid e-mail id format";
				isValid = false; 
			}
		}
	if(isValid) 
		return true;
	else
		alert(msg);
	return false;	
}

function moveoutid()
{
	var sda	 = document.getElementById('allDB');;
	var len	 = sda.length;
	var sda1 = document.getElementById('allocDB');
	for(var j=0; j<len; j++)
	{
		if(sda[j].selected)
		{
			var tmp	 = sda.options[j].text;
			var tmp1 = sda.options[j].value;
			//sda.remove(j);
			//j--;
			var y=document.createElement('option');
			y.text=tmp;
			try
			{
				if(!checkAvail(tmp1))
				{
					sda1.add(y,null);
					var len2 = sda1.length;
					sda1[len2-1].selected = true;
					sda1[len2-2].selected = false;
				}
			}
			catch(ex)
			{
				sda1.add(y);
			}
		}
	}
}
function checkAvail(input)
{
	//alert(input);
	var sda1 = document.getElementById('allocDB');
	var len3 = sda1.length;
	for(i=0;i<len3; i++)
	{
		if(sda1[i].value == input)
		{
			//alert(sda1[i].text)
			return true;
		}
	}
	return false;
}
function moveinid()
{
	var sda = document.getElementById('allDB');
	var sda1 = document.getElementById('allocDB');
	var len = sda1.length;
	for(var j=0; j<len; j++)
	{
		if(sda1[j].selected)
		{
			var tmp = sda1.options[j].text;
			var tmp1 = sda1.options[j].value;
			sda1.remove(j);
			var len2 = sda1.length;
			j--;
			var y=document.createElement('option');
			y.text=tmp;
			try
			{
				//sda.add(y,null);
				sda1[j].selected = true;
			}
			catch(ex)
			{
				//sda.add(y);	
			}
		}
	}
	return;	
}
