var req;
var oldData;
var doesNotSupport = true;

url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function ListSomthing(url,arg1,arg2)
{
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest;
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (req) {
		req.open("POST",url, true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		if(arg2=='t'){
			var postvalues="";
			postvalues="area_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChange;
		}
		if(arg2=='m'){
			var postvalues="";
			postvalues="town_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChange1;
		}
		if(arg2=='ct'){
			var postvalues="";
			postvalues="area_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChange;
		}
		if(arg2=='cm'){
			var postvalues="";
			postvalues="town_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChangecm;
		}
	} else {
		alert("Please use latest version of the current browser to function properly");
		doesNotSupport = false;
	}
}
function processReqChange() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var aa=req.responseText;
			document.getElementById('town').innerHTML = aa;
			document.getElementById('town').style.display='block';
			document.getElementById('town1').style.display='none';
		}
	}
}
function processReqChange1() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var bb=req.responseText;
			var splitvar=bb.split(",");
			document.getElementById('mall').innerHTML = splitvar[1];
			document.getElementById('mall').style.display='block';
			document.getElementById('mall1').style.display='none';
		}
   }
}
function processReqChangecm() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var aa=req.responseText;
			document.getElementById('mall').innerHTML = aa;
			document.getElementById('mall').style.display='block';
			document.getElementById('mall1').style.display='none';
		}
	}
} 
function CheckGo(){
	if(document.go.key.value==""){
		alert("Please give search keyword");
		document.go.key.focus();
		return false;
	}else{
		document.go.act.value="Search";
		document.go.submit();
	}
}
//this is for checking the availability of email in user table
function check_process(email){
	if(email == ''){
		thetd='progress1';
		document.getElementById(thetd).innerHTML="Enter the Email first";
	}else{
		thetd1='progress1';
		document.getElementById(thetd1).innerHTML="&nbsp;";
		thetd='progress1';
		loading(thetd,'Please wait');
		url="check_email.php?email="+email;
		ajax_do(url);
	}
}

function loading(thediv,txt){
	document.getElementById(thediv).innerHTML="<img src=./images/loading.gif border=0>"+"<b>"+txt+"</b>";
}

function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
			url = base_url + url;
	}
	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
	//return true;
}

//this is for checking the availability of email in banner table
function check_process1(email){
	if(email == ''){
		thetd='progress1';
		document.getElementById(thetd).innerHTML="Enter the Email first";
	}else{
		thetd1='progress1';
		document.getElementById(thetd1).innerHTML="&nbsp;";
		thetd='progress1';
		loading(thetd,'Please wait');
		url="check_banner_email.php?email="+email;
		ajax_do(url);
	}
}

//--------------------------Ajax Book Mark----------------------

function BookMark(url,arg1,arg2)
{
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest;
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (req) {
		req.open("POST",url, true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		if(arg2=='s'){
			var postvalues="";
			postvalues="res_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChange2;
		}
		if(arg2=='r'){
			var postvalues="";
			postvalues="res_id="+arg1+"&type="+arg2;
			req.send(postvalues);
			req.onreadystatechange = processReqChange3;
		}
	} else {
		alert("Please use latest version of the current browser to function properly");
		doesNotSupport = false;
	}
}
function processReqChange2() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var aa=req.responseText;
			document.getElementById('start').style.display='none';
			document.getElementById('add').style.display='none';
			document.getElementById('remove').style.display='block';
		}
	}
}
function processReqChange3() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var aa=req.responseText;
			document.getElementById('start').style.display='none';
			document.getElementById('remove').style.display='none';
			document.getElementById('add').style.display='block';
		}
	}
}

function load_popup(popupfile,winheight,winwidth)
{
	window.open(popupfile,'EatOutHawaii','location=0, scrollbars=1,resizable=0,height=500,width=500');
}
function load_popup1(popupfile,winheight,winwidth)
{
	window.open(popupfile,'EatOutHawaii','location=0, scrollbars=1,resizable=1,height=1000,width=1000');
}

function go_popup(popupfile,winheight,winwidth){
	window.open(popupfile,'EatOutHawaii','location=0, scrollbars=1,resizable=1,height=700,width=600');
}
function salespage_popup(popupfile,winheight,winwidth){
	window.open(popupfile,'EatOutHawaii','location=0, scrollbars=1,resizable=1,height=700,width=740');
}
function Check_Search(){
	if(document.sea.area_id.value==""){
		alert("please select the area");
		return false;
	}else{
		document.sea.submit();
	}
}
function Check_Search1(){
	if(document.sea.town_id.value==""){
		alert("please select the town");
		return false;
	}else{
		document.sea.submit();
	}
}
function New_Photo(){
	document.getElementById("menu").style.display="none";
	document.getElementById("fle").style.display="inline";
}
function Cancel_Photo(){
	document.getElementById("menu").style.display="inline";
	document.getElementById("fle").style.display="none";
}

