// JavaScript Document


/**************************************************Category Manager**********************************************************/

function cat_edit(category_id,page,limit)
{	
	//alert(category_id);
	document.frm_cat_mgmt.action = "cat_add.php?category_id="+category_id+"&page="+page+"&limit="+limit;
	document.frm_cat_mgmt.submit();
}
function cat_save(category_id,page,limit)
{	   	
	if(document.frm_cat_add.category_name.value==''){
		alert('Please enter category name!');
		document.frm_cat_add.category_name.focus();
		return false;
	}if(document.frm_cat_add.category_parent_id.value==''){
		alert('Please select parent category!');
		document.frm_cat_add.category_parent_id.focus();
		return false;
	}else{
		document.frm_cat_add.action = "cat_save.php?category_id="+category_id+"&page="+page+"&limit="+limit;
		document.frm_cat_add.submit();
	}
	
}
function cat_delete(category_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_cat_mgmt.action = "cat_delete.php?category_id="+category_id+"&page="+page+"&limit="+limit;
		document.frm_cat_mgmt.submit();
	}
}

function company_mgmt(category_id){
	
	//alert(category_id);
	document.frm_cat_mgmt.action = "../company_manager/company_mgmt.php?category_id="+category_id;
	document.frm_cat_mgmt.submit();

}

/*******************************************Forum Manager***************************************/

function for_edit(forum_id,page,limit)
{	
	//alert(category_id);
	document.frm_forum_mgmt.action = "forum_add.php?forum_id="+forum_id+"&page="+page+"&limit="+limit;
	document.frm_forum_mgmt.submit();
}
function for_save(forum_id,page,limit)
{	   	
	//alert(page);
	//alert("hiii");
	if(document.frm_forum_add.forum_name.value==''){
		alert('Please enter forum name!');
		document.frm_forum_add.forum_name.focus();
		return false;
	}else{
		document.frm_forum_add.action = "forum_save.php?forum_id="+forum_id+"&page="+page+"&limit="+limit;
		document.frm_forum_add.submit();
	}
	
}
function for_delete(forum_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_forum_mgmt.action = "forum_delete.php?forum_id="+forum_id+"&page="+page+"&limit="+limit;
		document.frm_forum_mgmt.submit();
	}
}

/*******************************************Forum Post Manager***************************************/

function post_edit(forum_id,forum_post_id,page,limit)
{	
	//alert(category_id);
	document.frm_forum_post_mgmt.action = "forum_post_add.php?forum_id="+forum_id+"&forum_post_id="+forum_post_id+"&page="+page+"&limit="+limit;
	document.frm_forum_post_mgmt.submit();
}
function post_save(forum_id,page,limit)
{	   	
	//alert(page);
	//alert("hiii");
	if(document.frm_forum_post_add.forum_post_name.value==''){
		alert('Please enter forum post name!');
		document.frm_forum_post_add.forum_post_name.focus();
		return false;
	}else{
		document.frm_forum_post_add.action = "forum_post_save.php?forum_post_id="+forum_id+"&page="+page+"&limit="+limit;
		document.frm_forum_post_add.submit();
	}
	
}
function post_delete(forum_id,forum_post_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_forum_post_mgmt.action = "forum_post_delete.php?forum_id="+forum_id+"&forum_post_id="+forum_post_id+"&page="+page+"&limit="+limit;
		document.frm_forum_post_mgmt.submit();
	}
}

/*******************************************Forum Comments Manager***************************************/

function post_comment_edit(forum_id,forum_post_id,forum_post_ans_id,page,limit)
{	
	//alert(category_id);
	document.frm_forum_comment_mgmt.action = "forum_comments_add.php?forum_id="+forum_id+"&forum_post_id="+forum_post_id+"&forum_post_ans_id="+forum_post_ans_id+"&page="+page+"&limit="+limit;
	document.frm_forum_comment_mgmt.submit();
}
function post_comment_save(forum_id,page,limit)
{	   	
	//alert(page);
	//alert("hiii");
	if(document.frm_forum_comment_add.forum_post_ans_name.value==''){
		alert('Please enter forum comment name!');
		document.frm_forum_comment_add.forum_post_ans_name.focus();
		return false;
	}else{
		document.frm_forum_comment_add.action = "forum_comments_save.php?forum_post_ans_id="+forum_id+"&page="+page+"&limit="+limit;
		document.frm_forum_comment_add.submit();
	}
	
}
function post_comment_delete(forum_id,forum_post_id,forum_post_ans_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_forum_comment_mgmt.action = "forum_comments_delete.php?forum_id="+forum_id+"&forum_post_id="+forum_post_id+"&forum_post_ans_id="+forum_post_ans_id+"&page="+page+"&limit="+limit;
		document.frm_forum_comment_mgmt.submit();
	}
}

