// JavaScript Document
function check_catfaq_edit()
{
	var cate_name=document.form1.txt_new_cate.value;
	if(cate_name.length<1 || cate_name=="")
	{
		alert("Please enter a category name");
		return false;
	}
	return true;
	
}

function check_catfaq_add()
{
	var cate_name=document.form1.txt_cate_nm.value;
	if(cate_name.length<1 || cate_name=="")
	{
		alert("Please enter a category name");
		return false;
	}
	return true;
}

function delete_category()
{
	if(confirm("Are you sure? \nYou are going to delete all the records in this category"))
		return true;
	else
		return false;
}
function change()
{
	if(confirm("Are you sure? You are going to change payment status"))
		return true;
	else
		return false;
}
function validate_discount()
{
	var code=document.form1.ca_payment_discount_code.value;
	var discount=document.form1.ca_payment_discount_percent.value;
	var flag=0;
	var msg="There are following errors with your submission.\n";
	if(code=="" || code.length<4)
	{
		flag=1;
		msg+="Discount code must have minimum 4 alphanumerics.\n";
	}
	if(discount=="" || isNum(discount))
	{
		flag=1;
		msg+="Please enter a valid discount.\n";
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}

function enable_ad()
{
	if(confirm("Are you sure? You are going to Enable this classified"))
		return true;
	else
		return false;
}
function disable_ad()
{
	if(confirm("Are you sure? You are going to Disable this classified"))
		return true;
	else
		return false;
}
function image_window(img_name,height,width,title)
{
			
	window.open("image_view.php?img_name="+img_name,"","width="+width+",height="+height+",resizable=no,menubar=no,left=10,top=10,screenX=10,screenY=10,scrollbars=no");
}
function attr_edit()
{
	var msg="There are following error(s) with your submission :\n";
	var flag=0;
	var attr=document.form1.attribute.value;
	if(attr=="" || attr.length<1)
	{
		msg+="please enter attribute name";
		flag=1;
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}

function attr_add()
{
	var msg="There are following error(s) with your submission :\n";
	var flag=0;
	var attr=document.form1.ca_categories_attributes.value;
	if(attr=="" || attr.length<1)
	{
		msg+="please enter attribute name";
		flag=1;
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}
function cate_add()
{
	var msg="There are following error(s) with your submission :\n";
	var flag=0;
	var attr=document.form1.ca_categories_category_name.value;
	if(attr=="" || attr.length<1)
	{
		msg+="Please enter Category name";
		flag=1;
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}

function validate()
{
	var msg="There are following error(s) with your submission :\n";
	var flag=0;
	var username=document.form1.username.value;
	var password=document.form1.password.value;
	var new_password=document.form1.new_password.value;
	if(username=="" || username.length<1)
	{
			msg+="Please Enter username\n";
			flag=1;
	}
	if(password=="" || password.length<5)
	{
			msg+="Please enter a password atleast 5 charcters\n";
			flag=1;
	}
	if(new_password=="" || new_password.length<5)
	{
			msg+="Please enter a new password atleast 5 charcters\n";
			flag=1;
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}
function login_validate()
{
	var msg="There are following error(s) with your submission :\n";
	var flag=0;
	var username=document.form1.ca_admin_users_username.value;
	var password=document.form1.ca_admin_users_password.value;

	if(username=="" || username.length<1)
	{
			msg+="Please Enter username\n";
			flag=1;
	}
	if(password=="" || password.length<5)
	{
			msg+="Please enter a password atleast 5 charcters\n";
			flag=1;
	}
	if(flag==1)
	{
		alert(msg);
		return false;
	}
	return true;
}
function yesno()
{
	if(confirm("Are you sure? You are going to delete the record"))
		return true;
	else
		return false;
}
function admin_validate()
{
	var username=document.form1.ca_members_member_username.value; 
	var password=document.form1.ca_members_member_password.value;
	var re_password=document.form1.ca_members_member_password_again.value;
	var msg="There are following errors to your submission:\n";
	var flag=0;

	if(username=="" || username.length<5)
	{
			msg+="User Name should be minimum 5 chars long\n";
			flag=1;
	}
	if(password=="" || password.length<5)
	{
			msg+="Password field should be minimum of 5 charcters\n";
			flag=1;
	}
	if(password!=re_password)
	{
			msg+="Passwod confirmation not true\n";
			flag=1;
	}
	if(flag==1)
	{
			alert(msg);
			return false;
	}
	return true;
}
function member_validate()
{
	var username=document.form1.ca_members_member_username.value; 
	var email=document.form1.ca_members_member_email.value;
	var name=document.form1.ca_members_member_name.value;
	var surname=document.form1.ca_members_member_surname.value
	
	var address=document.form1.ca_members_member_address.value;
	var city=document.form1.ca_members_member_city.value; 
	var zipcode=document.form1.ca_members_member_zipcode.value;
	//var country=document.form1.ca_members_member_country.value;
	var phone=document.form1.ca_members_member_phone.value;
	
	var password=document.form1.ca_members_member_password.value;
	var re_password=document.form1.ca_members_member_password_again.value;
	
	var msg="There are following errors to your submission:\n";
	var flag=0;
	if(username=="" || username.length<5)
	{
			msg+="User Name should be minimum 5 chars long\n";
			flag=1;
	}
	if(email=="" || isEmail(email))
	{
			msg+="Please Enter a valid email\n";
			flag=1;
	}
	if(name=="" || name.length<1)
	{
			msg+="Please Enter a Name\n";
			flag=1;
	}
	if(surname=="" || surname.length<1)
	{
			msg+="Please Enter a Surname\n";
			flag=1;
	}
	if(address=="" || address.length<1)
	{
			msg+="Please Enter Address\n";
			flag=1;
	}
	if(city=="" || city.length<1)
	{
			msg+="Please Enter a Name\n";
			flag=1;
	}
	if(zipcode=="" || zipcode.length<1 || isNum(zipcode))
	{
			msg+="Please Enter valid Zipcode\n";
			flag=1;
	}
	/*if(country=="-1")
	{
		msg+="Please select a country from list\n";
		flag=1;
	}*/
	if(phone=="" || phone.length<1 || isNum(phone))
	{
			msg+="Please Enter a valid Phone Number\n";
			flag=1;
	}
	if(password=="" || password.length<5)
	{
			msg+="Password field should be minimum of 5 charcters\n";
			flag=1;
	}
	if(password!=re_password)
	{
			msg+="Passwod confirmation not true\n";
			flag=1;
	}
	if(flag==1)
	{
			alert(msg);
			return false;
	}
	return true;
}			
			
function isEmail(val)
{
        // Return false if e-mail field does not contain a '@' and '.' .
        if (val.indexOf ('@',0) == -1 || val.indexOf ('.',0) == -1)
        {
                return 1;
        }
        else
        {
                return 0;
        }
}

function isNum(str)
{
        // Return false if characters are not '0-9' or '.' .
        for (var i = 0; i < str.length; i++)
        {
                var ch = str.substring(i, i + 1);
                if ((ch < "0" || "9" < ch) && ch != '.' && ch != '-')
                {
                        return 1;
                }
        }
        return 0;
}
function isSTR(val){
        var str = val;
        // Return false if characters are not a-z, A-Z, or a space.
        for (var i = 0; i < str.length; i++){
                var ch = str.substring(i, i + 1);
                if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' '){
                return 1;
                }
        }
        return 0;
}

function check_form_list_add_1() {

        var error_message = "The following problem(s) occurred when processing your Listing Add form, please verify and try again:\n";
        var error = 0;
       		
		var online_booking_listing_title = document.listing_add_1.online_booking_listing_title.value;
		var online_booking_listing_description = document.listing_add_1.online_booking_listing_description.value;
		var online_booking_listings_zipcode = document.listing_add_1.online_booking_listings_zipcode.value;
		var online_booking_listings_contact_phone = document.listing_add_1.online_booking_listings_contact_phone.value;
		
		var online_booking_listing_category_id = document.listing_add_1.online_booking_listing_category_id.value;
		
		// Validation for online_booking_listing_title
        if (online_booking_listing_title == "" || online_booking_listing_title.length < 1) {
                error_message = error_message + "Please Enter Title\n";
                error = 1;
        }	


		// Validation for online_booking_listing_description
        if (online_booking_listing_description == "" || online_booking_listing_description.length < 1) {
                error_message = error_message + "Please Enter Description\n";
                error = 1;
        }	


		// Validation for online_booking_listings_zipcode
        if (online_booking_listings_zipcode == "" || online_booking_listings_zipcode.length < 1) {
                error_message = error_message + "Please Enter Zipcode\n";
                error = 1;
        }	


		// Validation for online_booking_listings_contact_phone
        if (online_booking_listings_contact_phone == "" || online_booking_listings_contact_phone.length < 1) {
                error_message = error_message + "Please Enter Phone No.\n";
                error = 1;
        }
		
		// validations for seat booking frequency events
		if(online_booking_listing_category_id=='3') {
	     var f_events = document.listing_add_1.online_booking_listings_frequency_events.value;
			if (f_events == "" ||  isNum(f_events)) {
			 error_message = error_message + "Frequency of events must be a number\n";
			 error = 1;
			}
		 
		} //end if(online_booking_listing_category_id=='3') {

		if (error == 1) {
		 alert(error_message);
		return false;
		 } else {
		 return true;
		}
		
} //end function check_form_list_add_1() {
