function log() {
	if(window.console) {
		window.console.log([].slice.call(arguments));
	}
};

function validate() {
    if ( 
    	document.forms['o'].elements['Company'].value == "" ||
    	document.forms['o'].elements['LastName'].value == "" ||
    	document.forms['o'].elements['Street'].value == "" ||
    	document.forms['o'].elements['City'].value == "" ||
    	document.forms['o'].elements['OfficePhone'].value == "" ||
    	document.forms['o'].elements['EMailAddress'].value == "") {
        alert('Täytä kaikki * merkityt kentät!');
        return false;
    }
    else
        return true;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getElement(id,win)
{
	doc = win ? win.document : document;
	elem = doc.getElementById ? doc.getElementById(id) : doc.all[id];
	/*
	if (!elem)
		alert("element " + id + " not found");
	else
		alert(id + "found");	
	*/
	return elem;
}

function cs(catalog, category, name) {
	f = getElement("f", window.top.left.criteria);
	cc = getElement("cc", window.top.left.criteria);
	if ( cc )
		cc.value = catalog;
	cg = getElement("cg", window.top.left.criteria);
	if ( cg )
		cg.value = category;
	cn = getElement("cn", window.top.left.criteria);
	if ( cn )
		cn.value = name;
	f.submit();
}

function rs() {
	cc = getElement("cc");
	if ( cc )
		cc.value = "";
	cg = getElement("cg");
	if ( cg )
		cg.value = "";
	cn = getElement("cn");
	if ( cn )
		cn.value = "";
}

function setTitle(id) {
	to = getElement(id, window.top.title);
	from = getElement(id);
	if ( to && from )
		to.innerHTML = from.innerHTML;
}

function cnv(id) {
	to = getElement(id, window.top.title);
	if ( to )
		to.innerHTML = "";
}

function setTitleB(id) {
	from = getElement(id, window.top.view);
	to = getElement(id);
	if ( to && from )
		to.innerHTML = from.innerHTML;
}


function clrs() {
	cc = getElement("cc", window.top.left.criteria);
	//alert(cc);
	if ( cc )
		cc.value = "";
	cg = getElement("cg", window.top.left.criteria);
	if ( cg )
		cg.value = "";
	cn = getElement("cn", window.top.left.criteria);
	if ( cn )
		cn.value = "";
	ct = getElement("ct", window.top.left.criteria);
	if ( ct )
		ct.value = "";

	ca = getElement("ca", window.top.left.criteria);
	if ( ca )
		ca.selectedIndex = 0;

	ck = getElement("ck", window.top.left.criteria);
	if ( ck )
		ck.selectedIndex = 0;

	/*
	cu = getElement("cu", window.top.left.criteria);
	if ( cu )
		cu.checked = false;
	*/

}

function rlt(width, height) {
	//window.top.title.location.reload(true);
	// window.top.title.location = "title.jsp";
	if ( width && height ) {
		window.top.title.location = "title.jsp?width=" + width + "&height=" + height;
	} else {
		window.top.title.location = 'title.jsp';
	}
}

function issx(size, width, height) {
	var categoryWidth   = 251;
	var rowsOverLoad	= 2;
	var tambow 			= 12;
	var win = window.top.view
	var t = String(window.top.view.location);
	if  (t.indexOf("Search") > 0 || t.indexOf("Grid") > 0) {

		var X = (width - categoryWidth) / (size+tambow);
		var cols = Math.floor( X );

		var X = height / (size+tambow);
		var rows = Math.floor( X ) * rowsOverLoad;

		var l = 'Grid.jsp?imageSize=' + size + "&cols=" + cols + "&rows=" + rows;
		//alert( "W=" + w(win) + " H=" + h(win) + " L=" + l);
		window.top.view.location = l;
	}
}

	function w(win) {
		try {
			if ( window.innerWidth ) 
				return win && win.innerWidth ? win.innerWidth : window.innerWidth;
			 else 
			 	if ( document.documentElement && document.documentElement.clientWidth) {
					return document.documentElement.clientWidth;
				} else {
					return document.body.clientWidth;
				}
	    } catch (E) { return 800; }
	}

	function h(win) {
		try {
			if ( window.innerHeight )
				return win && win.innerHeight ? win.innerHeight : window.innerHeight;
			 else 
			 	if ( document.documentElement && document.documentElement.clientHeight) {
					return document.documentElement.clientHeight;
				} else {
					return document.body.clientHeight;
				}
	    } catch (E) { return 600; }
	}




function dob(width, height) {
	if ( width && height ) {
		window.top.left.location = "order.jsp?swidth=" + width + "&sheight=" + height;
		window.top.view.location = "Basket.jsp?swidth=" + width + "&sheight=" + height;
	} else {
		window.top.view.location = 'Basket.jsp';
		window.top.left.location = 'order.jsp';
	}
}

function dog(width, height) {
	width = 800 || w(window.top);
	height = 600 || h(window.top);
	
	//log( "W:" + w(window.top) );
	
	//log( "H:" + h(window.top) );

	if ( width && height ) {
		window.top.left.location = "left.jsp?width=" + width + "&height=" + height;
		window.top.view.location = "Grid.jsp?swidth=" + width + "&sheight=" + height;
	} else {
		window.top.left.location = 'left.jsp';
		window.top.view.location = 'Grid.jsp';
	}
}

function eb() {
	alert('Tilauskori on tyhjä');
}

function shf() {
	f = getElement("form");
	if ( f.style.display == 'none' ) {
		f.style.display = '';
	} else {
		f.style.display = 'none';
	}
	f = getElement("till");
		f.style.display = 'none';

}