/*******************************************Company Manager*************************************/

function company_edit(company_id,category_id,page,limit)
{
	//alert(category_id);
	document.frm_company_mgmt.action="company_add.php?category_id="+category_id+"&company_id="+company_id+"&page="+page+"&limit="+limit;
	document.frm_company_mgmt.submit();
}
function company_delete(company_id,category_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_company_mgmt.action="company_delete.php?category_id="+category_id+"&company_id="+company_id+"&page="+page+"&limit="+limit;
		document.frm_company_mgmt.submit();	
	}
}

function company_save(company_id,category_id,page,limit)
{
	if(document.frm_company_add.company_name.value==''){
		alert("Please Enter Company Name");
		document.frm_company_add.company_name.focus();
		return false;
	}else if(document.frm_company_add.company_url.value==''){
		alert("Please Enter Company Url");
		document.frm_company_add.company_url.focus();
		return false;
	}
	else{
		document.frm_company_add.action = "company_save.php?category_id="+category_id+"&company_id="+company_id+"&page="+page+"&limit="+limit;
		document.frm_company_add.submit();
	}
}


/*******************************************City Manager*************************************/

function city_edit(city_id,page,limit)
{		
	document.frm_city_mgmt.action = "city_add.php?city_id="+city_id+"&page="+page+"&limit="+limit;
	document.frm_city_mgmt.submit();
}
function city_save(page,limit)
{	
	if(document.frm_city_add.city_name.value==''){
		alert("Please Enter City Name")
		document.frm_city_add.city_name.focus();
		return false;
	}else{
		document.frm_city_add.action = "city_save.php?page="+page+"&limit="+limit;
		document.frm_city_add.submit();
	}
}
function city_delete(city_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_city_mgmt.action = "city_delete.php?city_id="+city_id+"&page="+page+"&limit="+limit;
		document.frm_city_mgmt.submit();
	}
}


/******************************************Property Manager***************************************/

function property_edit(property_id,page,limit)
{
	document.frm_property_mgmt.action="property_add.php?property_id="+property_id+"&page="+page+"&limit="+limit;
	document.frm_property_mgmt.submit();
}
function property_delete(agent_id,property_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_property_mgmt.action="property_delete.php?agent_id="+agent_id+"&property_id="+property_id+"&page="+page+"&limit="+limit;
		document.frm_property_mgmt.submit();	
	}
}

function property_save(property_id,page,limit)
{
	if(document.frm_property_add.city.value==0){
		alert("Select City");
		document.frm_property_add.city.focus();
		return false;
	}else if(document.frm_property_add.property_name.value==''){
		alert("Please Enter Property Name");
		document.frm_property_add.property_name.focus();
		return false;
	}/*else if(document.frm_property_add.property_address.value==''){
		alert("Please Enter Property Address");
		document.frm_property_add.property_address.focus();
		return false;
	}else if(document.frm_property_add.property_post_code.value==''){
		alert("Please Enter Property Postcode");
		document.frm_property_add.property_post_code.focus();
		return false;
	}else if(document.frm_property_add.property_location.value==''){
		alert("Please Enter Property Location");
		document.frm_property_add.property_location.focus();
		return false;
	}/*else if(document.frm_property_add.property_email.value == ""){
		alert("Please Enter Property Email");
		document.frm_property_add.property_email.focus();
		return false;
	}else if(document.frm_property_add.property_email.value.indexOf("@") == -1){
		alert("Please enter valid Email");
		document.frm_property_add.property_email.focus();
		return false;
	}else if(document.frm_property_add.property_email.value.indexOf(".") == -1){
		alert("Please enter valid Email");
		document.frm_property_add.property_email.focus();
		return false;
	}*/
	
	document.frm_property_add.action="property_images.php?page="+page+"&limit="+limit+"&property_id="+property_id;
	document.frm_property_add.submit();
}

/*****************************************************Product Category Manager*************************************************/

function product_category_validate(){
	if(document.frm_product_category_add.product_category_name.value==''){
		alert("Please enter Product Category Name");
		document.frm_product_category_add.product_category_name.focus();
		return false;
	}
	
}