var text_r = "00";
var text_g = "00";
var text_b = "00";
var back_r = "00";
var back_g = "00";
var back_b = "00";
	
function colorsAll(RGB)
{
	var RR = RGB.substring(0,2);
	var GG = RGB.substring(2,4);
	var BB = RGB.substring(4,6);

	//text
	if(document.frm.color_chooser[0].checked == true)
	{
		text_r = RR; text_g = GG; text_b = BB;
		text_rgb = "" + text_r + text_g + text_b;
		document.getElementById("txtclr").value = text_rgb;
		document.getElementById("txtclr").style.color = "#" + text_rgb;
	}

	//skin
	else if(document.frm.color_chooser[1].checked == true)
	{
		back_r = RR; back_g = GG; back_b = BB;
		back_rgb = "" + back_r + back_g + back_b;
		document.getElementById("skinclr").value = back_rgb;
		document.getElementById("skinclr").style.color = "#" + back_rgb;
	}
}


function colorsOne(RGorB,XX)
{
	var colorbox_text = document.getElementById("txtclr").value;
	var colorbox_skin = document.getElementById("skinclr").value;
	//text
	if(document.frm.color_chooser[0].checked == true)
	{
		if (colorbox_text != '')
		{
			text_r = colorbox_text.substring(0,2);
			text_g = colorbox_text.substring(2,4);
			text_b = colorbox_text.substring(4,6);
		}
		if(RGorB == "R") { text_r = XX; }
		else if(RGorB == "G") { text_g = XX; }
		else if(RGorB == "B") { text_b = XX; }
		text_rgb = "" + text_r + text_g + text_b;
		document.getElementById("txtclr").value = text_rgb;
		document.getElementById("txtclr").style.color = "#" + text_rgb;
	}

	//skin
	else if(document.frm.color_chooser[1].checked == true)
	{
		if (colorbox_skin != '')
		{
			back_r = colorbox_skin.substring(0,2);
			back_g = colorbox_skin.substring(2,4);
			back_b = colorbox_skin.substring(4,6);
		}

		if(RGorB == "R") { back_r = XX; }
		else if(RGorB == "G") { back_g = XX; }
		else if(RGorB == "B") { back_b = XX; }
		back_rgb = "" + back_r + back_g + back_b;
		document.getElementById("skinclr").value = back_rgb;
		document.getElementById("skinclr").style.color = "#" + back_rgb;
	}
}


var ratingValue = new Array();
ratingValue[0] = 'Not good';
ratingValue[1] = 'Average';
ratingValue[2] = 'Good';
ratingValue[3] = 'Great';
ratingValue[4] = 'Awesome';

/**
 ** when mouse over on star at blog page
 **/
function blog_rating_mouseover(rating) {
	$j('#blog_current_rating').css('width', '0px');
	$j('#ratingResult').html(ratingValue[rating-1]);
}

/**
 ** when mouse out on star at blog page
 **/
function blog_rating_mouseout(width, allrating) {
	$j('#blog_current_rating').css('width', width + 'px');
	$j('#ratingResult').html(allrating + ' ratings');
}

/**
 ** rate blog at blog page
 **/
function blog_checkrating(rating) {
	$j('#blog_current_rating').css('width', (18 * parseInt(rating)) + 'px');
	$j("#ratingResult").html("<img src='images/ajaxloader.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "blograting=true&blog_id=" + $j('#blog_id').val() + "&rating=" + rating,
		success: function(data){
			if (data != 'You already rated.' && data != 'failure') {
				$j("div#blogRating").html(data);
			} else {
				$j("div#ratingResult").html(data);
			}
		}
	});
}

/**
 ** show blog filter list
 **/
