pagechanged = function (url, ctid, page) {

//	alert (url + 'page=' + page + '&ctid=' + ctid);

	open (url + 'page=' + page + '&ctid=' + ctid, "_self");

}


function charsNotAllowed(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e) 
	   key = e.which;
	else
	   return true;

	keychar = String.fromCharCode(key);

	// control keys 
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;
	// numbers
	else if ((("~!#$%^&*()+{}|:\"<>?`=[]\\;',/").indexOf(keychar) > -1))
	   return false;
	// decimal point jump
	else
	   return true;
}


function numbersonly(myfield, e, dec) {

	var key;

	var keychar;



	if (window.event)

	   key = window.event.keyCode;

	else if (e)

	   key = e.which;

	else

	   return true;

	keychar = String.fromCharCode(key);

	

	// control keys

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )

	   return true;

	

	// numbers

	else if ((("0123456789").indexOf(keychar) > -1))

	   return true;

	

	// decimal point jump

	else if (dec && (keychar == "."))

	   {

	   myfield.form.elements[dec].focus();

	   return false;

	   }

	else

	   return false;

}



function popup(mypage,myname){

	var infocus = 'front';

	var pos = 'center';

	var h = 300;

	var w = 700;

	var popupWindow=null;

	if (pos == 'random')

		{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}

	else

		{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}

		settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';popupWindow=window.open('',myname,settings);

		if(infocus=='front'){popupWindow.focus();popupWindow.location=mypage;}

		if(infocus=='back'){popupWindow.blur();popupWindow.location=mypage;popupWindow.blur();}

}



// Pass in a query string variable and it returns the value. 

function queryString(keyName) { 

    var keyValue = "";

    keyName = keyName.toUpperCase() + "="; 

//alert (keyName);

    var queryString = location.search;

    if (location.search.indexOf("?") != -1) { 

        queryString = location.search.substring(1, queryString.length); 

        var searchString = queryString.toUpperCase(); 

        if (searchString.indexOf(keyName) != -1) { 

            var keyValueStart = parseInt(searchString.indexOf(keyName)) + keyName.length; 

            var keyValueEnd = searchString.indexOf("&", keyValueStart); 

            var keyValueEnd = (keyValueEnd != -1) ? keyValueEnd : searchString.length; 

            keyValue = queryString.substring(keyValueStart,keyValueEnd); 

        }



        var plusPos = keyValue.indexOf('+');

        while (plusPos != -1) {

            keyValue = keyValue.substring(0, plusPos) + " " + keyValue.substring(plusPos + 1, keyValue.length);

            plusPos = keyValue.indexOf('+');

        }

    } 



    return unescape(keyValue); 

} 



function checkemail(str){



	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	if (filter.test(str))

		testresults=true

	else{

		testresults=false

	}

	return (testresults)

}

function checkURL(){

	retVal = false;

	if (myzinesform.zineURL.value) {

		retVal = true; 

	} else {

		alert ("Please enter URL");

	}

	return retVal;

}



function checkpw(str){

	retVal = false;

	if (str) {

		retVal = true;

	}

	return retVal;

}

function verify_emailaddr(username, password, whichscreen) {

	retVal = true;

	if (!checkpw(password) || !checkemail(username)) {

		if (whichscreen == 'loginpopup') {

			jQuery("div.loginbx p.error").fadeIn();

		} else  {

			jQuery("div#hc_loginbox p.error").fadeIn();

		}	

		retVal = false;

	}	

	return retVal;

}



function isLoggedIn() {

	var cookie_name="screenname";

	var nameEQ = cookie_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 true;

	}

	return false;

}