/*****************************************************Notice Board Manager*************************************************/

function notice_board_validate(){
	if(document.frm_notice_board_add.notice_board_name.value==''){
		alert("Please enter Notice Board Name");
		document.frm_notice_board_add.notice_board_name.focus();
		return false;
	}
	
}

function notice_board_edit(notice_board_id,page,limit)
{
	document.frm_notice_board_mgmt.action="notice_board_add.php?notice_board_id="+notice_board_id+"&page="+page+"&limit="+limit;
	document.frm_notice_board_mgmt.submit();
}
function notice_board_delete(notice_board_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_notice_board_mgmt.action="notice_board_delete.php?notice_board_id="+notice_board_id+"&page="+page+"&limit="+limit;
		document.frm_notice_board_mgmt.submit();	
	}
}


/***************************************************Product Manager*******************************************************/

function product_save(product_id,page,limit)
{
	if(document.frm_product_add.product_category.value==''){
		alert("Please select a Product Category");
		document.frm_product_add.product_category.focus();
		return false;
	}else if(document.frm_product_add.product_name.value==''){
		alert("Please enter Product name");
		document.frm_product_add.product_name.focus();
		return false;
	}else if(document.frm_product_add.product_price.value==''){
		alert("Please enter product price");
		document.frm_product_add.product_price.focus();
		return false;
	}
	document.frm_product_add.action="product_save.php?product_id="+product_id+"&page="+page+"&limit="+limit;
	document.frm_product_add.submit();	
}

function product_edit(product_id,page,limit){
	//alert(product_id);
	document.frm_product_mgmt.action="product_add.php?product_id="+product_id+"&page="+page+"&limit="+limit;
	document.frm_product_mgmt.submit();
}

function product_delete(product_id,page,limit){
	document.frm_product_mgmt.action="product_delete.php?product_id="+product_id+"&page="+page+"&limit="+limit;
	document.frm_product_mgmt.submit();
}


/********************************************Page Manager*****************************************/

function change_status(val)
{
	//alert(val);
	if(val=='page_upload'){
		//tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
		document.getElementById('f_upload').style.display='block';
		document.getElementById('text2').style.display='none';
	}else if(val=='text1'){
		//tinyMCE.addMCEControl(document.getElementById('page_desc'),sEditorID);
		document.getElementById('text2').style.display='block';
		document.getElementById('f_upload').style.display='none';
		
	}
}	

function validate_page(page_id,img)
{
	if(document.page_add.page_name.value==''){
		alert("Please enter Page Name");
		document.page_add.page_name.focus();
		return false;
	}else if(document.page_add.page_link.value==''){
		alert("Please enter Page Link");
		document.page_add.page_link.focus();
		return false;
	}else if(document.page_add.parent_id.value==''){
		alert("Please select from Parent Page");
		document.page_add.parent_id.focus();
		return false;
	}
	document.page_add.action="page_save.php?page_id="+page_id+"&page_img="+img;
	document.page_add.submit();
} 

/***********************************************User Manager****************************************/
function user_edit(user_id,page,limit)
{
	document.frm_user_mgmt.action="user_add.php?user_id="+user_id+"&page="+page+"&limit="+limit;
	document.frm_user_mgmt.submit();
}
function user_delete(user_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_user_mgmt.action="user_delete.php?user_id="+user_id+"&page="+page+"&limit="+limit;
		document.frm_user_mgmt.submit();	
	}
}

function user_save(user_id,page,limit)
{
	if(document.frm_user_add.user_type_id.value==0){
		alert("Select User Type");
		document.frm_user_add.user_type_id.focus();
		return false;
	}else if(document.frm_user_add.first_name.value==''){
		alert("Please Enter First Name");
		document.frm_user_add.first_name.focus();
		return false;
	}else if(document.frm_user_add.last_name.value==''){
		alert("Please Enter Last Name");
		document.frm_user_add.last_name.focus();
		return false;
	}else if(document.frm_user_add.email.value == ""){
		alert("Please Enter EmailID");
		document.frm_user_add.email.focus();
		return false;
	}else if(document.frm_user_add.email.value.indexOf("@") == -1){
		alert("Please enter valid Email");
		document.frm_user_add.email.focus();
		return false;
	}else if(document.frm_user_add.email.value.indexOf(".") == -1){
		alert("Please enter valid Email");
		document.frm_user_add.email.focus();
		return false;
	}else{
		var password=document.frm_user_add.password;
		
		if(password.value==""){
			alert("Please enter your password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		
		var pass_string = password.value;		
		var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password contains invalid characters');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="123456789";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password contains only characters. Please enter an alphanumeric	value like -alpha1-');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password contains only numbers. Please enter an alphanumeric value like -alpha1-');
			password.focus();
			return false;
		}

		document.frm_user_add.action="user_save.php?page="+page+"&limit="+limit+"&user_id="+user_id;
		document.frm_user_add.submit();
	}
}

