// Login Form Validation

function Clicking(){
	var frmlogin=document.logFrm;
	if(frmlogin.username.value==""){
		alert("User name should not be blank");
		frmlogin.txtName.focus();
		return false;
	}
	if(frmlogin.password.value==""){
		alert("Password should not be blank");
		frmlogin.txtPwd.focus();
		return false;
	}
	document.logFrm.action="index.php";
	document.logFrm.submit();
}

function jumpSrch(pgVal){
	document.SearchForm.start.value=pgVal;
	document.SearchForm.submit();
}

function ValidateChange()
{
	var formobj=document.change_pass;
	if(!IsBlank(formobj.old_pass,'Old Password should not be blank.'))
		return false;
	if(formobj.old_pass.value.length < 4)
	{
		alert("Enter minimum 4-digit:");
		formobj.old_pass.focus();
		return false;
	}
	
	if(!IsBlank(formobj.new_pass,'New Password should not be blank.'))
		return false;
	if(formobj.new_pass.value.length < 4)
	{
		alert("Enter minimum 4-digit:");
		formobj.new_pass.focus();
		return false;
	}
	
	if(!IsBlank(formobj.conf_pass,'Retype Password should not be blank.'))
		return false;
	if(formobj.conf_pass.value.length < 4)
	{
		alert("Enter minimum 4-digit:");
		formobj.conf_pass.focus();
		return false;
	}
	if(formobj.new_pass.value!=formobj.conf_pass.value){
		alert("Retype password does not match with original password");
		formobj.conf_pass.focus();
		return false;
	}
	
	return true;
}

function ValidateLogin()
{
	var formobj=document.login;

	if(!IsEmail(formobj.email,'Email Address should not be blank.'))
		return false;
	if(!IsBlank(formobj.pwd,'Password should not be blank.'))
		return false;
	
	return true;
}

function ValidateEmail()
{
	var formobj=document.forget_pass;

	if(!IsEmail(formobj.email,'Email Address should not be blank.'))
		return false;
	
	return true;
}


function ValidateContectUs()
{
	
	var formobj = document.Con;

	if(!IsBlank(formobj.fname,'Firstname should not be blank.'))
		return false;
	if(!IsBlank(formobj.lname,'Lastname should not be blank.'))
		return false;
	if(!IsEmail(formobj.email,'Email Address should not be blank.'))
		return false;
	if(!IsBlank(formobj.phone,'Contact Number should not be blank.'))
		return false;
		
	return true;
}

function enbl()
	{
	  if(document.Menu.b_type[0].checked)
		{
		 document.getElementById("txt").style.display = 'block';
		 document.getElementById("img").style.display = 'none';
		}
	  if(document.Menu.b_type[1].checked)
		{
		 document.getElementById("txt").style.display = 'none';
		 document.getElementById("img").style.display = 'block';
		}
	}
	
function enb2()
	{
	  if(document.Banner.b_type[0].checked)
		{
		 document.getElementById("txt").style.display = 'block';
		 document.getElementById("img").style.display = 'none';
		}
	  if(document.Banner.b_type[1].checked)
		{
		 document.getElementById("txt").style.display = 'none';
		 document.getElementById("img").style.display = 'block';
		}
	}

function validateAdmin()
{
	var formobj=document.Admin;
	if(!IsBlank(formobj.admin_fname,'Admin Firstname should not be blank.'))
		return false;
	if(!IsBlank(formobj.admin_lname,'Admin Lastname should not be blank.'))
		return false;
	if(!IsEmail(formobj.admin_email,'Email Address should not be blank.'))
		return false;
	if(!IsBlank(formobj.admin_pass,'Password should not be blank.'))
		return false;
	if(formobj.admin_pass.value.length < 4)
	{
		alert("Enter minimum 4-digit:");
		formobj.admin_pass.focus();
		return false;
	}
	if(!IsBlank(formobj.conf_pass,'Retype Password should not be blank.'))
		return false;
	if(formobj.conf_pass.value.length < 4)
	{
		alert("Enter minimum 4-digit:");
		formobj.conf_pass.focus();
		return false;
	}
	if(formobj.admin_pass.value!=formobj.conf_pass.value){
		alert("Retype password does not match with original password");
		formobj.conf_pass.focus();
		return false;
	}
	
	return true;
}


