var IFrameObj=null;
var divObj	=null;

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function WindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

	return [ windowWidth, windowHeight ]
}

function productZoom(id){
	hideProductZoom()
	createIframe(id,"/store/page_product_zoom.cfm?prID="+id);
};

function leatherInfoZoom(id){
	createIframe(id,"/page_leatherspecs_zoom.cfm?id="+id);
};

function createIframe(id,url) {
	var tempIFrame=document.createElement('iframe');
	var tempDIV=document.createElement('div');
	
	//tempDIV.style.width=document.body.offsetWidth+"px";
	//tempDIV.style.height=document.body.offsetHeight+"px";
	tempDIV.style.width=WindowSize()[0]+"px";
	tempDIV.style.height=WindowSize()[1]+"px";
	tempDIV.style.zIndex="100";
	tempDIV.style.top=getScrollXY()[1];
	//tempDIV.style.top="0px";
	tempDIV.style.left="0px";
	tempDIV.style.position="absolute";
	tempDIV.style.backgroundColor="#000000";
	tempDIV.style.zIndex="100";
	tempDIV.style.filter="Alpha(Opacity=70)";
	tempDIV.style.opacity="0.7";	
	tempDIV.style["-moz-opacity"]="0.7";

	divObj=document.body.appendChild(tempDIV);
	divObj.onclick=hideProductZoom;

	tempIFrame.setAttribute('id','productZoom');
	tempIFrame.setAttribute('classname','productZoom');
	tempIFrame.setAttribute('frameBorder','0');
	tempIFrame.setAttribute('marginHeight','0');
	tempIFrame.setAttribute('marginWidth','0');
	tempIFrame.setAttribute('scrolling','no');
	
	tempIFrame.style.position	='absolute';
	
	var top=0;
	var left=0;
	var clientHeight = WindowSize()[1];
	var clientWidth = WindowSize()[0];
	var scrollTop= getScrollXY()[1];
	var scrollLeft = getScrollXY()[0];
	var width=750;
	var height=560;

	// verbeteren voor IEMOFO, FF3, Chrome
	//if (document.documentElement) {
	//	if (document.documentElement.clientHeight)
	//		clientHeight = document.documentElement.clientHeight;
	//	if (document.documentElement.clientWidth)
	//		clientWidth = document.documentElement.clientWidth;
	//	if (document.documentElement.scrollTop)
	//		scrollTop = document.documentElement.scrollTop;
	//	if (document.documentElement.scrollLeft)
	//		scrollLeft = document.documentElement.scrollLeft;
	//}
	//else if (document.body) {
	//	if (document.body.clientHeight)
	//		clientHeight = document.body.clientHeight;
	//	if (document.body.clientWidth)
	//		clientWidth = document.body.clientWidth;
	//	if (document.body.scrollTop)
	//		scrollTop = document.body.scrollTop;
	//	if (document.body.scrollLeft)
	//		scrollLeft = document.body.scrollLeft;
	//}
	

	top  = parseInt( (clientHeight-height) / 2 ) + scrollTop;
	left = parseInt( (clientWidth-width) / 2) + scrollLeft;
	
	tempIFrame.style.backgroundColor="#FFFFFF";
	tempIFrame.style.top	= top + 'px';
	tempIFrame.style.left	= left + 'px';

	tempIFrame.style.borderStyle	='none';
	tempIFrame.style.borderWidth	='0px';

	tempIFrame.style.width	= width+'px';
	tempIFrame.style.height	= height+'px';
	tempIFrame.style.zIndex="200";
	
	IFrameObj = document.body.appendChild(tempIFrame);
	tempIFrame.src=url;

	return false;
}



function showImage(image) {
	var image_container=null;
	var image_container_name='zoom-image';
	
  if (document.getElementById)
		image_container = document.getElementById(image_container_name);
  else if (document.all)
		image_container = document.all[image_container_name];
  else if (document.layers)
		image_container = document.layers[image_container_name];
				
	if (image_container && image_container.style) {
		if (image_container.style.setAttribute)		// IE
			image_container.style.setAttribute("cssText", "background-image: url("+image+");");
		else	// Other browsers
			image_container.setAttribute("style", "background-image: url("+image+");");
	}
}

function hideProductZoom(blnReload){
	if(divObj){	
		divObj.style.display="none";
		divObj=null;
	}
	if(IFrameObj){
		IFrameObj.style.display="none";
		IFrameObj=null;
	}
	if (blnReload)
		window.document.location.reload();
}

/* CLIENT-LOGIN FUNCTIONS */

function doLogin(){
	var formName='login';
	var frm=document.forms[formName?formName:0];
	if(frm)
		frm.submit();
}

/* SHOP FUNCTIONS */

function increaseQuantity(inputObj,formName,submit){
	var frm=document.forms[formName?formName:0];
	var submit=submit|false;
	
	if(frm.elements[inputObj])
		frm.elements[inputObj].value=parseInt(frm.elements[inputObj].value)+1;
	
	if(submit)
		frm.submit();
	
}
function decreaseQuantity(inputObj,formName,submit){
	var frm=document.forms[formName?formName:0];
	var submit=submit|false;
	if(frm.elements[inputObj] && parseInt(frm.elements[inputObj].value)>0)
		frm.elements[inputObj].value=parseInt(frm.elements[inputObj].value)-1;
		
	if(submit)
		frm.submit();	
}
function addToBasket(inputObj,formName){
	var frm=document.forms[formName?formName:0];
	if(frm){
		if(frm.elements[inputObj] && parseInt(frm.elements[inputObj].value)==0)
			frm.elements[inputObj].value=1;
		frm.submit();
	}
}

/* BASKET FUNCTIONS */

function productRemove(prodID){
	var formName='basket';
	var frm=document.forms[formName?formName:0];
	if(frm) {
		frm.elements['basketAction'].value='removeFromBasket';
		frm.elements['applyToProdID'].value=prodID;
		frm.submit();
	}
}

function recalcBasket(){
	var formName='basket';
	var frm=document.forms[formName?formName:0];
	if(frm) {
		frm.elements['basketAction'].value='updateBasket';
		frm.submit();
	}
}

function showBillingInfo(){
	var formName='basket';
	var frm=document.forms[formName?formName:0];
	if(frm) {
		frm.elements['basketAction'].value='updateBasket';
		frm.elements['basketReloc'].value='?action=checkout';
		frm.submit();
	}
}

/* CHECKOUT FUNCTIONS */

function backToBasket(){
	document.location='?action=basket';
}

function showOverview(){
	var formName='checkout';
	var frm=document.forms[formName?formName:0];
	if(frm)
		frm.submit();
}

function backToBillingInfo(){
	document.location='?action=checkout';
}

function finalizeOrder(){
	document.location='?action=checkout&sub=finalize';
}

function Logout(){
	document.location="?action=client_login&sub=logoff";
}

function checkSame(elem){
	
	if(elem.checked == true)
	{
		document.getElementById('shippinginfo').style.display="block";
	}
	else
	{
		document.getElementById('shippinginfo').style.display="none";
	}
}
