// check username on blurr using jquery+ajax
//GetUsrName.php is checking the username from the database.
$(function() {
 $("#username").blur(function()
    {
	 $("#error").html('<img src="images/ajax-loader.gif">');
      if($("#username").val().length <3)
            {
              $("#error").html('Username is too short.');
              $("#username").focus();
              return false;
            }
        $.post("GetUsrName.php",{'username':$("#username").val()},function(data)
		{
        $("#error").html(data);
        });
	});
});
// Validation in javascript 
//==============================================
// Function name : validation_login
// Function Use : For validation
//====================================================================
function validation_login(){
	if(document.login_frm.username.value==""){
	alert("Enter The Username"); 
	document.login_frm.username.focus();
	return false;
	}
	if(document.login_frm.password.value==""){
	alert("Enter The Password"); 
	document.login_frm.password.focus();
	return false;
	}
}
//====================================================================
// Function name : changepass_validate
// Function Use : For validation
//====================================================================
function changepass_validate(){
	if(document.form1.opassword.value==""){
	alert("Enter The Old Password ...!");
	document.form1.opassword.focus();
	return false;
	}
	if(document.form1.npassword.value==""){
	alert("Enter The New Password ...!");
	document.form1.npassword.focus();
	return false;
	}
	if(document.form1.cpassword.value==""){
	alert("Enter The Confirm Password ...!");
	document.form1.cpassword.focus();
	return false;
	}
	if(document.form1.npassword.value!=document.form1.cpassword.value){
	alert("New Password And Confirm Password Is Not Same Password ...!");
	document.form1.cpassword.focus();
	return false;
	}
}
//======================================================================
// Function name : frmValidate_editpagename
// Function Use : For validation
//====================================================================
function frmValidate_editpagename(){
	if (document.edit_page_frm.pagesectionname.value==""){
		alert("Please Enter Page Name...!");
		document.edit_page_frm.pagesectionname.focus();
		return false;
	}
	if (document.edit_page_frm.meta_description.value==""){
		alert("Please Enter Meta Description...!");
		document.edit_page_frm.meta_description.focus();
		return false;
	}
	if (document.edit_page_frm.meta_keyword.value==""){
		alert("Please Enter Meta Keyword...!");
		document.edit_page_frm.meta_keyword.focus();
		return false;
	}
	if (document.edit_page_frm.page_title.value==""){
		alert("Please Enter Page Title...!");
		document.edit_page_frm.page_title.focus();
		return false;
	}
}
//========================================================================

//==============================================
// Function name : news_validate
// Function Use : For Newsletter validation
//==============================================
function news_validate(){
	if (document.frmnews.news_subject.value==""){
		alert("Please Enter News Subject...!");
		document.frmnews.news_subject.focus();
		return false;
	}
}

//========================================================================

// Function name : validate_addcategory
// Function Use : For validation
//====================================================================
function validate_addcategory()
{
	if(document.addcat_frm.catname.value=="")
	{
		alert("Please Enter Category Name...!");
		document.addcat_frm.catname.focus();
		return false;
	}
}

//====================================================================
// Function name : validate_editcategory
// Function Use : For validation
//====================================================================
function validate_editcategory()
{
	if(document.editcat_frm.catname.value=="")
	{
		alert("Please Enter Category Name...!");
		document.editcat_frm.catname.focus();
		return false;
	}
}

//====================================================================
// Function name : subscribe_validate
// Function Use : For Front subscribe validation
//====================================================================
function subscribe_validate()
{
	if(document.subscribeform.name.value=="Name" || document.subscribeform.name.value=="")
	{
		alert("Please Enter Subscriber Name...!");
		document.subscribeform.name.focus();
		return false;
	}
	
	if(document.subscribeform.email.value!="")
	{
		if(document.subscribeform.email.value.indexOf("@")==-1 ||
			document.subscribeform.email.value.indexOf(".")==-1 ||
			document.subscribeform.email.value.indexOf("")==-1 ||
			document.subscribeform.email.value.length < 6)
		{
			alert("Sorry, the e-Mail Address is not valid.");
			document.subscribeform.email.focus();
			return false;		
		}
	}
	else
	{
		alert("Please enter e-Mail Address.");
		document.subscribeform.email.focus();
		return false;	
	}
}

//====================================================================
// Function name : validate_categorylist
// Function Use : For validation
//====================================================================
function validate_memberlist()
{
	return confirm("Are You Sure To Delete This Member? ");
}

