// JavaScript Document

function tinymce_setup() {
	var wid = document.body.clientWidth;
	if (wid < 1024) {
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		cleanup : false,	
		theme_advanced_source_editor_width : '300px',
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,blockquote,search,replace",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,insertdate,inserttime,preview",
		theme_advanced_buttons3 : "forecolor,backcolor,|,hr,removeformat,visualaid,sub,sup,|,sup,charmap,iespell,media,advhr,print,ltr,rtl,insertlayer,fullscreen",
		theme_advanced_buttons4 : "tablecontrols,|,moveforward,movebackward,absolute,styleprops,spellchecker,cite,abbr",
		theme_advanced_buttons5:"acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,styleselect,formatselect,fontsizeselect",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
	//	theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});
	} else {
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",	
		cleanup : false,
		theme_advanced_source_editor_width : 600,
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",		
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime",
		theme_advanced_buttons3 : "preview,|,forecolor,backcolor,tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap",
		theme_advanced_buttons4 : "iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
	//	theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});

	}
}


/*--------------------------------------------------------------------------*/


function validate_reservation(this_form)
{
	with (this_form)
	{
	
		if(isEmpty(Firstname.value))
		{   setError(this_form, Firstname, "Please enter your First Name"); return false; }
		
		if(isEmpty(Lastname.value))
		{	setError(this_form, Lastname, "Please enter your Last Name"); return false; }
			
		if(!isEmpty(Workphone.value))
			if (!isNumeric(Workphone.value))
			{	setError(this_form, Workphone, "Invalid Work phone number"); return false; }
		
		if(!isEmpty(Homephone.value))
			if (!isNumeric(Homephone.value))
			{	setError(this_form, Homephone, "Invalid Home phone number"); return false; }
				
		if(!isEmpty(Contactfax.value))
			if (!isNumeric(Contactfax.value))
			{	setError(this_form, Contactfax, "Invalid Fax number"); return false; }
		
		if(!isEmpty(MobileNumber.value))
			if (!isNumeric(MobileNumber.value))
			{	setError(this_form, MobileNumber, "Invalid Mobile number"); return false; }
				
		if(isEmpty(Useremail.value))
			{ setError(this_form, Useremail, "Please enter your Email"); return false; }
		else
			if (!isValidEmail(Useremail.value))
			{	setError(this_form, Useremail, "Invalid Email"); return false; }
			
		
		
			
		if(isEquals(day_required.value,"0"))
			{ setError(this_form, day_required, "Please select a day"); return false; }
			
		if(isEquals(month_required.value,"0"))
			{ setError(this_form, month_required, "Please select a month"); return false; }
		
		if(isEquals(year_required.value,"0"))
			{ setError(this_form, year_required, "Please select a year"); return false; }
			
		if((isEquals(Lunch.value,"0")) && (isEquals(Dinner.value,"0")))
			{ setError(this_form, Lunch, "Please select the time"); return false; }
			
		if(isEmpty(Numberinparty.value))
			{ setError(this_form, Numberinparty, "Please enter Number in party"); return false; }
		else if(!isNumeric(Numberinparty.value))
			{ setError(this_form, Numberinparty, "Invalid Number in party"); return false; }
	}
}

function isEmpty(val)
{
	if(val==null || val=="")
		return true;
	else 
		return false;
}

function isNumeric(val)
{
	var numericExpression = /^[0-9]+$/;

	if(val.match(numericExpression))
		return true;
	else		
		return false;
}

function isValidEmail(val)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	if(val.match(emailExp))
		return true;
	else
		return false;
}

function setError(this_form, field, msg)
{
	with(this_form)
	{
		field.focus();
		alert(msg);
	}
}

function isEquals(val1, val2)
{
		
	if(val1 == val2)
		return true;
	else
		return false;
}


function validateadmin_add_new_cms_page(thisform){

with(thisform)
{
	if (!IsValid(mand_page_name.value,'Page Name')) { 
		mand_page_name.focus(); return false;
	}
	
	if(!IsValid(tinyMCE.get('mand_page_content').getContent(),"Page Content")) {
		 mand_page_content.focus(); return false;
	}
	
}
}

function IsValid(Val,Label)
{
    if(trim(Val)=="")
    {
        alert(Label+" Should Not be Empty");
        return false;
    }
    return true;
}

var trim = function(Val)
{
    while(''+Val.charAt(0)==' ')
    Val=Val.substring(1,Val.length);
    return Val;
}
