///////////////////////   AJAX START HERE   //////////////
function makeObject(){
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		x = new XMLHttpRequest();
	}
	return x;
}
var request = makeObject();
function form_select_category(){

    request.open('get','process.php?index_category='+document.add_product.category.options(document.add_product.category.selectedIndex).value+'&key=CATEGORY');
	request.onreadystatechange = form_categroy_combo_filter;
	request.send('');
}

function form_categroy_combo_filter(){
	document.getElementById('form_sub_category_div').innerHTML ="";

	if(request.readyState == 1){
		divStr1+="<option>Loading..</option>";
	}
	
	if(request.readyState == 4){ 
		var answer = request.responseText.split("|");
		var vt=answer[0];
		var mt=answer[1];
	}
	//---- set the sub category combo ----
	var divStr1 ="<select name='sub_category' class='textBox'><option value='0' selected>[SELECT]</option>";
	divStr1+=vt;
	divStr1+="</select>";
	document.getElementById('form_sub_category_div').innerHTML=divStr1;
}
////////////////////////   AJAX end HERE //////////////////////////


function user_login_submit(){
    if(document.login_box.username.value==''){
		alert("Please Enter your user Name");
		document.login_box.username.focus();
		return false;
	}    
	if(document.login_box.password.value==''){
		alert("Please Enter the password");
		document.login_box.password.focus();
		return false;
	}
	document.login_box.action="result.php?func_val=LOGIN&key_val=user";
	document.login_box.submit();
	return true;
}
function user_login_submit2(){
    if(document.user_login.username.value==''){
		alert("Please Enter your user Name");
		document.user_login.username.focus();
		return false;
	}    
	if(document.user_login.password.value==''){
		alert("Please Enter the password");
		document.user_login.password.focus();
		return false;
	}
	document.user_login.action="result.php?func_val=LOGIN&key_val=user";
	document.user_login.submit();
	return true;
}
function user_logout_submit(){

	document.login_box.action="result.php?func_val=LOGOUT&key_val=user";
	document.login_box.submit();
	return true;
}

function admin_login_submit(){
    if(document.admin_login.user_name.value==''){
		alert("Please Enter your user Name");
		document.admin_login.user_name.focus();
		return false;
	}    
	if(document.admin_login.password.value==''){
		alert("Please Enter the password");
		document.admin_login.password.focus();
		return false;
	}
	document.admin_login.action="result.php?func_val=LOGIN&key_val=admin";
	document.admin_login.submit();
	return true;
}

function add_category_submit(){
    if(document.add_category.category.value==''){
		alert("Please Enter the New Category Name");
		document.add_category.category.focus();
		return false;
	}
	document.add_category.action="result.php?func_val=ADD&key_val=category";
	document.add_category.submit();
	return true;
}
function add_news_submit(){
    if(document.add_news.title.value==''){
		alert("Please Enter the Title of the news");
		document.add_news.title.focus();
		return false;
	}    
	if(document.add_news.news.value==''){
		alert("News content cannot be blank ");
		document.add_news.news.focus();
		return false;
	}
	document.add_news.action="result.php?func_val=ADD&key_val=news";
	document.add_news.submit();
	return true;
}
function edit_news_submit(){
    if(document.edit_news.title.value==''){
		alert("Please Enter the Title of the news");
		document.edit_news.title.focus();
		return false;
	}    
	if(document.edit_news.news.value==''){
		alert("News content cannot be blank ");
		document.edit_news.news.focus();
		return false;
	}
	document.edit_news.action="result.php?func_val=EDIT&key_val=news";
	document.edit_news.submit();
	return true;
}

function add_sub_category_submit(){
    if(document.add_sub_category.sub_category.value==''){
		alert("Please Enter the New Sub Category Name");
		document.add_sub_category.sub_category.focus();
		return false;
	}
	document.add_sub_category.action="result.php?func_val=ADD&key_val=sub_category";
	document.add_sub_category.submit();
	return true;
}
function edit_colors_submit(){
	document.edit_colors.action="result.php?func_val=EDIT&key_val=Colors";
	document.edit_colors.submit();
	return true;
}
function edit_sizes_submit(){
	document.edit_sizes.action="result.php?func_val=EDIT&key_val=Sizes";
	document.edit_sizes.submit();
	return true;
}
function edit_brands_submit(){
	document.edit_brands.action="result.php?func_val=EDIT&key_val=Brands";
	document.edit_brands.submit();
	return true;
}
function edit_prices_submit(){
	document.edit_prices.action="result.php?func_val=EDIT&key_val=Price";
	document.edit_prices.submit();
	return true;
}

function order_product_form_submit(){
    if(document.order_form.quantity.value==''){
		alert("Please Enter Quantity ..");
		document.order_form.quantity.focus();
		return false;
	}
	if(document.order_form.quantity.value < document.order_form.min_quantity.value){
		alert("Quantity cannot be less than Minimum Purchase Quantity ");
		document.order_form.quantity.focus();
		return false;
	}
	document.order_form.action="order_quote.php";
	document.order_form.submit();
	return true;
}

function add_product_submit(){
    if(document.add_product.category.value==0){
		alert("Please select a Category");
		document.add_product.category.focus();
		return false;
	}
    if(document.add_product.code.value==''){
		alert("Please Enter code for the product");
		document.add_product.code.focus();
		return false;
	}
    if(document.add_product.name.value==''){
		alert("Please Enter name for the product");
		document.add_product.name.focus();
		return false;
	}
	document.add_product.action="result.php?func_val=ADD&key_val=product";
	document.add_product.submit();
	return true;
}

