function wndOpen(URL, dname, dwidth, dheight, scrollbars, other_params)
{
	var params = 'status=no,modal=yes';
	
	if (!scrollbars) scrollbars ='yes';
	
	if (dwidth)
	{
		var leftpos = (self.screen.width / 2) - (dwidth / 2);
		params += ',width=' + dwidth+',left=' + leftpos;
	}
	
	if (dheight)
	{
		var toppos = (self.screen.height / 2) - (dheight / 2);
		params += ',height=' + dheight + ',top=' + toppos;
	}
	
	if (scrollbars)
	{
		params += ',scrollbars=' + scrollbars;
	}
	
	/*if (other_params)
	{
		params += ',' + other_params;
	}*/
	
	URL = URL.replace('http://','');
	URL = 'http://' + URL;
	
	//alert(URL);
	
	window.open(URL, dname, params);
	
	return false;
}

function forward()
{
	var pg_id = location.href;
	/*
	var i=pg_id.indexOf("?");
	if(i>0)
	{
		pg_id=pg_id.substring(0,i);
	}
	*/
	location.href="forward_friend.php?page_id="+pg_id;
}

function getstep()
{
	var step=document.form1.step.value;
	var arr=step.split(",");
	var chap_id=arr[0];
	var step_id=arr[1];
}

function AddFavorite()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		var url="http://www.the-happy-side.com";
		var title="The-Happy-Side.com";
		
		window.external.AddFavorite(url,title);
	}
	return false;
}

function MakeHomepage(obj)
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage('http://www.the-happy-side.com');
	}
	return false;
}

function check_links(obj)
{
	location.href = obj.value;
}

function feedback()
{
	var pg_id=location.href
	var i=pg_id.indexOf("?");
	if(i>0)
	{
		pg_id=pg_id.substring(0,i);
	}
	location.href="feedback.php?page_id="+pg_id+"?<?=$QUERY_STRING;?>";;
}

function news_check_name()
{
	document.news.name.value="";
}

function news_check_email()
{
	document.news.email.value="";
}

function check_email(e) 
{
	e = e||"";
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}
	}
	
	if (document.images)
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);
		}
	}
}

if ($.browser.msie) {
	document.execCommand("BackgroundImageCache",false,true);
}

//,height:"show"

$(document).ready(
	function(){
		
		$(".nav")
		.superfish({
			animation : { opacity:"show" },
			speed     : 0
		})
		.find(">li[ul]")
			.mouseover(function(){
				$("ul", this).bgIframe({opacity:false});
			})
			.find("a")
				.focus(function(){
					$("ul", $(".nav>li[ul]")).bgIframe({opacity:false});
				});
		
		
		$("#contactSubmit").click(function()
		{
			if( !$("#contactName").attr("value") || $("#contactName").attr("value").length==0 )
			{
				$("#contactError").html("Please Fill in Name");
				$("#contactError").fadeIn("fast");
				return;
			}
			if( !check_email( $("#contactEmail").attr("value") ) )
			{
				$("#contactError").html("Please Fill in Email");
				$("#contactError").fadeIn("fast");
				return;
			}
			if( !$("#contactCountry").attr("value"))
			{
				$("#contactError").html("Please Fill in Country");
				$("#contactError").fadeIn("fast");
				return;
			}
			if( !$("#contactSubject").attr("value"))
			{
				$("#contactError").html("Please Fill in Subject");
				$("#contactError").fadeIn("fast");
				return;
			}
			if( !$("#contactMessage").attr("value") || $("#contactMessage").attr("value").length==0 )
			{
				$("#contactError").html("Please Fill in Message");
				$("#contactError").fadeIn("fast");
				return;
			}
			contactSendProcess();
			return false;
		});
	}
);

function contactSendProcess()
{
	$("#contactError").css({display: "none"});
	$("#contactError").fadeOut("fast");
	$("#contactDetails").css({display: "none"});
	$("#requestProcessing").css({display: "block"});
	
	var contactSubject = $("#contactSubject").attr("value").replace('&', '__AMP__');
	var contactMessage = $("#contactMessage").attr("value").replace('&', '__AMP__');
	
	$.ajax({
		type: "POST",
		url: "contact_send_process.php",
		data: "name=" + $("#contactName").attr("value") + "&email=" + $("#contactEmail").attr("value") + "&country=" + $("#contactCountry").attr("value") + "&subject=" + contactSubject + "&message=" + contactMessage,
		success: function(msg)
			{
				$("#requestProcessing").css({display: "none"});
				$("#requestResult").css({display: "block"});
			}
		});
}