function chkRegFrm1() {


	retval=true;



	$('p#error1').hide();

	$('p#error2').hide();

	$('p#error3').hide();

	$('p#error4').hide();

	$('p#error5').hide();

	$('p#error6').hide();

	$('p#error7').hide();

	$('p#error8').hide();

	$('p#error9').hide();

	if(!checkemail(document.forms.registrationform.email.value)) {

		$('p#error9').show();

		retval=false;

	}



	if(document.forms.registrationform.username.value == "") {

		$('p#error1').show();

		retval=false;

	}



	if((document.forms.registrationform.email.value == "") || (document.forms.registrationform.email.value != document.forms.registrationform.confirmemail.value)) {

		$('p#error2').show();

		retval=false;

	}

	

	if((document.forms.registrationform.password.value == "") || (document.forms.registrationform.password.value != document.forms.registrationform.retypepassword.value)) {

		$('p#error3').show();

		retval=false;

	}



	if(document.forms.registrationform.verifytext.value == "") {

		$('p#error4').show();

		retval=false;

	}



	if(!document.forms.registrationform.terms.checked) {

		$('p#error5').show();

		retval=false;

	}

	

	if (!retval) {

		document.forms.searchfrm.search_keyword.focus();

	}

	return retval;

}



function chkRegEditFrm1() {

	retval=true;



	$('p#error1').hide();

	$('p#error2').hide();

	$('p#error3').hide();

	$('p#error4').hide();

	$('p#error5').hide();

	$('p#error6').hide();

	$('p#error7').hide();

	$('p#error8').hide();

	$('p#error9').hide();



//alert ("check email");

	if(!checkemail(document.forms.regFrm.emailaddr.value)) {

		$('p#error9').show();

//alert ("in check email");

		retval=false;

	}

	

//alert ("check screen");

	if(document.forms.regFrm.screenname.value == "") {

		$('p#error1').show();

//alert ("check screen");

		retval=false;

	}



//alert ("check email match");

//alert (document.forms.regFrm.emailaddr.value);

//alert (document.forms.regFrm.emailaddr2.value);

	   if((document.forms.regFrm.emailaddr.value == "") || (document.forms.regFrm.emailaddr.value != document.forms.regFrm.emailaddr2.value)) {

		$('p#error2').show();

//alert ("in check email match");

		retval=false;

	}

	

//alert ("check password match");

	if((document.forms.regFrm.password.value == "") || (document.forms.regFrm.password.value != document.forms.regFrm.password2.value)) {

		$('p#error3').show();

//alert ("check password match");

		retval=false;

	}



	if (!retval) {

		document.forms.searchfrm.search_keyword.focus();

	}

	

//alert ("return value=" + retval);

	return retval;

}



/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de)

 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 

 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.

 * 

 * Thanks to Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.

 */

jQuery.extend({

/**

* Returns get parameters.

*

* If the desired param does not exist, null will be returned

*

* @example value = $.getURLParam("paramName");

*/ 

 getURLParam: function(strParamName){

	  var strReturn = "";

	  var strHref = window.location.href;

	  var bFound=false;

	  

	  var cmpstring = strParamName + "=";

	  var cmplen = cmpstring.length;



	  if ( strHref.indexOf("?") > -1 ){

	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);

	    var aQueryString = strQueryString.split("&");

	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){

	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){

	        var aParam = aQueryString[iParam].split("=");

	        strReturn = aParam[1];

	        bFound=true;

	        break;

	      }

	      

	    }

	  }

	  if (bFound==false) return null;

	  return strReturn;

	}

});





jQuery.noConflict()