function edit_product_submit(){
    if(document.add_product.sub_category.value==0){
		alert("Please select a SUB Category");
		document.add_product.category.focus();
		return false;
	}
    if(document.add_product.code.value==''){
		alert("Please Enter code for the product");
		document.add_product.code.focus();
		return false;
	}
    if(document.add_product.name.value==''){
		alert("Please Enter name for the product");
		document.add_product.name.focus();
		return false;
	}
	document.add_product.action="result.php?func_val=EDIT&key_val=product";
	document.add_product.submit();
	return true;
}

function image_add_submit(){
    if(document.add_image.image_name.value==''){
		alert("Please select an Image");
		document.add_image.image_name.focus();
		return false;
	}
	document.add_image.action="result.php?func_val=ADD&key_val=image";
	document.add_image.submit();
	return true;
}
function edit_category_submit(){
    if(document.edit_category.category.value==''){
		alert("Category field cannot be blank !");
		document.edit_category.category.focus();
		return false;
	}
	document.edit_category.action="result.php?func_val=EDIT&key_val=category";
	document.edit_category.submit();
	return true;
}

function search_submit(){
    if(document.search_box.value.value==''){
		alert("Please enter a word or phrase !");
		document.search_box.value.focus();
		return false;
	}
	document.search_box.action="search.php";
	document.search_box.submit();
	return true;
}

function edit_country_submit(){
    if(document.edit_country.country.value==''){
		alert("Country field cannot be blank !");
		document.edit_country.country.focus();
		return false;
	}
	document.edit_country.action="result.php?func_val=EDIT&key_val=country";
	document.edit_country.submit();
	return true;
}

function edit_sub_category_submit(){
    if(document.Edit_Category.sub_Category.value==''){
		alert("SUBCategory field cannot be blank !");
		document.Edit_Category.sub_Category.focus();
		return false;
	}
	document.Edit_Category.action="result.php?func_val=EDIT&key_val=sub_category";
	document.Edit_Category.submit();
	return true;
}

function edit_city_submit(){
    if(document.edit_city.city.value==''){
		alert("City field cannot be blank !");
		document.edit_city.city.focus();
		return false;
	}
	document.edit_city.action="result.php?func_val=EDIT&key_val=city";
	document.edit_city.submit();
	return true;
}

function user_register_submit(){
    if(document.new_user_signup.first_name.value==''){
		alert("Name field cannot be blank !");
		document.new_user_signup.first_name.focus();
		return false;
	}
	if(document.new_user_signup.surname.value==''){
		alert("Surname field cannot be blank !");
		document.new_user_signup.surname.focus();
		return false;
	}
    if(document.new_user_signup.address.value==''){
		alert("Address field cannot be blank !");
		document.new_user_signup.address.focus();
		return false;
	}
    if(document.new_user_signup.telephone.value==''){
		alert("Telephone field cannot be blank !");
		document.new_user_signup.telephone.focus();
		return false;
	}
    if(document.new_user_signup.e_mail.value==''){
		alert("E mail field cannot be blank !");
		document.new_user_signup.e_mail.focus();
		return false;
	}
    if(document.new_user_signup.username.value==''){
		alert("Please enter a username!");
		document.new_user_signup.username.focus();
		return false;
	}    
	if(document.new_user_signup.e_mail.value!=document.new_user_signup.confirm_email.value){
		alert("email mismatch - enter again !!!");
		document.new_user_signup.confirm_email.value="";
		document.new_user_signup.confirm_email.focus();
		return false;
	}		
	document.new_user_signup.action="result.php?func_val=ADD&key_val=new_user";
	document.new_user_signup.submit();
	return true;
}


function update_user_form_submit(){
    if(document.update_my_account.name.value==''){
		alert("Name field cannot be blank !");
		document.update_my_account.name.focus();
		return false;
	}
	if(document.update_my_account.user_name.value==''){
		alert("username field cannot be blank !");
		document.update_my_account.username.focus();
		return false;
	}
    if(document.update_my_account.password.value==''){
		alert("password field cannot be blank !");
		document.update_my_account.password.focus();
		return false;
	}
	if(document.update_my_account.password.value!=document.update_my_account.conf_password.value){
		alert("Password mismatch - enter again !!!");
		document.update_my_account.conf_password.value="";
		document.update_my_account.password_conf.focus();
		return false;
	}		
	document.update_my_account.action="result.php?func_val=EDIT&key_val=update_user";
	document.update_my_account.submit();
	return true;
}

function register_business_submit(){
    if(document.reg_business.business_name.value==''){
		alert("Business Name field cannot be blank !");
		document.reg_business.business_name.focus();
		return false;
	}
	document.reg_business.action="result.php?func_val=ADD&key_val=new_business";
	document.reg_business.submit();
	return true;
}

function search_box_submit(){
    if(document.search_box.keywords.value==''){
		alert("Keyword cannot be blank !");
		document.search_box.keywords.focus();
		return false;
	}
	document.search_box.action="result.php?func_val=SEARCH";
	document.search_box.submit();
	return true;
}
function submit_get_password(){
    if(document.lost_password.email.value==''){
		alert("Please enter your email  !");
		document.lost_password.email.focus();
		return false;
	}
	document.lost_password.action="result.php?func_val=GET&key_val=password";
	document.lost_password.submit();
	return true;
}
//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)