function ValidateMenu()
{
	var formobj=document.Menu;
	if(!IsBlank(formobj.menu_name,'Menu Name should not be blank.'))
		return false;
	if(!IsNumber(formobj.sort_order,'Sort Order should not be blank.'))
		return false;
	var desc = FCKeditorAPI.GetInstance('menu_desc');
	if(document.Menu.b_type[0].checked)
	{
		if (desc.GetXHTML() == "")
		{      
			alert("Desciption should not be blank");
			formobj.menu_desc.focus();
			return false;
		}
	}
	if(document.Menu.b_type[1].checked)
	{
		if(!IsBlank(formobj.menu_link,'Menu Link should not be blank.'))
		return false;
	}
return true;
}

function ValidateNews()
{
	var formobj=document.News;
	if(!IsBlank(formobj.news_title,'News Title should not be blank.'))
		return false;
	if(!IsBlank(formobj.news_link,'News Link should not be blank.'))
		return false;
	/*var desc = FCKeditorAPI.GetInstance('news_full');
	if (desc.GetXHTML() == "")
	{      
		alert("Full News should not be blank");
		formobj.news_full.focus();
		return false;
	}*/
	
return true;
}

function ValidateCat()
{
	var formobj=document.Category;
	if(!IsBlank(formobj.categories_name,'Category Name should not be blank.'))
		return false;

	var desc = FCKeditorAPI.GetInstance('categories_desc');
	if (desc.GetXHTML() == "")
	{      
			alert("Desciption should not be blank");
			formobj.categories_desc.focus();
			return false;
	}
}

function ValidateSubCat()
{
	var formobj=document.Category;
	
	if(!IsBlank(formobj.categories_id,'Select Category'))
		return false;
	
	if(!IsBlank(formobj.subcat_name,'Sub Category Name should not be blank.'))
		return false;
		
	return true;
}

function ValidateAdvertise()
{
	var formobj=document.AdvertiseAdd;
	
	if(!IsBlank(formobj.subcat_id,'Select Sub Category'))
		return false;	
	if(!IsBlank(formobj.advertise_name,'Advertise Name should not be blank.'))
		return false;
	if(!IsUrl(formobj.advertise_link,'Advertise Link should not be blank.'))
		return false;
	if(!IsBlank(formobj.image,'Image should not be blank.'))
		return false;
	return true;
}

function ValidateModAdvertise()
{
	var formobj=document.AdvertiseMod;
	
	if(!IsBlank(formobj.subcat_id,'Select Sub Category'))
		return false;	
	if(!IsBlank(formobj.advertise_name,'Advertise Name should not be blank.'))
		return false;
	if(!IsUrl(formobj.advertise_link,'Advertise Link should not be blank.'))
		return false;
		
	return true;
}

function ValidateAdvertiseAll()
{
	var formobj=document.AdvertiseAddAll;
	
	if(!IsBlank(formobj.categories_id,'Select Category'))
		return false;
	if(!IsBlank(formobj.advertise_name,'Advertise Name should not be blank.'))
		return false;
	if(!IsUrl(formobj.advertise_link,'Advertise Link should not be blank.'))
		return false;	
	if(!IsBlank(formobj.image,'Image should not be blank.'))
		return false;
		
	return true;
}

function ValidateModAdvertiseAll()
{
	var formobj=document.AdvertiseModAll;
	
	if(!IsBlank(formobj.categories_id,'Select Category'))
		return false;
	if(!IsBlank(formobj.advertise_name,'Advertise Name should not be blank.'))
		return false;
	if(!IsUrl(formobj.advertise_link,'Advertise Link should not be blank.'))
		return false;
		
	return true;
}