//====================================================================
// Function name : validate_categorylist
// Function Use : For validation
//====================================================================
function validate_categorylist()
{
	return confirm("Are You Sure To Delete This Category? ");
}
//====================================================================
// Function name : validate_addcategory
// Function Use : For validation
//====================================================================
function validate_addproduct()
{
	if(document.addproduct_frm.catid.value=="")
	{
		alert("Please Select Category Name...!");
		document.addproduct_frm.catid.focus();
		return false;
	}
	if(document.addproduct_frm.product_name.value=="")
	{
		alert("Please Enter Product Name...!");
		document.addproduct_frm.product_name.focus();
		return false;
	}
	if(document.addproduct_frm.product_price.value=="")
	{
		alert("Please Enter Product Price...!");
		document.addproduct_frm.product_price.focus();
		return false;
	}
	if(document.addproduct_frm.product_image.value=="")
	{
		alert("Please Browse Product Image...!");
		document.addproduct_frm.product_image.focus();
		return false;
	}
}
//====================================================================
// Function name : validate_editproduct
// Function Use : For validation
//====================================================================
function validate_editproduct()
{
	if(document.editproduct_frm.category.value=="")
	{
		alert("Please Select Category Name...!");
		document.editproduct_frm.category.focus();
		return false;
	}
	if(document.editproduct_frm.product_name.value=="")
	{
		alert("Please Enter Product Name...!");
		document.editproduct_frm.product_name.focus();
		return false;
	}
	if(document.editproduct_frm.product_price.value=="")
	{
		alert("Please Enter Product Price...!");
		document.editproduct_frm.product_price.focus();
		return false;
	}
}
//====================================================================
// Function name : validate_productlist
// Function Use : For validation
//====================================================================
function validate_productlist()
{
	return confirm("Are You Sure To Delete This Product ? ");
}
//====================================================================

//====================================================================
// Function name : validate_productlist
// Function Use : For validation
//====================================================================
function validate_subscribelist()
{
	return confirm("Are You Sure To Delete This subscriber ? ");
}
//====================================================================


//==============================================
// Function name : CheckAll
// Function Use : Check all checkboxes for send news 
//==============================================

function CheckAll(chk)
{
for (var i=0;i < document.forms[0].elements.length;i++)
	{
		var e = document.forms[0].elements[i];
		if (e.type == "checkbox")
		{
			e.checked = chk.checked;
		}
	}
}


//====================================================================================

function validate_sendnews()
{	
	if(document.frmsendnews.news_id.value=="")
	{
		alert("Please select newletter to send");
		document.frmsendnews.news_id.focus();
		return false;
		
	}
	var checked ;
	checked=false;
	elements=document.getElementsByName("subsc_id[]");
	for(var i=0; i < elements.length; i++)
    {
		if(elements[i].checked)
		{
			checked = true;
		}
	}
	
	if (!checked) {
		alert('Please select at least 1 email id  to send newletter');
		return false;
	}else
	{
		return checked;
	}
	

}

//=============================================================
//Product JS
//=============================================================
function validate_addproduct(){
	if(document.addproduct_frm.category.value==""){
	alert("Select Category Name ...! ");
	document.addproduct_frm.category.focus();
	return false;
	}
	if(document.addproduct_frm.product_name.value==""){
	alert("Enter The Productname ...!");
	document.addproduct_frm.product_name.focus();
	return false;
	}
	if(document.addproduct_frm.product_price.value==""){
	alert("Enter The Product Price ...!");
	document.addproduct_frm.product_price.focus();
	return false;
	}
	if(document.addproduct_frm.product_image.value==""){
	alert("Enter The  Image ...!");
	document.addproduct_frm.product_image.focus();
	return false;
	}
}
//================================================================
//FAQ JS
//================================================================
function validate_addfaq()
{
	if(document.frm_faq.question.value=="")
	{
		alert("Please Enter Question ...! ");
		document.frm_faq.question.focus();
		return false;
	}
		if(document.frm_faq.answer.value=="")
	{
		alert("Please Enter Answer ...! ");
		document.frm_faq.answer.focus();
		return false;
	}
}
//===============================================================
//Delete confirmation
//===============================================================

function validate_del()
{
	return confirm("Are You Sure To Delete?");
}

//==============================================================

function member_check()
{
	
 	if(document.frm_member.name.value=="")
	{
		alert("Please Enter Name...");
		document.frm_member.name.focus();
		return false;		
	}
	
	if(document.frm_member.Email.value!="")
	{
		if(document.frm_member.Email.value.indexOf("@")==-1 ||
			document.frm_member.Email.value.indexOf(".")==-1 ||
			document.frm_member.Email.value.indexOf("")==-1 ||
			document.frm_member.Email.value<6)
			{
				alert("Please enter valid Email-Id....");
				document.frm_member.Email.focus();
				return false;
			}
	}
	else
	{
			alert("Please enter your Email-Id....");
			document.frm_member.Email.focus();
			return false;
	}
	if(document.frm_member.username.value=="")
	{
		alert("Please Enter Username..");
		document.frm_member.username.focus();
		return false;		
	}

	if(document.getElementById('error').innerHTML!= "")
	{
		alert("Please enter username is correct format..");
		return false;
	}

	
	if(document.frm_member.password.value=="")
	{
		alert("Please Enter Password..");
		document.frm_member.password.focus();
		return false;		
	}
	if(document.frm_member.cpassword.value=="")
	{
		alert("Please Enter Confirm Password..");
		document.frm_member.cpassword.focus();
		return false;		
	}
	
	if(document.frm_member.password.value!=document.frm_member.cpassword.value)
	{
		alert("Confirm Password and Password is not same..");
		document.frm_member.password.focus();
		return false;		
	}
	
}