function show_blog_filter() {
    blog_box_flag = 2;

	if($j.browser.msie){
		var left = $j("#filter_arrow").offset().left - 180;
		var top = $j("#filter_arrow").offset().top + 17;
	} else {
		var left = $j("#filter_arrow").offset().left - 180;
		var top = $j("#filter_arrow").offset().top + 22;
	}

	$j("#search_filter_select").css("left", left + "px");
	$j("#search_filter_select").css("top", top + "px");
	$j("#search_filter_select").fadeIn('slow');

	$j("#inner_search_filter").css("left", (left + 10) + "px");
	$j("#inner_search_filter").css("top", (top + 10) + "px");
	$j("#inner_search_filter").fadeIn('slow');
}

function set_show_blog_box() {
    blog_box_flag = 2;
}

/**
 ** hide blog filter list
 **/
function hide_blog_filter() {
    if (blog_box_flag == 1) {
		$j("#search_filter_select").fadeOut('slow');
		$j("#inner_search_filter").fadeOut('slow');
	} else if (blog_box_flag == 2) {
		blog_box_flag = 1;
	}
}

/**
 ** show blog filter list
 **/
function home_show_blog_filter() {
    home_blog_box_flag = 2;

	if($j.browser.msie){
		var left = $j("#home_filter_arrow").offset().left - 180;
		var top = $j("#home_filter_arrow").offset().top + 17;
	} else {
		var left = $j("#home_filter_arrow").offset().left - 180;
		var top = $j("#home_filter_arrow").offset().top + 22;
	}

	$j("#home_search_filter_select").css("left", left + "px");
	$j("#home_search_filter_select").css("top", top + "px");
	$j("#home_search_filter_select").fadeIn('slow');

	$j("#home_inner_search_filter").css("left", (left + 10) + "px");
	$j("#home_inner_search_filter").css("top", (top + 10) + "px");
	$j("#home_inner_search_filter").fadeIn('slow');
}

function home_set_show_blog_box() {
    home_blog_box_flag = 2;
}

/**
 ** hide blog filter list
 **/
function home_hide_blog_filter() {
    if (home_blog_box_flag == 1) {
		$j("#home_search_filter_select").fadeOut('slow');
		$j("#home_inner_search_filter").fadeOut('slow');
	} else if (home_blog_box_flag == 2) {
		home_blog_box_flag = 1;
	}
}

function search_blog(obj, filter, filter_id) {
	var selected = obj.innerHTML;
	$j("#blog_search_result").html("<img src='images/ajaxbar.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "blogsearch=true&filter=" + filter + "&filter_id=" + filter_id,
		success: function(data){
			home_hide_blog_filter();
			$j('#blog_selected_item').html(selected);
			$j('#blog_search_result').html('');
			$j('#home_blog_list').html(data);
		}
	});
}

function top_blog_page() {
	document.location.href = 'index.php?type=blog&pg=' + $j('#top_pg').val() + '#home_blog_table';
}

function bottom_blog_page() {
	document.location.href = 'index.php?type=blog&pg=' + $j('#bottom_pg').val() + '#home_blog_table';
}

/**
 ** vote to restaurant
 **/
function vote_restaurant(vote) {
	$j("#vote_restaurant_result").html("<img src='images/ajaxloader.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "vote_restaurant=true&res_id=" + $j('#res_id').val() + "&vote=" + vote,
		success: function(data){
			$j("#vote_restaurant_result").html("");
			$j("#vote_restaurant_board").html(data);
		}
	});
}

/**
 ** show video filter list
 **/
function show_video_filter() {
    video_box_flag = 2;

	if($j.browser.msie){
		var left = $j("#video_filter_arrow").offset().left - 180;
		var top = $j("#video_filter_arrow").offset().top + 20;
	} else {
		var left = $j("#video_filter_arrow").offset().left - 180;
		var top = $j("#video_filter_arrow").offset().top + 22;
	}

	$j("#video_search_filter").css("left", left + "px");
	$j("#video_search_filter").css("top", top + "px");
	$j("#video_search_filter").fadeIn('slow');

	$j("#inner_video_search_filter").css("left", (left + 10) + "px");
	$j("#inner_video_search_filter").css("top", (top + 10) + "px");
	$j("#inner_video_search_filter").fadeIn('slow');
}

function set_show_video_box() {
    video_box_flag = 2;
}

/**
 ** hide blog filter list
 **/
function hide_video_filter() {
    if (video_box_flag == 1) {
		$j("#video_search_filter").fadeOut('slow');
		$j("#inner_video_search_filter").fadeOut('slow');
	} else if (video_box_flag == 2) {
		video_box_flag = 1;
	}
}