function ValidateUrl()
{
	var formobj=document.Url;
	if(!IsBlank(formobj.subcat_id,'Select Sub Category'))
		return false;
	if(!IsBlank(formobj.url_name,'Url Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.phone,'Phone Number should not be blank.'))
		return false;
	/*if(!IsBlank(formobj.contact_name,'Contact Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.contact_phone,'Contact Phone Number should not be blank.'))
		return false;*/
	if(!IsEmail(formobj.contact_email,'Contact Email should not be blank.'))
		return false;
	
	return true;
}

function ValidateEditUrl()
{
	var formobj=document.Url;
	if(!IsBlank(formobj.subcat_id,'Select Sub Category'))
		return false;
	if(!IsBlank(formobj.url_name,'Url Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.phone,'Phone Number should not be blank.'))
		return false;
	/*if(!IsBlank(formobj.contact_name,'Contact Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.contact_phone,'Contact Phone Number should not be blank.'))
		return false;
	if(!IsEmail(formobj.contact_email,'Contact Email should not be blank.'))
		return false;*/
	
	return true;
}

function ValidateBusiness()
{
	var formobj=document.User;
	if(!IsBlank(formobj.url_name,'Business Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.phone,'Business Phone Number should not be blank.'))
		return false;
	if(!IsBlank(formobj.contact_name,'Contact Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.contact_phone,'Contact Phone Number should not be blank.'))
		return false;
	if(!IsEmail(formobj.contact_email,'Contact Email should not be blank.'))
		return false;
	if(!IsBlank(formobj.categories,'Please Select Category.'))
		return false;
	if(!IsBlank(formobj.subcat,'Please Select Sub Category.'))
		return false;
		
	return true;
}

function ValidateAddFood()
{

	var formobj=document.FoodAdd;
	if(!IsBlank(formobj.food_court_name,'Food Court Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.food_court_phone,'Phone Number should not be blank.'))
		return false;
	if(!IsBlank(formobj.food_court_add1,'Address Line 1 should not be blank.'))
		return false;
	if(!IsBlank(formobj.image,'Image should not be blank.'))
		return false;
		
return true;
}


function ValidateModFood()
{
	var formobj=document.FoodMod;
	if(!IsBlank(formobj.food_court_name,'Food Court Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.food_court_phone,'Phone Number should not be blank.'))
		return false;
	if(!IsBlank(formobj.food_court_add1,'Address Line 1 should not be blank.'))
		return false;
	
return true;
}

function ValidateCuisine()
{
	var formobj=document.Cuisine;
	
	if(!IsBlank(formobj.cuisine_name,'Cuisine Name should not be blank.'))
		return false;
		
return true;
}

function ValidateFeatures()
{
	var formobj=document.Features;
	
	if(!IsBlank(formobj.features_name,'Features Name should not be blank.'))
		return false;
		
return true;
}

function ValidateQuickCategory()
{
	var formobj=document.QuickCategory;
	
	if(!IsBlank(formobj.qcat_name,'Quick Link Category Name should not be blank.'))
		return false;
		
return true;
}

function ValidateBuletinCategory()
{
	var formobj=document.BuletinCategory;
	
	if(!IsBlank(formobj.buletincategory_name,'Buletin Category Name should not be blank.'))
		return false;
		
return true;
}

function ValidateBuletinBoard()
{
	var formobj=document.BuletinBoard;
	
	if(!IsBlank(formobj.buletincategory_id,'Please Select Buletin Category.'))
		return false;
	if(!IsBlank(formobj.buletinboard_name,'Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.buletinboard_phone,'Phone should not be blank.'))
		return false;
	if(!IsEmail(formobj.buletinboard_email,'email Address should not be blank.'))
		return false;
	if(!IsBlank(formobj.buletinboard_listing,'Buletin Board Listing should not be blank.'))
		return false;
		
return true;
}

function ValidateQuickLink()
{
	var formobj=document.quick_link;
	
	if(!IsBlank(formobj.qcat_id,'Select Quick Link Category.'))
		return false;
	if(!IsBlank(formobj.subcat_id,'Select Category to Link.'))
		return false;	
		
return true;
}

function ValidateSimchaCategory()
{
	var formobj=document.SimchaCategory;
	
	if(!IsBlank(formobj.subcat_id,'Select Category to Link.'))
		return false;	
		
return true;
}

function DeleteRecords(){
	 var hasSelected = false;
	 var chklen = document.DeleteFrm.elements.length;
	 for( var n = 0; n < chklen; n++ ){
		currobj = document.DeleteFrm.elements[n];
		if(currobj.type == "checkbox" && currobj.checked)
			hasSelected = true;
	}
	if( hasSelected ){ 
		if( confirm( "Are you sure you want to delete?" )){  
			for( var n = 0; n < chklen; n++ ){
				currobj = document.DeleteFrm.elements[n];
				if(currobj.type == "checkbox" && currobj.checked){
					document.DeleteFrm.submit();
				}
			}
		}
	}
	else{  
	   alert( "Please select at least one Record to delete." );
	}
}

function AddRecords(){
	 var hasSelected = false;
	 var chklen = document.DeleteFrm.elements.length;
	 for( var n = 0; n < chklen; n++ ){
		currobj = document.DeleteFrm.elements[n];
		if(currobj.type == "checkbox" && currobj.checked)
			hasSelected = true;
	}
	if( hasSelected ){ 
		if( confirm( "Are you sure you want to delete?" )){  
			for( var n = 0; n < chklen; n++ ){
				currobj = document.DeleteFrm.elements[n];
				if(currobj.type == "checkbox" && currobj.checked){
					document.DeleteFrm.submit();
				}
			}
		}
	}
	else{  
	   alert( "Please select at least one Record to delete." );
	}
}

function IsNumber(obj, msgstr)
{
	if(Trim(obj.value) == ""){
		alert(msgstr);
		obj.focus();
		return false;
	}	
	else
	{
	    if(obj.value.search(/^\d+$/) != -1)
    	    return true;
	    else
		{
			alert("Invalid Value! Enter Only Numeric Value");
			obj.focus();
    	    return false;
		}
	}
}


// Validation For Blank Field
function IsBlank(obj,msg)
{
		if(Trim(obj.value) == "")
		{
			alert(msg);
			obj.focus();
			return false;
		}
		return true;
}
// Trim Function
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}

// Right Trim Function
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	}
	return strTemp;
}

//Left Trim Function
function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

// Email Validation Function
function IsEmail(obj, msgstr){
	if(Trim(obj.value) == ""){
		alert("Email Address should not be blank.");
		obj.focus();
		return false;
	}
	else{
	    if(obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    	    return true;
	    else{
			alert("Invalid Email Address");
			obj.focus();
    	    return false;
		}
	}
}
// End of function

// URL Validation Function
function IsUrl(obj, msgstr){
	if(Trim(obj.value) == ""){
		alert("Link should not be blank.");
		obj.focus();
		return false;
	}
	else{
	    if(obj.value.search(/^(http|https|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/) != -1)
    	    return true;
	    else{
			alert("Invalid Link format");
			obj.focus();
    	    return false;
		}
	}
}
// End of function
function getXMLHTTP()
{
	var xmlhttp=false;	
	try
	{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)
	{		
		try
		{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			try
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1)
			{
				xmlhttp=false;
			}
		}
	}
return xmlhttp;
}
function getVideo(type)
{
	//alert(type);
	if(type == 1)
	{
		document.getElementById("vid").style.display = 'block';
		document.getElementById("vid").style.visibility = 'visible';
	}
	else
	{
		document.getElementById("vid").style.display = 'none';
		document.getElementById("vid").style.visibility = 'hidden';
	}
}

function ValidateFrontBuletinBoard()
{
	var formobj=document.bulletin;
	
	if(!IsBlank(formobj.buletincategory_id,'Please Select Buletin Category.'))
		return false;
	if(!IsBlank(formobj.buletinboard_name,'Name should not be blank.'))
		return false;
	if(!IsBlank(formobj.buletinboard_phone,'Phone should not be blank.'))
		return false;
	if(!IsEmail(formobj.buletinboard_email,'email Address should not be blank.'))
		return false;
	if(!IsBlank(formobj.buletinboard_listing,'Buletin Board Listing should not be blank.'))
		return false;
		
return true;
}

function dlt_url()
{
	if(confirm( "Are you sure you want to delete your Business?" ))
	{
		document.dltform.submit();
	}
}

