function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function show_neighbor(cate_id, city_id) //path
{
	$("#primary .cat-item a").css("color","#00478C");
	$("#primary #category_"+cate_id+ " a").css("color","#FF0000");
	if(getCookie('music') == null || getCookie('music') == 'on'){
		$("#music").html('<object width="1" height="1" type="application/x-shockwave-flash" id="play-music" name="play-music" data="http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/players/player.swf"><param name="wmode" value="transparent"><param name="allowfullscreen" value="false"><param name="allowscriptaccess" value="always"><param name="allownetworking" value="all"><param name="flashvars" value="width=120&amp;height=45&amp;autostart=true&amp;repeat=false&amp;backcolor=111111&amp;frontcolor=cccccc&amp;lightcolor=66cc00&amp;stretching=fill&amp;enablejs=true&amp;mute=false&amp;skin=http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/players/skins/default.swf&amp;plugins=&amp;javascriptid=10852pp-single-4eb7c0ec31872&amp;file=http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/playlist-controller.php?pp_playlist_id=10852pp-single-4eb7c0ec31872&amp;sid=1320665324">');
	}
	
	
	var xmlhttp, params, path;
	path = "../get_neighborhood.php";
	params = 'cate_id='+cate_id+'&city_code='+city_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		//alert($("#secondary ul li .textwidget").is()=='');
		
		var text = trim(xmlhttp.responseText);
		
		if(text <= 0 && text.length<10)
		{
			
			$("#container .post_head").text('');
			$("#container #content .post_content").html(xmlhttp.responseText);
	}
	
	$("#secondary ul li .textwidget").html(xmlhttp.responseText);	
	
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}

function show_post(neighborhood_id, cate_id, neighborhood_name, city_id) //path
{
	$("#secondary .cat-item a").css("color","#00478C");
	$("#secondary #neighbor_"+neighborhood_id+" a").css("color","#FF0000");
	
	if(getCookie('music') == null || getCookie('music') == 'on'){
		$("#music").html('<object width="1" height="1" type="application/x-shockwave-flash" id="play-music" name="play-music" data="http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/players/player.swf"><param name="wmode" value="transparent"><param name="allowfullscreen" value="false"><param name="allowscriptaccess" value="always"><param name="allownetworking" value="all"><param name="flashvars" value="width=120&amp;height=45&amp;autostart=true&amp;repeat=false&amp;backcolor=111111&amp;frontcolor=cccccc&amp;lightcolor=66cc00&amp;stretching=fill&amp;enablejs=true&amp;mute=false&amp;skin=http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/players/skins/default.swf&amp;plugins=&amp;javascriptid=10852pp-single-4eb7c0ec31872&amp;file=http://wonderdads.rave-staging.net/wp-content/plugins/proplayer/playlist-controller.php?pp_playlist_id=10852pp-single-4eb7c0ec31872&amp;sid=1320665324">');
	}
	
	var xmlhttp, params, path;
	path = "../get_post.php";
	params = 'neighborhood_id='+neighborhood_id+'&category_id='+cate_id+'&city_code='+city_id;
	neighborhood_name = neighborhood_name.replace(/_/g,' ');
	neighborhood_name = neighborhood_name.replace(/%/g,"'");
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	$("#container .post_head").text(neighborhood_name);
	$("#container #content .post_content").html(xmlhttp.responseText);
	
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}


function share_post(post_id) //path
{
var xmlhttp, params, path;
path = "../share_post.php";
params = 'post_id='+post_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		/*pos1 = strpos(xmlhttp.responseText,'content_description',0);
		content = xmlhttp.responseText.substr($pos1+24,100);
		content = str_replace('&lt;','',$content);
		content = str_replace('&gt;','',$content);
		content = str_replace('/div','',$content);
		content = str_replace('hr /','',$content);*/
 
		window.open(xmlhttp.responseText,'_blank'); //http://www.facebook.com/sharer/sharer.php?s=100&p[title]=<?php echo urlencode('GiftsFromGrandpa.com - Send Monthly, Birthday or One-Time Gifts to Your Grandkids!'); ?>&p[summary]=<?php echo urlencode($content);?>&p[url]=http://<?php echo $_SERVER['HTTP_HOST'];?>" target="_blank"
		
		
		//BookMarkOnFaceBook(xmlhttp.responseText);
		
		
		
		
	//$("#container .post_head").text(neighborhood_name);
	//$("#container #content .post_content").html(xmlhttp.responseText);
	//alert('http://www.facebook.com/sharer.php?u=http//wonderdads.com&t='+xmlhttp.responseText);
	//window.open('http://www.facebook.com/sharer.php?t=tESTING');
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}

