$(function()
{
    	$('.fg-button').hover(
    		function(){ $(this).removeClass('ui-state-default').addClass('ui-state-focus'); },
    		function(){ $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }
    	);
	$('#flat').menu({
		content: $('#flat').next().html(), // grab content from this page
		showSpeed: 400 
	});
	
});
function selectcity_onclick()
{
	var errstr='';
	if($("#cmbcities_id").val()=='')
	{
		errstr=errstr+"Select city\n";
	}
	if($("#txtemail_dlg").val()!='')
	{
		if(!echeck($("#txtemail_dlg").val()))
		{
			errstr=errstr+"Enter a valid email address\n";
		}
	}
	if(errstr!='')
	{
		alert(errstr);
		return false;
	}
	else
	{
		if($("#txtemail_dlg").val()!='')
		{
			$("#divloading").show('fast');
			murl=window.location.protocol+"//"+window.location.host+"/saveuseremail.php";
			$.ajax(
			{
				type:"POST",
				url:murl,
				data:"txtemail_dlg="+$("#txtemail_dlg").val(),
				success:function(retData)
				{
					Set_Cookie('cities_id',$("#cmbcities_id").val(),'1000', '/', '','');
					$("#divloading").hide();
					$('#dialog-box').hide();
					//window.location.reload();
					window.location.href="http://www.7jades.com";
				},
				failure:function()
				{
					alert("Action failed!\nPlease retry.");
				}
			});
		}
		else
		{
			Set_Cookie('cities_id',$("#cmbcities_id").val(),'1000', '/', '','');
			$('#dialog-box').hide();
			//window.location.reload();
			window.location.href="http://www.7jades.com";
		}
	}
}
function selectcity_onclick1()
{
	var errstr='';
	if($("#cmbcities_id_h").val()=='')
	{
		errstr=errstr+"Select city\n";
	}
	if(errstr!='')
	{
		alert(errstr);
		return false;
	}
	else
	{
		Set_Cookie('cities_id',$("#cmbcities_id_h").val(),'1000', '/', '','');
		window.location.href="http://www.7jades.com";
	}
}
/*
function selectcity_onclick1(item)
{
	Set_Cookie('cities_id',$(item).attr('href'),'1000', '/', '','');
	window.location.href="http://www.7jades.com";
}
*/
function popup(message,forced_open) {
	//alert($(window).height());
	// get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();
	// calculate the values for center alignment
	var dialogTop =  ($(window).height()/2) - ($('#dialog-box').height()/2);
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	
	// display the message
	//$('#dialog-message').html(message);
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
	
	return false;
	
}			
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		var c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			var c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1)
				c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
function checkCookie(c_name)
{
	//Delete_Cookie(c_name,'/','')
	if(!getCookie(c_name))
	{
		popup('','');
		//Set_Cookie(c_name,'Pune','1000', '/', '','');
		//alert("Cookie not set");
	}
	else
	{
		//Delete_Cookie(c_name,'/','');
		
		//Delete_Cookie(c_name,'/','');
	}
	
}

function Set_Cookie(c_name,c_value,expires, path, domain, secure )
{
	// set time, it's in milliseconds
	//domain = 'www.7jades.com';
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('setting cookie value to '+c_name+'='+c_value);
	document.cookie = c_name + "=" +escape(c_value) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
function Delete_Cookie( name, path, domain )
{
	if ( getCookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
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)
	{
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		alert("Invalid E-mail ID")
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false
	}
	if (str.indexOf(" ")!=-1)
	{
		return false
	}
	return true					
}