jQuery(document).ready(function() {

jQuery(function()
{
    jQuery('div.featured-zines-browse').jScrollPane({showArrows:true, scrollbarWidth: 19});

});

	



	//show report a bug box

	jQuery("a#rab").click( 

			function(event) {
					jQuery("div.rabbx").show("slow");
					return false
		});

	jQuery("div.rabbx span.closebtn").click( 

			function(event) {

				jQuery("div.rabbx").hide();

				return false;

			});

	//show header login box

	jQuery("div#login a.signin").click( 

			function(event) {

				if (!isLoggedIn()) {

					jQuery("div.loginbx").show("slow");

				} else {

					open ("http://login.zinecube.com/logout.php", "_self");

				}

				return false

		});

	

	jQuery("div.loginbx span.closebtn").click( 

			function(event) {

				jQuery("div.loginbx").hide();

				return false;

			});

	

	jQuery("input#login_btn").click( 

			function(event) {

				retval1 = verify_emailaddr(pop_loginform.hc_loginusername.value,  pop_loginform.hc_loginpassword.value, 'loginpopup');

				return retval1;

		});

	

	jQuery("a#switchcaptchaimg").toggle( 

			function() {

				jQuery("span#captchaimage img").attr("src","/images/registration/captcha_2.gif");

				

				return false

			}, 

			function() {

				jQuery("span#captchaimage img").attr("src","/images/registration/captcha_1.gif");

				

				return false

			} 

		);

		

	jQuery("input#regeditsubmitbtn").click( 

			function(event) {

//				alert ("Checking edit javascript fields");

				if (!chkRegEditFrm1()) {

					jQuery("div.errors").fadeIn();

					return false;

				} else {

					return true;

				}

		});



	jQuery("input#regsubmitbtn").click( 

			function(event) {

//				alert ("Checking javascript fields");

				if (!chkRegFrm1()) {

					jQuery("div.errors").fadeIn();

//					alert ("Show errors");

//					jQuery("label#forusername").hide();

					return false;

				} else {

					return true;

				}

		});



	

	jQuery("input#hc_login_btn").click( 

		function(event) {

			retval = verify_emailaddr(hc_loginform.hc2_loginusername.value,  hc_loginform.hc2_loginpassword.value,'login');

			return retval;

		});



	jQuery("input#hc_forgotpw_btn").click( 

		function(event) {

			retval = checkemail(hc_loginform.emailaddr.value);

			if (!retval) {

				alert ("Please enter a valid Email Address.");

				jQuery("div.hc_loginbox p.error").fadeIn();  

			}	



			return retval;

		});



	jQuery("#mailzine").click( 

		function(event) {

//				alert ("Please enter a valid Email Address.");

				jQuery("div#share").fadeIn();  

				jQuery("div#commentform").hide();  

				jQuery("div#comments").hide();  

				jQuery("div#postcomment").hide();  

				jQuery("div#login").hide();  

				jQuery("div#morebyuser").hide();  



			return false;

		});



	jQuery("#commentslink").click( 

		function(event) {

//				alert ("Please enter a valid Email Address.");

				jQuery("div#commentform").fadeIn();  

				jQuery("div#comments").fadeIn();  

				jQuery("div#postcomment").fadeIn();  

				jQuery("div#login").fadeIn();  

				jQuery("div#share").hide();  

				jQuery("div#morebyuser").hide();  



			return false;

		});

		

	jQuery("#morebyauthor").click( 

		function(event) {

//				alert ("Please enter a valid Email Address.");

				jQuery("div#morebyuser").fadeIn();  

				jQuery("div#share").hide();  

				jQuery("div#commentform").hide();  

				jQuery("div#comments").hide();  

				jQuery("div#postcomment").hide();  

				jQuery("div#login").hide();  



			return false;

		});



//MyZines  functionality

		

		function loadMyZines(ctid, uid){

			

			var resultsURL = "/includes/myzines_results.php?ctid="+ctid+"&page="+page;

			jQuery("#results").load(resultsURL,

				function() {

					jQuery("a.edit").click( 

					function(event) {

						

						jQuery(this).parent().parent().siblings().removeClass("hilite");

						jQuery(this).parent().parent().parent().siblings().children().removeClass("hilite");

						jQuery(this).parent().parent().addClass("hilite");



						cid = jQuery(this).attr("id")

						

						

//						alert ("cid="+cid+" ctid="+ctid);

						if (ctid == 1 || ctid == 0) {

							open ("/createzines/createpage.php?cid="+cid, "_self");

						} else {

							loadcpform(ctid, cid, uid)

						}

						return false

					});

					

					jQuery("a.delete").click( 

					function(event) {

						jQuery(this).parent().parent().siblings().removeClass("hilite");

						jQuery(this).parent().parent().parent().siblings().children().removeClass("hilite");

						jQuery(this).parent().parent().addClass("hilite");

						cid = jQuery(this).attr("id")

						jQuery("div#confirm").fadeIn();

						jQuery("div#confirm").css("top",""+(event.pageY-200)+"px");

						jQuery("div#confirm").css("left",""+(event.pageX-440)+"px");

						jQuery("#confirm a.yes").click( 

							function(event) {

								var deleteURL = "/includes/myzines_delete.php?cid="+cid+"&uid="+uid+"&ctid="+ctid;

								jQuery.post(deleteURL,

									function() {

										loadMyZines(ctid, uid);

										loadcpform(ctid, -1, uid);

										jQuery("div#confirm").hide();

									}

								)

								return false

							});

							

						jQuery("#confirm a.no").click( 

							function(event) {

								jQuery("div#confirm").hide();

								return false

							});

					return false

					});

				}

			

			)

		}

		function loadcpform(ctid, cid, uid){



//			alert ("inside loadcpform");

			var cpformURL = "/includes/myzines_form.php?ctid="+ctid+"&cid="+cid;

//			alert ("inside loadcpform1");

			jQuery("#cpform").load(cpformURL,

				function() {

//			alert ("loadcpform cid="+cid);

					if(cid != -1 ){

//			alert ("inside loadcpform4");

							jQuery("div#cpform #myzine_btn").attr("src","/css/i/myzines/save_btn.jpg");

							jQuery("div#cpform #myzine_btn").click( 

								function(event) {

//									alert ("sazine" + cid);

									if (cid) {

										savezine(cid);

									}

									cid = -1;

									return false

							});

							

							jQuery("div#cpform #cancel_btn").css("display","block");

							jQuery("div#cpform #cancel_btn").click( 

								function(event) {

								    jQuery("div.zinepromo").removeClass("hilite");

									cid = -1;

									//alert ("czine=" + cid);

//									jQuery("div#cpform #zinetitle").text("");

									//$("p").text("<b>Some</b> new text.");



									loadcpform(ctid,-1, uid);

									return false

							});

							

						} else {

//							alert ("Inside add section");

							jQuery("div#cpform #myzine_btn").attr("src","/css/i/myzines/add_new_btn.gif");

							jQuery("div#cpform #myzine_btn").click( 

								function(event) {

//									alert ("adzine" + cid);

									addzine(ctid, cid, uid);

									return false

							});

							

							

							jQuery("div#cpform #cancel_btn").css("display","none");

						}

				

				}

			)

		}

		

		function savezine(cid) {

//			alert (jQuery("div#cpform #zinedesc").val());

//			alert (jQuery("div#cpform #ispublic").attr("checked"));

//			alert (jQuery("div#cpform #ispublic #checked").val());

//			alert ("SaveZine");

//alert (uid);

			jQuery.post("/includes/myzines_save.php?cid="+cid, { zinedesc: jQuery("div#cpform #zinedesc").val(), zinetitle: jQuery("div#cpform #zinetitle").val(), zineURL: jQuery("div#cpform #zineURL").val(), ispublic: jQuery("div#cpform #ispublic").val(), zinegenre: jQuery("div#cpform #zinegenre").val(), zinetext: jQuery("div#cpform #zinetext").val() }, 

				  function(){

					loadMyZines(ctid, uid);

					loadcpform(ctid, -1, uid);

				  })

			}



		function addzine(ctid, cid, uid) {
			valid = 0;
			if (ctid=='2') {
				// The text functionality is under construction until beta iii.
				//				if (jQuery("div#cpform #zinetext").val()) {
				//					valid = 1;
				//				}
			} else if (ctid=='3') {
				//ending = jQuery("div#cpform #zineURL").val().substr(jQuery("div#cpform #zineURL").val().length-3,3);
				splitArr = jQuery("div#cpform #zineURL").val().split('.');
				if (splitArr[splitArr.length-1] == 'jpg' || 
					splitArr[splitArr.length-1] == 'png' || 
					splitArr[splitArr.length-1] == 'gif' || 
					splitArr[splitArr.length-1] == 'bmp' || 
					splitArr[splitArr.length-1] == 'jpeg') 
				{
					valid = 1;
				}
			} else if (ctid=='5') {
				splitArr = jQuery("div#cpform #zineURL").val().split('=');
				if (splitArr[0] == 'http://www.youtube.com/watch?v' && 
					splitArr[1].length == 11) 
				{
					valid = 1;
				}
			}
			//alert (splitArr[splitArr.length-1]);
			if (valid) {
				jQuery.post("/includes/myzines_add.php?cid="+cid+"&ctid="+ctid+"&uid="+uid, { zinedesc: jQuery("div#cpform #zinedesc").val(), zinetitle: jQuery("div#cpform #zinetitle").val(), zineURL: jQuery("div#cpform #zineURL").val(), ispublic: jQuery("div#cpform #ispublic").val(), zinegenre: jQuery("div#cpform #zinegenre").val(), zinetext: jQuery("div#cpform #zinetext").val() },

					  function(){

						loadMyZines(ctid, uid);

						loadcpform(ctid, -1, uid);

					  })
			} else {
				if (ctid=='2') {
					alert ("This functionality will be available in Beta iii");
				} else if (ctid=='3') {
					alert ("Please enter a valid image URL.  The ending should be '.jpg', '.jpeg', '.gif', '.png', or '.bmp'.");
				} else if (ctid=='5') {
					alert ("Please enter a valid video URL.  Something like 'http://www.youtube.com/watch?v=oSyKUrK531w'");
				}
			}
		}

			

		function setcpnav(ctid) {		

				//var cpnavcat = jQuery.getURLParam("ctid");

				if(ctid){

					//alert (ctid);

					//jQuery("#myzinescp ul li").removeClass("active");

					jQuery("#myzinescp ul li."+ctid).addClass("active");

				} 

			}

			

		

		if (typeof(ctid) == "undefined") {

			ctid = 0;

		}

		if (typeof(page) == "undefined") {

			page = 0;

		}

		if (typeof(uid) == "undefined") {

			uid = 0;

		}

		loadMyZines(ctid, uid);

		loadcpform(ctid, -1, uid);

		setcpnav(ctid);

//		alert ("after");

});



