//photo loader function
function photoLoader(image,width,height){
	var maxWidth=screen.width-110
	var maxHeight=screen.height-110
	 //formatting image within limits
	if(width>maxWidth || height>maxHeight){
		if(maxWidth*height/width<=maxHeight){	
			height=Math.round(maxWidth*height/width)
			width=maxWidth
		} else {
			width=Math.round(maxHeight*width/height)
			height=maxHeight
		}
	}

	var imageURL=image
	var windowW=width
	var windowH=height
	// set the screen position where the popup should appear
	var windowX = (screen.width/2)-(windowW/2);
	var windowY = (screen.height/2)-(windowH/2);
	// set this to true if the popup should close
	// upon leaving the launching page; else, false
	var autoclose = true
	var s = "width="+windowW+",height="+windowH;
	//
	var popVDS="photoholder.asp?imageURL="+imageURL+"&width="+width+"&height="+height
	var popWindow=window.open(popVDS,"sitephotos","scrollbars=no,"+s)
	popWindow.blur()
	window.focus() 
	popWindow.resizeTo(windowW,windowH)
	popWindow.moveTo(windowX,windowY)

	popWindow.focus()   
	if (autoclose){
		window.onunload = function(){
			if (popWindow && popWindow.open && !popWindow.closed){
				popWindow.opener = null;
				popWindow.close()
			}
			
		}
	}
}
//PAGE POPUP WINDOW SCRIPT
function pageLoader(page,width,height,name){
	// set this to true if the popup should close
	// upon leaving the launching page; else, false
	var autoclose = true
	var maxWidth=screen.width;
	var maxHeight=screen.height;
		//formatting image within limits
	if(width>maxWidth || height>maxHeight){
		if(maxWidth*height/width<=maxHeight){	
			height=Math.round(maxWidth*height/width);
			width=maxWidth;
		} else {
			width=Math.round(maxHeight*width/height);
			height=maxHeight;
		}
	}
	var windowW=width;
	var windowH=height;
	// set the screen position where the popup should appear
	var windowX = (screen.width/2)-(windowW/2);
	var windowY = (screen.height/2)-(windowH/2);
	var s = "width="+windowW+",height="+windowH;
	//name of app
	pageName=name
	//
	var pageVDS=page;
	var pageWindow=window.open(pageVDS,pageName,"scrollbars=no,status=no,"+s);
	pageWindow.blur();
	window.focus();
	pageWindow.resizeTo(windowW,windowH);
	pageWindow.moveTo(windowX,windowY);
	pageWindow.focus();
	
	if (autoclose){
		window.onunload = function(){
			if (pageWindow && pageWindow.open && !pageWindow.closed){
				pageWindow.opener = null;
				pageWindow.close();
			}
			
		}
	}
}
//NEWSLETTER SUBSCRIPTION
function checkEmail(){
	//Check for an e-mail address and that it is valid
	if ((document.frmNewsletter.email.value == "") || (document.frmNewsletter.email.value.length > 0 && (document.frmNewsletter.email.value.indexOf("@",0) == - 1 || document.frmNewsletter.email.value.indexOf(".",0) == - 1))) {
  		msg = "____________________________________________________________________\n\n";
		msg += "Your submission has failed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "____________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		msg += "\n\tEmail Address \t- Please enter your valid email address";
		errorMsg=msg;
		alert(errorMsg);
		document.frmNewsletter.email.focus();
	} else {
		document.frmNewsletter.submit();
	}
}
//SEARCH ENGINE
function checkSearch() {
	var errorMsg = "";
	if (document.frmSearch.search.value==""){
		errorMsg += "\n\tSearch \t- Please enter at least one word to search for";
	}
	if (errorMsg != ""){
		msg = "____________________________________________________________________\n\n";
		msg += "Your Search of our website has failed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "____________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";

		errorMsg += alert(msg + errorMsg + "\n\n");
		document.frmSearch.search.focus();
		//return false;
	} else {
		if(document.frmSearch.sitesearch.length>-1){
			for(i=0;i<document.frmSearch.sitesearch.length;i++){
				if(document.frmSearch.sitesearch[i].checked){
					sitesearch=document.frmSearch.sitesearch[i].value;
				}
			}
		} else {
			sitesearch=document.frmSearch.sitesearch.value;
		}
		if(sitesearch=="JAKO" ){
			document.frmSearch.action="search.asp";
			document.frmSearch.method="get";
			document.frmSearch.submit();
		} else {
			searchUrl="google.asp?q=" + document.frmSearch.search.value + "&domains=" + document.frmSearch.domains.value + "&sitesearch=" + sitesearch;
			window.open(searchUrl);
			return false;
		}
	}
}
//BUTTON TOOLTIP FOR DEFAULT BUTTONS
function buttonTip(section,selected){
	var tipText="jakoproductions.com";
	tipText+="<br /><strong>"+section.toUpperCase()+"</strong>";

	//if this is the active site section
	if(selected){
		tipText+="<br />Browse this section with the floating menu above.";
	}

	//show tooltip
	showtip(tipText);
}
