// JavaScript Document

function category_book(val)
{
	window.location.href="all-books.php?category="+val;
}

function call_pending(obj)
{
		document.getElementById(obj).className = "pendingtabactive";
		document.getElementById("declinelink").className = "declinetab";
		document.getElementById("declinelink1").className = "declinetab1";
		document.getElementById("friendlink").className = "friendtab";
		document.getElementById("pendinglink1").className = "pendingtab1";
		document.getElementById("pending").style.display='';
		document.getElementById("friend").style.display='none';
		document.getElementById("decline").style.display='none';
		document.getElementById("pending1").style.display='none';
		document.getElementById("decline1").style.display='none';
}
function call_dec(obj)
{
		document.getElementById(obj).className = "declinetabactive";
		document.getElementById("pendinglink").className = "pendingtab";
		document.getElementById("friendlink").className = "friendtab";
		document.getElementById("pendinglink1").className = "pendingtab1";
		document.getElementById("declinelink1").className = "declinetab1";
		document.getElementById("pending").style.display='none';
		document.getElementById("friend").style.display='none';
		document.getElementById("decline").style.display='';
		document.getElementById("pending1").style.display='none';
		document.getElementById("decline1").style.display='none';
}


function call_pending1(obj)
{
		document.getElementById(obj).className = "pendingtab1active";
		document.getElementById("declinelink").className = "declinetab";
		document.getElementById("friendlink").className = "friendtab";
		document.getElementById("pendinglink").className = "pendingtab";
		document.getElementById("declinelink1").className = "declinetab1";
		document.getElementById("pending").style.display='none';
		document.getElementById("friend").style.display='none';
		document.getElementById("decline").style.display='none';
		document.getElementById("pending1").style.display='';
		document.getElementById("decline1").style.display='none';
}
function call_dec1(obj)
{
		document.getElementById(obj).className = "declinetab1active";
		document.getElementById("pendinglink").className = "pendingtab";
		document.getElementById("friendlink").className = "friendtab";
		document.getElementById("declinelink").className = "declinetab";
		document.getElementById("pendinglink1").className = "pendingtab1";
		document.getElementById("pending").style.display='none';
		document.getElementById("friend").style.display='none';
		document.getElementById("decline").style.display='none';
		document.getElementById("pending1").style.display='none';
		document.getElementById("decline1").style.display='';
}

function call_friend(obj)
{
	
		document.getElementById(obj).className = "friendtabactive";
		document.getElementById("declinelink").className = "declinetab";
		document.getElementById("pendinglink").className = "pendingtab";
		document.getElementById("pendinglink1").className = "pendingtab1";
		document.getElementById("declinelink1").className = "declinetab1";
		document.getElementById("pending").style.display='none';
		document.getElementById("friend").style.display='';
		document.getElementById("decline").style.display='none';
		document.getElementById("pending1").style.display='none';
		document.getElementById("decline1").style.display='none';
}
function show_txtarea(val)
{
		document.getElementById(val).style.display='';
}
//Delete Book Code Start
function book_delete(val)
{
	if(confirm("Warning: This Book And All Chapter of This Book Will Be Deleted?"))
	{
		window.location.href="delete-book.php?book="+val;
	}
}
//Delete Book Code End

//Delete Chapter Code Start
function chapter_delete(val)
{
	if(confirm("Do You Really Want To Delete This Chapter?"))
	{
		window.location.href="delete-book.php?chapter="+val;
	}
}
//Delete Chapter Code End

//Delete Favourite Book Code Start
function fbook_delete(val)
{
	//alert("hi");
	if(confirm("Do You Really Want To Remove This Book From Your Favourite List?"))
	{
		window.location.href="delete-book.php?fbook="+val;
	}
}
//Delete Favourite Book Code End