/***********************************************Front side****************************************/

function generate_cart(product_id){
	//alert("dffd");
	document.frm_product_list.action="add_to_cart.php?product_id="+product_id;
	document.frm_product_list.submit();
}

function register(frmpara){
	if(document.frmregister.first_name.value==''){
		alert("Fyll inn fornavn");
		document.frmregister.first_name.focus();
		return false;
	}else if(document.frmregister.last_name.value==''){
		alert("Fyll inn etternavn");
		document.frmregister.last_name.focus();
		return false;
	}else if(document.frmregister.add1.value==''){
		alert("Fyll inn adresse1");
		document.frmregister.add1.focus();
		return false;
	}else if(document.frmregister.add2.value==''){
		alert("Fyll inn adresse2");
		document.frmregister.add2.focus();
		return false;
	}else if(document.frmregister.postcode.value==''){
		alert("Fyll inn postnummer");
		document.frmregister.postcode.focus();
		return false;
	}else if(document.frmregister.location.value==''){
		alert("Fyll inn sted");
		document.frmregister.location.focus();
		return false;
	}else if(document.frmregister.phone1.value==''){
		alert("Fyll inn telefonnummer1");
		document.frmregister.phone1.focus();
		return false;
	}else if(document.frmregister.email.value == ""){
		alert("Fyll inn e-post");
		document.frmregister.email.focus();
		return false;
	}else if(document.frmregister.email.value.indexOf("@") == -1){
		alert("Fyll inn gyldig e-post");
		document.frmregister.email.focus();
		return false;
	}else if(document.frmregister.email.value.indexOf(".") == -1){
		alert("Fyll inn gyldig e-post");
		document.frmregister.email.focus();
		return false;
	}else{
		var password=document.frmregister.pass;
		if(password.value==""){
			alert("Please enter your password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		var pass_string = password.value;		
		var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password contains invalid characters');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="123456789";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password contains only characters. Please enter an alphanumeric	value like -alpha1-');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password contains only numbers. Please enter an alphanumeric value like -alpha1-');
			password.focus();
			return false;
		}
		
		var re_pass=document.frmregister.re_pass.value;
		if(re_pass==''){
			alert("Please retype your password");
			document.frmregister.re_pass.focus();
			return false;
		}
		if(password.value!=re_pass){
			alert("Please retype your password");
			document.frmregister.re_pass.focus();
			return false;
		}

		document.frmregister.action="user_save.php?frmpara="+frmpara;
		document.frmregister.submit();
	}
}

function forgot_pass(){
	document.frmlogin.action="forgot_pass.php";
	document.frmlogin.submit();	
}

function login(){
	document.frmforum.action="login.php?frmpara=forum";
	document.frmforum.submit();
}

function new_post(forum_id){
	document.frmforum.action="post_forum.php?forum_id="+forum_id;
	document.frmforum.submit();	
}

function new_post1(){
	document.frm_post_forum.action="post_forum_save.php";
	document.frm_post_forum.submit();	
}

function forum_post_ans(id,val){
	if(val=='ans'){
		document.frm_forum_ans.action="forum_add_ans.php?forum_post_id="+id+"&val="+val;
		document.frm_forum_ans.submit();	
	}else{
		document.frm_forum_ans.action="post_forum.php?id="+id+"&val="+val;
		document.frm_forum_ans.submit();
	}
}

function forum_ans(id,val){
	document.forum_add_ans.action="forum_ans_save.php?id="+id+"&val="+val;
	document.forum_add_ans.submit();	
}

function update_ans(id,val){
	document.forum_add_ans.action="forum_ans_save.php?forum_post_ans_id="+id+"&val="+val;
	document.forum_add_ans.submit();	
}

function update_post(id){
	document.frm_post_forum.action="post_forum_save.php?forum_post_id="+id;
	document.frm_post_forum.submit();	
}

