//------------------------------------------------------------------------------------------------------------------------------------------
// Message declaration
//------------------------------------------------------------------------------------------------------------------------------------------
//General
	var enternumbersonly_message = "Please Enter Numbers Only";
	var loading_info_message = "loading data please wait...";
	var enter_value_greater_than_zero_message = "Please enter a value greater than zero";
	
//Basket area
	var emptybasket_message = "Are you sure you want to empty the basket?";

//Used when the submit button is clicked in the checkout page - file "process_checkout.js"
	var less_order_value_message = "Sorry! We are unable to proceed with your order as the net value total is less than our minimum order value";
	var less_order_value_message1 = "\n\nYou can either add more items to make up the minimum order value now, or your basket will be automatically saved for the next 30 days so that you can combine this order with other items later.";

//Used when the delivery details are entered as new or edit
	var order_no_message = "Please enter your order number";
	var contact_name_message = "Please enter a contact name";
	var contact_teleno_message = "Please enter a contact telephone number";
	var delivery_to_message = "Please enter a 'delivery to'";
	var address1_message = "Please enter an address1";
	var valid_email_id_message = "Please enter a valid Email address ...!";
	var town_message = "Please enter a town";
	var county_message = "Please enter a county";
	var country_message = "Please enter a country";
	var postcode_message = "Please enter a postcode";

	var delivery_name_message = "Please enter a delivery name";
	var select_delivery_address_message = "Please select a delivery address";
	var select_delivery_contact_message = "Please select a delivery contact";
	var select_country_message = "Please select a country";

//checking for the duplication; 
	var contact_name_and_telno_already_exists_message = "This Contact Name & telephone number already exists!";
	var delivery_address_exists_message = "This delivery address already exists!";

//When the submit button is clicked during the site is in the maintenance mode. 
	var select_developer_contact_mail_ids_message = "Please Select developer Email address...!";

//From the MPK process
	var new_mpk_message = "Please Enter an 'MPK name'";
	var select_mpk_message = "Please select an 'MPK Name'";

	var new_employee_name_message = "Please Enter an Employee Name";
	var new_employee_code_message = "Please Enter an Employee Code";
	var new_description_message = "Please Enter a Description";

	var mpkdelete_confirmation_message = "Are you sure you want to delete this MPK?";
	var mpkdelete_productlist_message = "Are you sure you want to delete this product from the MPK?";
	var del_addrs_message = "Are you sure you want to delete this delivery address?";
	var del_contact_message = "Are you sure you want to delete this delivery contact?";
	var reordermsg = "All items successfully added to your basket";
	var basket_product_del_message = "Are you sure you want to delete this product from your basket?";

	var discontinue_MPK_products_message = "The following MPK products have been discontinued, and are no longer available";
	/*var discontinue_MPK_products_message1 = "Discontinued products will not be added to the basket when you click 'Add MPK to Basket'.  Please choose alternative product(s) from the catalogue, if required, after clicking the 'Add MPK to Basket'.\n\nYour MPK contains products that have now been discontinued.  Please update your MPK by removing the discontinued products, and replacing them with alternative product(s).";*/

	var discontinue_MPK_products_message1 = "Discontinued products will not be added to the basket when you click 'Add MPK to Basket'.  Please choose alternative product(s) from the catalogue, if required, after clicking the 'Add MPK to Basket'.";
	
	var delete_delivery_address_message = "Are you sure you wish to delete this address from the list";
	
	var mpk_update_message = "MPK Update Completed";
	
//During manager approval
	var user_manager_approval_message = "Please Approve the User Order Request.....!";

//During adding item to the basket; during ordering
	var add_item_to_basket_message = "Please add at least one product to your basket";

//During the login form validation
	var login_username_message = "Please Enter Your Username";
	var login_valid_username_message = "Please Enter a Valid Username...!";
	var login_password_message = "Please Enter Your Password";

//Contact us form validation
	var contactus_name_message = "Please Enter Your Name";
	var contactus_telno_message = "Please Enter a Telephone Number";
	var contactus_email_message = "Please Enter an Email address";

//Change password form validation
	var changepwd_existing_pwd_message = "Please enter your existing password";
	var changepwd_new_pwd_message = "Please enter your new password";
	var changepwd_confirm_pwd_message = "Please confirm your password";
	var changepwd_confirm_pwd_message1 = "Your new passwords do not match";
	var changepwd_atleast_six_chars_message = "Please enter at least 6 characters for your new password";
	
//Historical order display
	var historical_discontinue_products_message = "The following products have been discontinued, and are no longer available";
	var historical_discontinue_products_message1 = "Discontinued products will not be added to the basket in the event of a 'reorder'. Please choose an alternative product(s) from the catalogue, if required, after the 'reorder' items have been added to the basket.";
	
	var select_historical_employee_message = "Please Select Historical Orders or Historical Orders by Employee";
//------------------------------------------------------------------------------------------------------------------------------------------

function showHelpInfo(mod) {

	if(mod == 1) {
		$j('#helpinfo').slideUp();
	}
	else {
		$j('#helpinfo').slideDown();
	}	
}

function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.form;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.form.boxchecked.value = n2;
	} else {
		document.form.boxchecked.value = 0;
	}
}
function sessionTimeOut() {
	document.forms[0].action = 'index.php';
	document.forms[0].target = "_self";
	document.forms[0].submit();
}


