/*$(document).bind("contextmenu",function(e){  
//you can enter your code here, e.g a menu list  
alert('To avoid copyright infridgement \n Right clicking has been disable for this site.')
//cancel the default context menu  
return false;  
}); */

//--------------Functions---------------//

function imgSelect(index){
	$("#bgChangerBox div img").css("border" , "none");
	$("#bgChangerBox div img").eq(index-1).css("border" , "outset 5px #F00");
}
//---BackGround Switcher
function bgswitch(bg){
			$("body").css("background" , "url('/images/background"+bg+".jpg') top center fixed no-repeat");
			$.cookie('background', bg, { expires: 400, path: '/' });
}

//User Validation Forms
function validate(){
	var user = $("#username").text();
	if(user == "Guess" || user == "demo" || user == null || user == "" || user == "undefined"){
		return false;
	}else{
		return true;
	}
}

function getUsername(){
	if(validate() == true){
		var user = $("#username").text();
		return user;
	}else{
		var user = "Guess"
		return user;
	}
}
function getEmail(){
	if(validate() == true){
		var email = $("#userEmail").val();
		return email;
	}else{
		return false;
	}
}

//popup
function popup(url,title,w,h,sc) {
	if(sc != null ){ sc = "yes"; };
	
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no, copyhistory=no, scrollbars='+sc+', dialog=yes, width='+w+', height='+h+', top='+top+', left='+left);

}

//News Letter Subscription Form
function subscribe(){
	var email = $("#NewsletterBox .userEmail").val();
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(reg.test(email) == true){
		$.get("includes/comments/track.php",{
			mode: "add",
			name: getUsername(),
			email: email,
			thread_id: 10
		},function(data){
			$.fn.colorbox.close();
			if(data != ""){
				alert('You are already Subscribed to the TheChozenFew Newsletters with '+data);
			}
		});

		//
	}else{
		alert('Invalid Email Address \nPlease Enter a Valid Email address');
	}
}

function unsubscribe(){
	var email = $(".userEmail").val();
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(reg.test(email) == true){
		$.get("/includes/comments/track.php",{
			mode: "rem",
			name: "no",
			email: email,
			thread_id: 10
		},function(data){
			alert('Done! \nThank You!');
			location.href='/';
		});

		//
	}else{
		alert('Invalid Email Address \nPlease Enter a Valid Email address');
	}
}

//Colorbox General PopUp Box
function popBox(Title,Body,sizeW){
	//Optional Variables
	if(!sizeW){ var sizeW = "500px";}
	//-------------------------
	if( typeof(Title) == 'object'){Title = $(Title).text(); }
	Body = $(Body).html();
	var titleC = $("#PopUp .popupTitle");
	var bodyC = $("#PopUp .popupBody");
	
	$(titleC).text(Title);
	$(bodyC).html(Body);
	$.fn.colorbox({inline: true, opacity: 0.8,  open: true, width: sizeW, href:"#PopUp"});
}
//-----BackGrounds---------------------------------------------------------	
function loadBgBox(x){
	var bgCount = x ;						  		
	var bg = $("#backgrounds-list");				   	
	var pic = 1;
	
	//  Pobulate widget
	do {
		var code =  "<img src='images/background"+pic+".jpg' onclick='bgswitch("+pic+"); imgSelect("+pic+");' > ";		
		bg.append(code);							   
		pic++;
	}
	while (pic <= bgCount)
	imgSelect($.cookie('background'));
}
//---------------End Functions-------------------//
//-------------jQuery Functions -----------------//
jQuery(function($) {
	$('p.links').clickUrl();
	$('p.strip').stripTags();
	$('p.escape').escapeHtml();
});
 
(function($) {
 
$.fn.clickUrl = function() {
	var regexp = new RegExp("((http|https)(:\/\/))?([a-zA-Z0-9]+[.]{1}){2}[a-zA-z0-9]+(\/{1}[a-zA-Z0-9]+)*\/?", "i");
	this.each(function() {
		$(this).html(
			$(this).html().replace(regexp,"<a href=\"$1\">$1</a>")
		);
	});
	return $(this);
}
 
$.fn.stripTags = function() {
	var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
	this.each(function() {
		$(this).html(
			$(this).html().replace(regexp,"")
		);
	});
	return $(this);
}
 
$.fn.escapeHtml = function() {
	this.each(function() {
		$(this).html(
			$(this).html()
				.replace(/&/g,'&amp;')
				.replace(/</g,'&lt;')
				.replace(/>/g,'&gt;')
				.replace(/"/g,'&quot;')
		);
	});
	return $(this);
}
 
})(jQuery);
 //----------------------------------------------------//