function ans(id,val){
	if(val=='ans'){
		document.frm_forum_ans.action="forum_add_ans.php?forum_post_id="+id+"&val="+val;
		document.frm_forum_ans.submit();	
	}else{
		document.frm_forum_ans.action="forum_add_ans.php?forum_post_ans_id="+id+"&val="+val;
		document.frm_forum_ans.submit();
	}
}

function property_display(area){
	document.frm_property_display.action="property_display.php?area="+area;
	document.frm_property_display.submit();		
}

function adv_search(area){
	document.frm_left_panel.action="property_display.php?area="+area;
	document.frm_left_panel.submit();		
}

function empty_cart(empty){
	document.frm_view_cart.action="update_cart.php?val="+empty;
	document.frm_view_cart.submit();
}

function check_contact()
{	   	
	if(document.frm_contact.first_name.value==''){
		alert('Fyll inn fornavn!');
		document.frm_contact.first_name.focus();
		return false;
	}else if(document.frm_contact.last_name.value==''){
		alert('Fyll inn etternavn!');
		document.frm_contact.last_name.focus();
		return false;
	}else if(document.frm_contact.email.value==''){
		alert('Fyll inn e-post!');
		document.frm_contact.email.focus();
		return false;
	}else if(document.frm_contact.contact_no.value==''){
		alert('Vennligst oppgi kontakt no!');
		document.frm_contact.contact_no.focus();
		return false;
	}else if(document.frm_contact.message.value==''){
		alert('Angi melding!');
		document.frm_contact.message.focus();
		return false;
	}
	else{
		document.frm_contact.action = "mail_send.php";
		document.frm_contact.submit();
	}
	
}

/************************Add Photo**************************/

function addphoto(id)
{
		document.frm_photo.action="photo_save.php?user_id="+id;
		document.frm_photo.submit();
}

function delete_photo(val)
{
		document.PhotoGallery.action="delete_photo.php?photo_gallery_id="+val;
		document.PhotoGallery.submit(); 
}

/************************Add Comment**************************/

function addcomment(photo_gallery_id)
{
		document.frm_comment.action="comment_save.php?photo_gallery_id="+photo_gallery_id;
		document.frm_comment.submit();
}

/****************************Edit Personal Details*******************************/

function edit_personal_detail(image)
{
	document.frm_edit_details.action="myaccount_save.php?image="+image;
	document.frm_edit_details.submit();		
}

/***************************************Photo Gallery Manager***************/

function photo_save(page,limit)
{	
	document.frm_photo_add.action="photo_gallery_save.php?page="+page+"&limit="+limit;
	document.frm_photo_add.submit();
}

function photo_edit(photo_gallery_id,page,limit){
	//alert(product_id);
	document.frm_photo_mgmt.action="photo_gallery_add.php?photo_gallery_id="+photo_gallery_id+"&page="+page+"&limit="+limit;
	document.frm_photo_mgmt.submit();
}

function photo_delete(photo_gallery_id,page,limit){
	document.frm_photo_mgmt.action="photo_gallery_delete.php?photo_gallery_id="+photo_gallery_id+"&page="+page+"&limit="+limit;
	document.frm_photo_mgmt.submit();
}

/*****************************************Comment Manager*********************/
function comment_save(id,page,limit)
{	
	if(document.frm_comment_add.comment_name.value==''){
		alert('Please enter Comment Name');
		document.frm_comment_add.comment_name.focus();
		return false;
	}else if(document.frm_comment_add.comment_desc.value==''){
		alert('Please enter Description');
		document.frm_comment_add.comment_desc.focus();
		return false;
	}else{
	document.frm_comment_add.action="photo_comment_save.php?page="+page+"&limit="+limit+"&photo_gallery_id="+id;
	document.frm_comment_add.submit();
	}
}

function comment_edit(photo_comment_id,page,limit,id){
	//alert(photo_comment_id);
	document.frm_comment_mgmt.action="photo_comment_add.php?photo_comment_id="+photo_comment_id+"&page="+page+"&limit="+limit+"&photo_gallery_id="+id;
	document.frm_comment_mgmt.submit();
}

function comment_delete(photo_comment_id,id,page,limit){
	document.frm_comment_mgmt.action="photo_comment_delete.php?photo_comment_id="+photo_comment_id+"&page="+page+"&limit="+limit+"&photo_gallery_id="+id;
	document.frm_comment_mgmt.submit();
}