//preload header.jpg
imgPreloader = new Image();
imgPreloader.onload=function(){
	imgPreloader.src = new Image();
}
imgPreloader.src = "image/header.jpg";

function loadMenu(siteKey, menuKey) {
	var divName;
	if (menuKey == 1){
	   divName = "menuLeftDiv";
	   loadMenuLeft();
	}
	else
	if (menuKey == 2){
	   divName = "menuTopDiv";
	   loadMenuTop();
	}
	else
	if (menuKey == 3){
	   divName = "menuRightDiv";
	   loadMenuRight();
	}
	else
	if (menuKey == 4){
	   divName = "menuBottomDiv"
	   loadMenuBottom();
	}	
	
	loadURL("menu/menu-"+siteKey+"-"+menuKey+".html",divName);
    
}

function loadHeader(){
	var headerKey = 1;
	if ( getCookie("headerKey") != null)
		headerKey = getCookie("headerKey");
	loadURL("layout/header-"+headerKey+".html","headerDiv");
}

function setHeader( headerKey ){
	setCookie("headerKey",headerKey);
}

function loadFooter(footerKey){
	loadURL("layout/footer-"+footerKey+".html","footerDiv");
}

function loadContentCategory( categoryKey , divName){
	loadURL("content/category-"+categoryKey+".html",divName);
}

function submitContentCategory( categoryKey , divName){
	location.href="?component=contentCategory&contentCategoryKey="+categoryKey;
}

function loadContent( categoryKey, contentKey, divName){
	loadURL("content/content-"+categoryKey+"-"+contentKey+".html",divName);
}

function submitContent( categoryKey, contentKey, divName){
	location.href="?component=content&contentCategoryKey="+categoryKey+"&contentKey="+contentKey;
}

function loadForm( formKey, divName ){
	loadURL("form/form-"+formKey+".html",divName)
}

function submitForm( formKey, divName ){
	location.href="?component=form&formKey="+formKey;
}

function changeClass( element, className ){
	document.getElementById(element.id).className  = className;
}

function loadGallery(galleryKey,albumKey, divName){
	loadURL("gallery/gallery-"+galleryKey+".html",divName);	
	if (albumKey==0)
		albumKey=1;
	setTimeout("loadAlbum("+galleryKey+","+albumKey+")",500);
}

function submitGallery(galleryKey, albumKey, divName){
	location.href="?component=gallery&galleryKey="+galleryKey+"&albumKey="+albumKey;
}


function loadAlbum(galleryKey, albumKey){
	loadURL("gallery/gallery-"+ galleryKey +"/album-"+ albumKey+".html", "albumContainerDiv");	
	setTimeout("initLightbox();",500);	
}

function setCurrency(){
	document.getElementById("defaultCurrency").innerHTML = " - " + document.getElementById("defaultCurrencyKey").value;
}

function loadProductCategory ( categoryKey ){
	loadURL("product/productContainer.html","contentDiv");
	setTimeout("loadURL('product/category-"+categoryKey+".html','productDiv');",500);
	setTimeout("setHTMLshoppingHeader();",1000);
	setTimeout("setCookie('categoryKey', "+categoryKey+" );",1500)
}

function submitProductCategory ( categoryKey ){
	location.href="?component=productCategory&productCategoryKey="+categoryKey;
}

function loadProduct ( categoryKey, product ){
	loadURL("product/product-"+categoryKey+"-"+product+".html","productDiv");	
	setTimeout("setHTMLshoppingHeader();",500);
	setTimeout("setCurrency();",1000)
}	

function submitProduct ( categoryKey, product ){
	location.href="?component=product&productCategoryKey="+categoryKey+"&productKey="+product;
}

function loadPaymentMethodList ( paymentMethodKey ){
	loadURL("product/paymentMethodList.html","paymentMethodListDiv");	
	loadPaymentMethod ( paymentMethodKey );
}

function loadPaymentMethod ( paymentMethodKey ){
	loadURL("product/paymentMethod-"+paymentMethodKey+".html","paymentMethodDiv");	
	setCookie("paymenthMethodCookie",paymentMethodKey);
}

function loadBuyerInfo (){
	loadURL("product/buyerInfo.html","buyerInfoDiv");
}

function loadShoppingCart (){
	
	loadURL("product/shoppingCart.html","productDiv");	
	setTimeout("initArrayByCookies();",500);
	setTimeout("loadPaymentMethodList(1);",1000);
	setTimeout("loadBuyerInfo();",1500);
}

function submitShoppingCart (){
	location.href="?component=shoppingCart";
}

function postShoppingCart(formAction){
	var paymentMethod = document.getElementById("paymentMethodList");
	var paymentMethodDiv = document.getElementById("paymentMethodDiv").innerHTML ;
	document.shoppingCartForm.action = formAction;
	if (formAction.indexOf("paypal") < 0)
	  document.getElementById("paymentMethodArea").value = "<strong>" + paymentMethod.options[paymentMethod.selectedIndex].text + "</strong><br/>" + paymentMethodDiv;
	document.shoppingCartForm.submit();
 	document.getElementById("paymentMethodArea").value = "";
}

function popContent( contentCategoryKey, contentKey, component, mailFlag){
	var width = 820;
 	var height = 740;
	var url = "pop.html?contentCategoryKey="+contentCategoryKey+"&contentKey="+contentKey+"&component="+component+"&mailFlag="+mailFlag;
	popWindow(url,"popWindow",width,height);
}

function loadInput(){
	loadURL("input.html","inputDiv");		
}

function loadMail(){
	loadURL("mail.html","mailDiv");		
}

function loadHTML(){
	//loadMail();
	setTimeout("loadInput();",250);
	setTimeout("readParameter();",500);
	setTimeout("loadComplete();",750);
}

function loadComplete(){
	var component = document.getElementById("component").value;
	if ( component=="contentCategory" ) {
		var contentCategoryKey = document.getElementById("contentCategoryKey").value;
		loadContentCategory( contentCategoryKey,"contentDiv");
	} 
	else if (component=="content") {
		var contentCategoryKey = document.getElementById("contentCategoryKey").value;
		var contentKey = document.getElementById("contentKey").value;
		loadContent( contentCategoryKey, contentKey, "contentDiv" );
	} 
	else if (component=="gallery") {
		var galleryKey = document.getElementById("galleryKey").value;
		var albumKey = document.getElementById("albumKey").value;
		loadGallery(galleryKey,albumKey, "contentDiv" );
	}
	else if ( component=="productCategory" ) {
		var productCategoryKey = document.getElementById("productCategoryKey").value;
		loadProductCategory( productCategoryKey,"contentDiv");
	} 

	else if ( component=="product" ) {
		var productCategoryKey = document.getElementById("productCategoryKey").value;
		var productKey = document.getElementById("productKey").value;
		loadURL("product/productContainer.html","contentDiv");
		loadProduct ( productCategoryKey, productKey );
	}
	else if (component=="shoppingCart") {
		loadURL("product/productContainer.html","contentDiv");
		loadShoppingCart();
	}
	else if (component=="form") {
		var formKey = document.getElementById("formKey").value;
		loadForm( formKey, "contentDiv" );
	}
	if (document.getElementById("mailFlag").value=="1" && document.getElementById("mailDiv")!=null)
		document.getElementById("mailDiv").style.visibility = "visible";
}