function show_rating(val)
{
	document.getElementById(val+"rate").style.display='';
	document.getElementById(val+"comment").style.display='none';
}
function show_comment(val)
{
	document.getElementById(val+"comment").style.display='';
	document.getElementById(val+"rate").style.display='none';
}
function show_profile()
{
	document.getElementById("author_profile").style.display='';
	document.getElementById("less").style.display='';
	document.getElementById("more").style.display='none';
}
function hide_profile()
{
	document.getElementById("author_profile").style.display='none';
	document.getElementById("less").style.display='none';
	document.getElementById("more").style.display='';
}
function show_initiate()
{
	document.getElementById("initiated_book").style.display='';
	document.getElementById("less_initiate").style.display='';
	document.getElementById("more_initiate").style.display='none';
	
}
function hide_initiate()
{
	document.getElementById("initiated_book").style.display='none';
	document.getElementById("less_initiate").style.display='none';
	document.getElementById("more_initiate").style.display='';
}
function show_chapter()
{
	document.getElementById("chapter_contri").style.display='';
	document.getElementById("less_contri").style.display='';
	document.getElementById("more_contri").style.display='none';
	
}
function hide_chapter()
{
	document.getElementById("chapter_contri").style.display='none';
	document.getElementById("less_contri").style.display='none';
	document.getElementById("more_contri").style.display='';

}
function show_books()
{
	document.getElementById("book_contri").style.display='';
	document.getElementById("less_books").style.display='';
	document.getElementById("more_books").style.display='none';
	
}
function hide_books()
{
	document.getElementById("book_contri").style.display='none';
	document.getElementById("less_books").style.display='none';
	document.getElementById("more_books").style.display='';
}
//Greybox Coding
GB_myShow = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
		center_win: true,
        height: height || 280,
        width: width || 450,
	    fullscreen: false,
		show_loading: false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}

//Greybox Coding
function rate(book)
{
//alert(book);	
if(document.form1.radio[0].checked==true){rate=1; alert(rate);}
 if(document.form1.radio[1].checked==true){rate=2;}
 if(document.form1.radio[2].checked==true){rate=3;}
 if(document.form1.radio[3].checked==true){rate=4;}
 if(document.form1.radio[4].checked==true){rate=5;}
	
	window.location.href="rating.php?rate="+rate+'&book=book';	
	return true;
}
function rate_active(val,obj)
{
		
		if(val!='')
		{
				obj.className='gobtnactive';
				obj.disabled=false;
				//window.location.href="latest-books.php?rate="+val;	
			}else{
				obj.className='gobtninactive';
				obj.disabled=true;
				}

		
}


function view_comments(val)
{
	window.location.href="view-comments.php?chapter="+val;	
}


function call_accept(val)
{
	window.location.href="accept-decline-friend.php?accept="+val;	
}
function call_decline(val)
{
	window.location.href="accept-decline-friend.php?decline="+val;	
}
function chk_password(obj,pass,npass,cpass,password)
{
		if(pass!='' && npass!='' && cpass!='')
		{
			if(pass==password)
			{	
				if(npass==cpass)
				{
				obj.className='gobtnactive';
				obj.disabled=false;
				}else{
				obj.className='gobtninactive';
				obj.disabled=true;
				}
			}else{
				obj.className='gobtninactive';
				obj.disabled=true;
				}
		}
}
function login_enable(obj,val,user)
{
		if(user!='' && val!='' && user!='Enter Email' && val!='Password')
		{
		obj.className='gobtnactive';
		obj.disabled=false;
		}else{
		obj.className='gobtninactive';
		obj.disabled=true;
		}
}
function chk_radio(obj)
{
	if(obj=='gender')
	{	
		document.getElementById("gender").checked=true;
		document.getElementById("gender1").checked=false;
	}
	if(obj=='gender1'){
		document.getElementById("gender").checked=false;
		document.getElementById("gender1").checked=true;
	}
}
function chk_field(obj)
{
	//alert("hi");
	
	if(document.getElementById("terms").checked==true)
	{
		//alert(document.getElementById("user_hidden").value);
		//alert(document.form3.password.value);
		//alert(document.getElementById("confirm_password").value);
		if(document.getElementById("email").value!='' && document.getElementById("password").value!='' && document.getElementById("confirm_password").value!='' && (document.form3.password.value==document.getElementById("confirm_password").value)  && document.getElementById("first_name").value!='' && document.getElementById("last_name").value!='' && document.getElementById("profile_name").value!='' && (document.getElementById("gender").value!='' || document.getElementById("gender1").value!='') && document.getElementById("Regcheck").value.length>=5 && document.getElementById("user_hidden").value!=1 && document.getElementById("profile_hidden").value!=1)
		{ //alert("rigth");
			obj.className='gobtnactive';
			obj.disabled=false;
		}else{
			//alert("wrong");
			obj.className='gobtninactive';
			obj.disabled=true;
}
	}
	if(document.getElementById("terms").checked==false)
	{
		obj.className='gobtninactive';
		obj.disabled=true;
	}
}
function filtercountry(val)
{
	if(val=='Non US State')
	{
		document.getElementById("usastate").style.display='';
		document.getElementById("nonusastate").style.display='';
		document.getElementById("usacountry").style.display='none';
		document.getElementById("nonusacountry").style.display='';
	}
	if(val!='Non US State')
	{
		document.getElementById("usastate").style.display='';
		document.getElementById("nonusastate").style.display='none';
		document.getElementById("usacountry").style.display='';
		document.getElementById("nonusacountry").style.display='none';
	}
	
}