function share_event(event_id) //path
{
var xmlhttp, params, path;
path = "../share_event.php";
params = 'event_id='+event_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		/*pos1 = strpos(xmlhttp.responseText,'content_description',0);
		content = xmlhttp.responseText.substr($pos1+24,100);
		content = str_replace('&lt;','',$content);
		content = str_replace('&gt;','',$content);
		content = str_replace('/div','',$content);
		content = str_replace('hr /','',$content);*/
 
		window.open(xmlhttp.responseText,'_blank');
		
		//BookMarkOnFaceBook(xmlhttp.responseText);
		
	//$("#container .post_head").text(neighborhood_name);
	//$("#container #content .post_content").html(xmlhttp.responseText);
	//alert('http://www.facebook.com/sharer.php?u=http//wonderdads.com&t='+xmlhttp.responseText);
	//window.open('http://www.facebook.com/sharer.php?t=tESTING');
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}

function share_page(city_name, api_key) //path
{
	
	content = 'The Best Dad/Child Activities in '+city_name+ ' - Check Out WonderDads at '+document.location.href;
	url = 'http://www.facebook.com/sharer/sharer.php?s=100&p[title]=The Best Dad/Child Activities&p[summary]='+content+'&p[url]='+document.location.href;
	window.open(url,'_blank');
	//content = 'The Best Dad/Child Activities in '+city_name+ ' - Check Out WonderDads at '+document.location.href;
	//content += '|||'+api_key;
	//BookMarkOnFaceBook(content);
}

function share_article(post_id) //path
{
var xmlhttp, params, path;
path = "../share_article.php";
params = 'post_id='+post_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		window.open(xmlhttp.responseText,'_blank');
		//BookMarkOnFaceBook(xmlhttp.responseText);
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}

function count() //path
{
var xmlhttp, params, path;
path = "../count.php";
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
 
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.send();
}


function show_page(city_id, URL, index,$twincityindex,$triangleallindex){
	
		var city_name = $(".city_content_Main li:eq("+(index-1)+")").text();
		
		
		city_name = city_name.toLowerCase();
		city_name = city_name.replace(' ','-');
		city_name = city_name.replace(' ','-');
		if(city_id==24||city_id==35)
		{
			city_name = $(".city_content_Main li:eq("+($twincityindex-1)+")").text();//37 is twin city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-');
			window.open(URL+'/'+city_name,'_self');
			}
		else if(city_id==14||city_id==8 ||city_id==30)
		{
			city_name = $(".city_content_Main li:eq("+($triangleallindex-1)+")").text();// 39 is triangale city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-');
			window.open(URL+'/'+city_name,'_self');
			
			}
		else
			window.open(URL+'/'+city_name,'_self');
		
}

function show_page1(city_id, URL, index,$twincityindex,$triangleallindex){
	
		var city_name = $(".cityCover li a:eq("+(index-1)+") span").text();
		
		
		city_name = city_name.toLowerCase();
		city_name = city_name.replace(' ','-');
		city_name = city_name.replace(' ','-');
		if(city_id==24||city_id==35)
		{
			city_name = $(".cityCover li a:eq("+($twincityindex-1)+") span").text();//37 is twin city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-');
			city_name = city_name+'-activities';
			window.open(URL+'/'+city_name,'_self');
			}
		else if(city_id==14||city_id==8 ||city_id==30)
		{
			city_name = $(".cityCover li a:eq("+($triangleallindex-1)+") span").text();// 39 is triangale city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-');
			city_name = city_name+'-activities';
			window.open(URL+'/'+city_name,'_self');
			
			}
		else{
			city_name = city_name+'-activities';
			window.open(URL+'/'+city_name,'_self');
		}
}
		


function show_activity(URL, index,$twincityindex,$triangleallindex,city_id){
	
	
			var city_name = $(".story_content li:eq("+(index-1)+")").text();
		
		
		city_name = city_name.toLowerCase();
		city_name = city_name.replace(' ','-');
		city_name = city_name.replace(' ','-') + '-activities';
		if(city_id==24||city_id==35)
		{
			city_name = $(".story_content li:eq("+($twincityindex-1)+")").text();//37 is twin city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-') + '-activities';
			window.open(URL+'/'+city_name,'_self');
			}
		else if(city_id==14||city_id==8 ||city_id==30)
		{
			city_name = $(".story_content li:eq("+($triangleallindex-1)+")").text();//40 is triangale city id 
			city_name = city_name.toLowerCase();
			city_name = city_name.replace(' ','-');
			city_name = city_name.replace(' ','-') + '-activities';
			window.open(URL+'/'+city_name,'_self');
			
			}
		else
			window.open(URL+'/'+city_name,'_self');
	}

function mouse_move(index){
	$(".city_content_Main li:eq("+(index-1)+")").css('cursor','pointer');
}

function mouse_move1(index){
	$(".story_content li:eq("+(index-1)+")").css('cursor','pointer');
}

function show_book(city_id, URL, index){
		var city_name = $(".story_content li:eq("+(index-1)+")").text();
		city_name = city_name.toLowerCase();
		city_name = city_name.replace(' ','-');
		city_name = city_name.replace(' ','-');
		city_name = city_name + '-book';
		window.open(URL+'/'+city_name,'_self');
}