function validate_user(){
	var email = $j("#email_id").val().replace(/^\s*|\s*$/,"");
	var password =  $j("#password").val().replace(/^\s*|\s*$/,"");	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;	
	
	if(email=='') {
		alert(login_username_message);
		document.getElementById('email_id').focus();
		return false;
	}
	if(email!=''){
		var mailval=filter.test(email);
		if(!mailval){
			alert(login_valid_username_message);
			document.getElementById('email_id').focus();
			return false;
		}
	}
	if(password==''){
		alert(login_password_message);
		document.getElementById('password').focus();
		return false;
	}
}
	
	
function main_page(type){
    var url;
	$j("#loading-mask").show();	
	if(type=='help'){
		$j.ajax({
		type: "GET",
		url: "help.php",
		success: function(msg){
			if(msg != 'session_timed_out') {
				 $j("#content").html(msg);
				 $j("#loading-mask").hide();	
			}
			else {
				 sessionTimeOut();
			}
		 }
		});	
	}
}

function validate_contact_us_form(){
	
	var name = $j("#realname").val().replace(/^\s*|\s*$/,"");
	var company =  $j("#Company").val().replace(/^\s*|\s*$/,"");	
	var telephone =  $j("#Tel").val().replace(/^\s*|\s*$/,"");
	var email =  $j("#email2").val().replace(/^\s*|\s*$/,"");
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;	
	var err =0 ;
	
	if(name=='') {
		err =1;
		alert(contactus_name_message);
		document.getElementById('realname').focus();
		return false;
	}
	if(telephone==''){
		err =1;
		alert(contactus_telno_message);
		document.getElementById('Tel').focus();
		return false;
	}
	
	if(email==''){
		err =1;
		alert(contactus_email_message);
		document.getElementById('email2').focus();
		return false;
	}
	if(email!=''){
		var mailval=filter.test(email);
		if(!mailval){
			err =1;
			alert(valid_email_id_message);
			document.getElementById('email2').focus();
			return false;
		}
	}
	if(err ==0){
		saveForm();
	}
}


function saveForm() {
    var fullName = $j("#realname").val();
    var companyName = $j("#Company").val();
	var address = $j("#Address").val();
	var telephone = $j("#Tel").val();
	var email = $j("#email2").val();
	var enquiry = $j("#Enquiry").val();
	var request_catalogue = document.getElementById('Catalogue').checked ;
	if(request_catalogue==true){
		request_catalogue = 'Yes';
	}
	else{
		request_catalogue = 'NO';
	}
	
	$j.ajax({
	type: "GET",
	url: "process/enquiry.php",
	data:{
				   action : "send",
				   fullName : fullName, 
				   companyName : companyName,
				   address : address,
				   telephone : telephone,
				   email : email,
				   enquiry : enquiry,
				   request_catalogue : request_catalogue
			},
	success: function(msg){
		
			 $j("#content").html(msg);
	 }
	});	
}

function changepassword() {
	var existpwd = $j("#exist_pwd").val();
	var newpwd = $j("#new_pwd").val();
	var newpwdLen = newpwd.length;
	
	var confirm_pwd = $j("#confirm_pwd").val();

	if(existpwd == '') {
		alert(changepwd_existing_pwd_message);
		document.getElementById("exist_pwd").focus();
		return false;
	}

	if(newpwd == '') {
		alert(changepwd_new_pwd_message);
		document.getElementById("new_pwd").focus();
		return false;
	}

	if(newpwdLen < 6) {
		alert(changepwd_atleast_six_chars_message);
		document.getElementById("new_pwd").focus();
		return false;
	}	
	
	if(confirm_pwd == '') {
		alert(changepwd_confirm_pwd_message);
		document.getElementById("confirm_pwd").focus();
		return false;
	}	
	
	if(newpwd != confirm_pwd) {
		alert(changepwd_confirm_pwd_message1);
		document.getElementById("confirm_pwd").focus();
		return false;
	}

	$j.ajax({
	type: "GET",
	url: "mpk.php",
	data:{
	   action : "changepassword",
	   newpwd : newpwd, 
	   confirm_pwd : confirm_pwd,
	   existpwd : existpwd
	},
	success: function(msg){
		alert(msg);
		$j("#exist_pwd").val('');
		$j("#new_pwd").val('');
		$j("#confirm_pwd").val('');
	 }
	});	
}
function showChangePwdForm(divId, displayStyle) {
	
	if(displayStyle == 'show') {
		$j("#"+divId).show();
	}
	else {
		$j("#"+divId).hide();
	}
}

/*
Global_functions.js
-------------------------
showHelpInfo
checkAll
sessionTimeOut
validate_user
main_page
validate_contact_us_form
saveForm
changepassword
showChangePwdForm


addAddress.js
-----------------
addNewData
addNewForm
hideShowForm
saveNewContactInfos


historical_detail.js
----------------------
printEmp_Orders
historicalOrders
showHide
reOrderProduct
historicalOrders_Emp
selectPopup
historical_statuschange

menu.js
-----------
showSubCategories
menu_listing
menu_change
displayInfo


mpk.js
------------
view_delivery_address
hidepopup
mpk_product_details
AddNewMPK
add_mpk
process_mpk
update_mpk_details
select_cart_descripton
get_empname_code
addmpk_basket
display_mpk_details
AddMPKproducts
delivery_address
edit_delivery_address
del_delivery_address1
cancel1
update_edit_details
updatedeliveryDetails
deletedeliveryaddress
checkalreadyExistContactNAme
checkalreadyExistGroupaddress

process_checkout.js
--------------------------
display_your_basket_details
emptyBasket
display_checkout_form_address
add_quantity
back_to_basket


product_listing.js
-------------------
generateAjaxPaging1
generateAjaxPaging
showproductinfo
toSetDynamicPopUpPos1
ShowModalWindow
closeDiv
addToCart
*/

	
	
