/*	Javascript Codes used for bci_web
 *
 *	(c) 2007 Centrum inc Software Solutions R & D
 *  Mhkonline - http://www.geocities.com/mhkonline2/
 *	August 2007 | Centrum Software Resarch Labs
 */
 
//---------------------------------------------------
// Common library functions
//---------------------------------------------------

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 = '';
}

/* fn isValidEmail()
 * input : string that is supposed to be an email-id
 * returns true if str is valid email else false
 * we are using regular expressions to validate it.
 * added : 03-Aug-2007
 */
function isValidEmail(str)
{	
	// Believe me, this will test for valid e-mail address, and it works
	var regExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;	
	return regExp.test(str);
}

function setContent(id,data)
{	gebid(id).value = data;}
//---------------------------------------------------------------

function validateNLForm(frm)
{// validates the NewsLetter SignUpForm
	var mailId = frm.txt_mailId.value;
	if(mailId)
	{
		if(isValidEmail(mailId)) return true;
		else	alert('Please Specify a valid email-address');
	}
	else
		alert('The e-mail field is empty.');
	return false;
}

function validateAdminSubmitNews(form)
{
	var isValid = true;
	var message = "You have forgot to fill the following : \n\n";
	if(form.txt_title.value == '')
	{ isValid = false; message += '* News Title\n';}
	if(form.txt_content.value == '')
	{ isValid = false; message += '* News Body\n';}
	
	if(isValid)	return true;

	alert(message);
	return false;
}

function validateUserFeedback(form)
{
	var isValid	= true;	
	var message = "You have forgot to fill the following : \n\n";
	if(form.txt_subject.value == '')
	{ isValid = false; message += '* Feedback Title\n';}
	if(gebid('txt_feedback').value == '')
	{ isValid = false; message += '* Feedback Content\n';}
	if(form.txt_name.value == '')
	{ isValid = false; message += '* Your Name\n';}
	if(form.txt_mailid.value == '')
	{ 
		isValid = false; message += '* Your e-mail id\n';	
	}
	else
	{
		if(!isValidEmail(form.txt_mailid.value))
		{ 	if(isValid)
				message = "Invalid e-mail id format";
			isValid = false; 
			message += '* Invalid e-mail id format';
		}
	}	
	if(isValid) return true;
	
	alert(message);
	return false;
}