//check if user is registered

if(queryString('user') == "guest") {

	var nonRegFlag = true;

} else {

	var nonRegFlag = false;

}



// Current user magazine stored rating stars images

strc_1 = "/css/i/shell/star_wht.png";

strc_2 = "/css/i/shell/star_wht.png";

strc_3 = "/css/i/shell/star_wht.png";

strc_4 = "/css/i/shell/star_wht.png";

strc_5 = "/css/i/shell/star_wht.png";

//strc_4 = "/css/i/shell/star_blu_half.gif";

//strc_5 = "/css/i/shell/star_blu.gif";



// Rating images

strmsg_1 = "Not Bad";

strmsg_2 = "Nice";

strmsg_3 = "Very Good";

strmsg_4 = "Excellent";

strmsg_5 = "Awesome";



//rating stars default no rating dispay (all gray stars)

var noRate = function() {

	stars('5','none');

}



//rating stars mouseover

var showRate = function(strs) {

	noRate();

	stars(strs, 'show');

}



//rating stars mouseout

var clearRate = function() {

	stars('5','reset');

}



//rating stars mouseout

var setRate = function(strs) {

	noRate();

	stars(strs, 'set');

	clearRate = showRate = function() {};

}



//rating stars click to set rating	

var stars = function(strNum, str) {

	if(str == "show"){

		var strSrc = "/css/i/shell/star_wht.png";

		for(i=1; i<=strNum; i++) {

			eval("document.getElementById('rated_"+i+"')").src = strSrc;

			eval("document.getElementById('rateMsg').innerHTML = strmsg_"+i+"");

		}

	} else if(str == "set"){

			if(nonRegFlag) {

				clearRate();

			return false;

		} else {

			var strSrc = "/css/i/shell/star_blu.png";

			for(i=1; i<=strNum; i++) {

				eval("document.getElementById('rated_"+i+"')").src = strSrc;

				eval("document.getElementById('rateVal')").value = strNum;

				eval("document.getElementById('rateMsg').innerHTML = strmsg_"+i+"");

			}

		}

		

	} else if(str == "none"){

		var strSrc = "/css/i/shell/star_wht.png";

		for(i=1; i<=strNum; i++) {

			eval("document.getElementById('rated_"+i+"')").src = strSrc;

			document.getElementById('rateMsg').innerHTML = "";

		}

	

	} else if (str == "reset") {

		for(i=1; i<=strNum; i++) {

			 eval("document.getElementById('rated_"+i+"').src = strc_"+i+"");

			 document.getElementById('rateMsg').innerHTML = "";

			}

	}

	

}



// Added for the clickable thumbs

function viewMagazine(cid) {

   

}