function search_video(obj, filter, filter_id) {
	var selected = obj.innerHTML;
	$j("#video_search_result").html("<img src='images/ajaxbar.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "videosearch=true&filter=" + filter + "&filter_id=" + filter_id,
		success: function(data){
			var dataArr = data.split("***");
			var count = dataArr[1];
			if (count <= 5) {
				$j("#video_field").css("height", "220px");
				$j("#restaurant_video").css("height", "210px");
				$j("#restaurant_video_list").css("height", "166px");
				$j("#inner_video_list").css("height", "155px");
			} else if (count >= 5 && count <= 10) {
				$j("#video_field").css("height", "360px");
				$j("#restaurant_video").css("height", "355px");
				$j("#restaurant_video_list").css("height", "311px");
				$j("#inner_video_list").css("height", "300px");
			} else {
				$j("#video_field").css("height", "530px");
				$j("#restaurant_video").css("height", "510px");
				$j("#restaurant_video_list").css("height", "466px");
				$j("#inner_video_list").css("height", "455px");
			}
			
			hide_video_filter();
			//$j(".round").corner("9px");
			$j("#video_selected_item").html(selected);
			$j("#video_search_result").html("");
			$j("#inner_video_list").html(dataArr[0]);
		}
	});
}

/* common functions */
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function writeCookie()
{
	var today = new Date();
	var the_date = new Date("December 31, 2023");
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = "users_resolution="+ screen.width +"-"+ screen.height;
	var the_cookie = the_cookie + ";expires=" + the_cookie_date;
	document.cookie = the_cookie;
}
function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	
	if(whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while ( j < i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
		s  = s.substring(j,i);
	}
	return s;
}
function RTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if(whitespace.indexOf(s.charAt(s.length -1)) != -1) {
		var i = s.length - 1;
		while( i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		    i--;
		s = s.substring(0, i+1);
	}
	return s;
}
function Trim(str){
	return RTrim(LTrim(str));
}

function echeck(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if(str.indexOf(at) == -1){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.indexOf(at,(lat+1)) != -1){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.indexOf(dot,(lat+2)) == -1){
		alert("Invalid Email Id.");
		return false;
	}
	if(str.indexOf(" ") != -1){
		alert("Invalid Email Id.");
		return false;
	}
	return true;
}

/**
 ** View sent mail this week
 **/
function view_sent_mail(res_id, fraid) {
	$j("#view_sent_mail_result").html("<img src='images/ajaxloader.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "view_sent_mail=true&res_id=" + res_id + "&fraid=" + fraid,
		success: function(data){
			$j("#view_sent_mail_result").html("");
			$j("#view_sent_mail_board").html(data);
		}
	});
}

/**
 ** View total created coupons
 **/
function view_created_coupons(res_id, fraid) {
	$j("#view_created_coupons_result").html("<img src='images/ajaxloader.gif' alt='' />");
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "view_created_coupons=true&res_id=" + res_id + "&fraid=" + fraid,
		success: function(data){
			$j("#view_created_coupons_result").html("");
			$j("#view_created_coupons_board").html(data);
		}
	});
}

/**
 ** check valid integer value
 **/
function check_valid_number(val) {
	if (val == '') {
		return false;
	} else {
		if (!isNaN(val)) {
			if (parseInt(val) < 1 ) {
				return false;
			}
		} else {
			return false;
		}
	}
	return true;
}

/*--------------- advanced menu ------------------*/
/**
 ** when mouse over on star at rating star
 **/
function menu_rating_mouseover(rating, item_id) {
	$j('#menu_current_rating_' + item_id).css('width', '0px');
}

/**
 ** when mouse out on star at rating star
 **/
function menu_rating_mouseout(item_id) {
	$j('#menu_current_rating_' + item_id).css('width', $j('#rating_width_' + item_id).val() + 'px');
}

/**
 ** rate menu at restaurant page
 **/
function menu_checkrating(rating, item_id) {
	$j('#menu_current_rating_' + item_id).css('width', (18 * parseInt(rating)) + 'px');
	$j('#menu_ratingResult_' + item_id).html('<img src="images/ajaxloader.gif" alt="" />');
	$j.ajax({
		type: "POST",
		url: "ajaxprocess.php",
		data: "menurating=true&item_id=" + item_id + "&rating=" + rating,
		success: function(data){
			$j('#menu_ratingResult_' + item_id).html('');
			$j('#rating_width_' + item_id).val(data);
			$j('#menu_current_rating_' + item_id).css('width', data + 'px');
		}
	});
}