function filtereditcountry(val)
{
	window.location.href="edit-details.php?country="+val;
	if(val=='213')
	{
		document.getElementById("usastate").style.display='';
		document.getElementById("nonusastate").style.display='none';
	}
	if(val!='213')
	{
		document.getElementById("usastate").style.display='none';
		document.getElementById("nonusastate").style.display='';
	}
}

function show_upload()
{
	document.getElementById("file_input").style.display='';
	document.getElementById("file_logo").style.display='none';
}

function chk_pass(pass1,pass2)
{
	if(pass1!=pass2)
	{
	alert("Your Password And Confirm Password Not Matched!");
	document.getElementById("confirm_password").value='';
	document.getElementById("confirm_password").focus();
	}
}

//Validation for registration Form
function VerifyRegister()
{
	if(document.getElementById("email").value=='')
	{
		alert("Please Enter Username!");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("email").value!='')
	{
	var email=document.getElementById("email").value;
	
	var pass1=email.indexOf('.');
	var pass2=email.indexOf('@');
	var dot_pos=email.lastIndexOf('.');
	var at_pos=email.lastIndexOf('@');
	if(pass1==-1||pass2==-1||at_pos>=dot_pos){
		alert("Enter the valid email");
		document.getElementById("email").focus();
		return false;
			}
	}
	if(document.getElementById("password").value=='')
	{
		alert("Please Enter Password!");
		document.getElementById("password").focus();
		return false;
	}
	if(document.getElementById("confirm_password").value=='')
	{
		alert("Please Enter Confirm Password!");
		document.getElementById("confirm_password").focus();
		return false;
	}
	if(document.getElementById("first_name").value=='')
	{
		alert("Please Enter First Name!");
		document.getElementById("first_name").focus();
		return false;
	}
	if(document.getElementById("last_name").value=='')
	{
		alert("Please Enter Last Name!");
		document.getElementById("last_name").focus();
		return false;
	}
	if(document.getElementById("profile_name").value=='')
	{
		alert("Please Enter Profile Name!");
		document.getElementById("profile_name").focus();
		return false;
	}
	if(document.getElementById("gender").checked==false && document.getElementById("gender1").checked==false)
	{
		alert("Please Select Your Gender!");
		document.getElementById("gender").focus();
		return false;
	}
return true;
}

//Validation For New Book Entry

function VerifyEntry()
{
	if(document.getElementById("selectcategory").value=='')
	{
		alert("Please Select Book Category!");
		document.getElementById("selectcategory").focus();
		return false;
	}
	if(document.getElementById("book_title").value=='')
	{
		alert("Please Enter Book title!");
		document.getElementById("book_title").focus();
		return false;
	}
	
return true;
}

function filtercategory(val)
{
	window.location.href="newbook-entry.php?category="+val;	
}




//Validation For Create First Chapter

function VerifyChapter()
{
	if(document.getElementById("chapter_title").value=='')
	{
		alert("Please Enter Chapter Title!");
		document.getElementById("chapter_title").focus();
		return false;
	}	
return true;
}



//Validation For Contact Us Form

function verifycontact()
{
	if(document.getElementById("name").value=='')
	{
		alert("Please Enter Your name!");
		document.getElementById("name").focus();
		return false;
	}	
	if(document.getElementById("email").value=='')
	{
		alert("Please Enter Your Email!");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("email").value!='')
	{
	var email=document.getElementById("email").value;
	
	var pass1=email.indexOf('.');
	var pass2=email.indexOf('@');
	var dot_pos=email.lastIndexOf('.');
	var at_pos=email.lastIndexOf('@');
	if(pass1==-1||pass2==-1||at_pos>=dot_pos){
		alert("Enter The Valid Email");
		document.getElementById("email").focus();
		return false;
			}
	}
	if(document.getElementById("msg").value=='')
	{
		alert("Please Enter Your Message!");
		document.getElementById("msg").focus();
		return false;
	}	
return true;
}
