// JavaScript Document
//loading image (the circle spinning)
var loadIMG='<img src="images/icons/loading.gif" style="padding-left:150px;" width="235" height="235" />'; //loading circle img

//top menu that shows product categories _ show that menu
function products_submenu_show(){
		document.getElementById("top_nav_products_submenu").style.display='block';
		document.getElementById("top_nav_other_links_container").style.display='none';	
		document.getElementById("screen_fade_out").style.display='block';
}

//top menu that shows product categories _ hide that menu
function products_submenu_hide(){
		document.getElementById("top_nav_products_submenu").style.display='none';
		document.getElementById("top_nav_other_links_container").style.display='block';
		document.getElementById("screen_fade_out").style.display='none';
}

//javascript email validater
function validate_email(email){
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (email.search(emailRegEx) == -1) { return false; } else {return true;}
}

//contact form ----------------------------------------------------------------------------------------
function contact_form(){
	//check fields for missing data
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var message = document.getElementById('message').value;
	var newsletter = document.getElementById('newsletter').checked;

	if(validate_email(document.getElementById('email').value)==false){
	alert("Please enter a valid email address!");
	} else if (name == "" || message == ""){
	alert("Some required information is missing in the form! Please confirm!");	
	} else {
			if(window.XMLHttpRequest){ var xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
			var url = 'scripts/contact.php?name='+name+'&email='+email+'&message='+message+'&newsletter='+newsletter;
			xhr.open("GET",url,true); xhr.send(null);
			xhr.onreadystatechange=function(){
				if(xhr.readyState==2){ document.getElementById("contact_form").innerHTML=loadIMG; } else if(xhr.readyState==4){
					document.getElementById("contact_form").innerHTML=xhr.responseText;
				}
			}
	}
} 
//contact form ----------------------------------------------------------------------------------------

//load all products within each category ----------------------------------------------------------------------------------------
function loadCat(category){
	if(window.XMLHttpRequest){ var xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
	var url = 'scripts/load_index_categories.php?cat='+category;
	xhr.open("GET",url,true); xhr.send(null);	
	xhr.onreadystatechange=function(){
		if(xhr.readyState==2){ document.getElementById("products_page_content").innerHTML=loadIMG; } else if(xhr.readyState==4){
			document.getElementById("products_page_content").innerHTML=xhr.responseText;
		}
	}
}
//load all products within each category ----------------------------------------------------------------------------------------

//load each product details ----------------------------------------------------------------------------------------
function loadProduct(pID){
	if(pID>0) {
	if(window.XMLHttpRequest){ var xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
	var url = 'scripts/load_index_products.php?ID='+pID; xhr.open("GET",url,true); xhr.send(null);
	xhr.onreadystatechange=function(){
		if(xhr.readyState==2){
			document.getElementById("products_page_content").innerHTML=loadIMG;
		} else if(xhr.readyState==4){
			document.getElementById("products_page_content").innerHTML=xhr.responseText;
		}
	}	
	}
}
//load each product details ----------------------------------------------------------------------------------------

//product print view
function print_view(ID){
window.open ("scripts/print_view.php?ID="+ID+"","IMG IMPORTS: PRINT","status=0,toolbar=1,height=600,width=600");
}

//index promotion image changer
function index_promotion_image_changer(img,url){
	document.getElementById("index_promotion_image").innerHTML='<a href="'+url+'" ><img border=0 src="images/index_promotions/'+img+'" /></a>';
}