function mouse_move_book(index){
	$(".story_content li:eq("+(index-1)+")").css('cursor','pointer');
}

function send_email(email_id, city_name, event_id) //path
{
	var xmlhttp, params, path;
	if(email_id == ''){
		return false;	
	}
	path = "../send_email.php";
	params = 'to_email='+$("#to_email").val()+'&name='+$("#name").val()+'&email='+$("#email").val()+'&phone='+$("#phone").val()+'&kids='+$("#kids").val();
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		alert(xmlhttp.responseText);
		disablePopup();
		//$("#ajax-loading").css("display","none");
		//$().message("Email has been send to Admin successfully.");
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}

function validateEmail(){
			//testing regular expression
	var a = document.getElementById('email').value;
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	//if it's valid email
	if(filter.test(a)){
		return true;
	}
	else{
		return false;
	}
}

function email_purchase_order(){
	var xmlhttp, params, path;
	if(trim($("#name").val()) == ''){
		alert('Please enter Your Name');
		return false;
	}
	if(!validateEmail($("#email").val())){
		alert('Please enter Valid Email Address');
		return false;
	}
	
	if(trim($("#email").val()) == ''){
		alert('Please enter Your Email Address');
		return false;
	}
	
	path = "../po_email1.php";
	params = 'to_email='+$("#to_email").val()+'&name='+$("#name").val()+'&store='+$("#store").val()+'&email='+$("#email").val()+'&phone='+$("#phone").val()+'&s_address='+$("#s_address").val()+'&b_address='+$("#b_address").val()+'&ref_number='+$("#ref_number").val()+'&qty_city_book='+$("#qty_city_book").val()+'&qty_gn_book='+$("#qty_gn_book").val()+'&qty_abc_book='+$("#qty_abc_book").val()+'&qty_baseball_book='+$("#qty_baseball_book").val()+'&qty_golf_book='+$("#qty_golf_book").val()+'&qty_fishing_book='+$("#qty_fishing_book").val()+'&comment='+$("#comment").val();
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
  	}
	else
	{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
		//alert($("#secondary ul li .textwidget").is()=='');
		alert(xmlhttp.responseText);
		return false;
		}
	}
	xmlhttp.open("POST",path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}

function send_article_email(post_id) //path
{
	var xmlhttp, params, path;
	if($("#article_email").val() == '' || $("#article_email").val() == 'Your Email'){
		alert("Please enter Email address");
		return false;	
	}
	path = "../send_article_email.php";
	params = 'email='+$("#article_email").val()+'&post_id='+post_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		alert(xmlhttp.responseText);
    }
  }
xmlhttp.open("POST",path,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}


function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+exdays);
	var c_value=escape(value) + "; expires="+exdate.toUTCString();
	document.cookie=c_name + "=" + c_value;
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
    }
    return null;
}

function set_music_on_off(){
	if(getCookie('music') == null || getCookie('music') == 'on'){
		setCookie('music','off',365*10);
		$("#music-container p").text("Music Off");
		src = $("#music-container img").attr("src");
		src = src.replace('on.png','off.png');
		$("#music-container img").attr("src",src);
	}else{
		setCookie('music','on',365*10);
		$("#music-container p").text("Music On");
		src = $("#music-container img").attr("src");
		src = src.replace('off.png','on.png');
		$("#music-container img").attr("src",src);
	}
}





var el;
function BookMarkOnFaceBook(content) {
	content = content.split('|||');
var strURL = "../facebook.php?content="+content[0]+'&api='+content[1]; //"../facebook.php?content=aliakbar";
//alert("asdsad");
el = document.getElementById('ifrm');
el.style.visibility = "visible";
el.src = strURL;

//window.open("http://wonderdads.com/facebook.php?content=aliakbar");

/*
var e = window.event;
if (e)
e.cancelBubble = true;
*/

/*if (evt)
evt.stopPropagation();*/

//if(el==null)
// el = document.createElement("iframe");

/*el.setAttribute('id', 'ifrm');
document.body.appendChild(el);
el.setAttribute('src', strURL);
el.setAttribute('height', '450px');
el.setAttribute('width', '550px');
el.setAttribute('scrolling', 'no');
el.setAttribute('frameborder', '0');
el.setAttribute('style', 'top:80px;left:40px;position:absolute;display:block;');*/

}



//http://www.facebook.com/sharer.php?t=['.$post_content.']
/*		var exdate=new Date();
		exdate.setDate(exdate.getDate() + 1);
		var c_value=escape(city_id) + "; expires="+exdate.toUTCString();
		document.cookie='other_city_code' + "=" + c_value;
		c_value=escape(city_name) + "; expires="+exdate.toUTCString();
		document.cookie='other_city_name' + "=" + c_value;*/
