function findPosY(obj) {

	var curtop = 0;

	if(obj.offsetParent) {

		while(1) {

			curtop += obj.offsetTop;

			if(!obj.offsetParent)

				break;

			obj = obj.offsetParent;

		}

	} else if(obj.y) {

		curtop += obj.y;

	}

	return curtop;

}



function hoverProduct( product ) {

	var element = document.getElementById( product );

	element.style.display = "block";

}



function unhoverProduct( product ) {

	var element = document.getElementById( product );
	element.style.display = "none";

}



function closeZoomImage( moduleid ) {

	var element = document.getElementById( "Catalog" + moduleid + "ImageZoom" );

	var image = document.getElementById( "Catalog" + moduleid + "ImageZoomImg" );

	var grayoverlay = document.getElementById( "grayoverlay" );

	element.style.display = "none";

	image.src = "/gp3_views/admin/images/icons/throbber-fast.gif";

	grayoverlay.style.display = "none";

}



function toggleZoomImage( url, moduleid, reference ) {

	var imageurl = "/gp3_image.php?height=640&src=" + url;

	var element = document.getElementById( "Catalog" + moduleid + "ImageZoom" );

	var image = document.getElementById( "Catalog" + moduleid + "ImageZoomImg" );

	var refObj = document.getElementById( reference );
	

	var grayoverlay = document.getElementById( "grayoverlay" );

	if( element.style.display == "none" ) {

		grayoverlay.style.display = "block";

		element.style.display = "block";

		image.src = imageurl;

		if( refObj ) {

		//				element.style.top = ( findPosY( refObj ) - 10 ) + "px";

		}

		var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }

		element.style.left = ( ( myWidth / 2 ) - 320 ) + "px";

		image.style.maxWidth = "640px";

	//			alert(window.innerWidth + " -> " + element.style.left);

	} else {

		grayoverlay.style.display = "none";

		element.style.display = "none";

		image.src = "/gp3_views/admin/images/icons/throbber-fast.gif";

		image.style.width = "32px";

		image.style.height = "32px";

	}

}



function toggleSelectProduct( idno, moduleid ) {

	name = "Product" + moduleid + "[" + idno + "]";

	hiddenvalue = "ProductQty" + moduleid + "[" + idno + "]";
	hiddenarea = document.getElementById( "ProductFields" + moduleid + "[" + idno + "]" );

	el = document.getElementById( name );

	el.checked = ( !el.checked );

	//		alert( name + " checked status: " + el.checked );

	icon = document.getElementById( name + "checkicon2" );

	storefield = document.getElementById( hiddenvalue );

	if( storefield.value == 0 ) {

//		icon.style.display = "inline";

//		storefield.value = parseInt( prompt( "Hvor mange av dette produkter ønsker du å legge til ønskelisten din?", 1 ) );
//		if( parseInt( storefield.value ) == 0 ) return;

		icon.className = "checkicon2";
		hiddenarea.style.display = "block";
		storefield.focus();

	} else {

//		icon.style.display = "none";

		storefield.value = 0;

		icon.className = "checkicon";

		document.produktvalg.submit();

		hiddenarea.style.display = "none";

	}

}



function toggleRemoveLine( listid, idno, moduleid ) {

	lineName = "Catalog" + moduleid + "List" + listid + "Line[" + idno + "]";

	lineElement = document.getElementById( lineName );

	if( lineElement ) {

		cells = lineElement.getElementsByTagName( "td" );

		inputs = lineElement.getElementsByTagName( "input" );

		hiddenfield = document.getElementById( "Catalog" + moduleid + "List" + listid + "RemoveLine[" + idno + "]" );

		if( !lineElement.markedForRemoval ) {

			for( i=0; i < cells.length; i++ ) {

				cells[i].style.textDecoration = "line-through";

			}



			for( i=0; i < inputs.length; i++ ) {

				if( inputs[i].type == "text" ) {

					inputs[i].style.background = "#F44";

					inputs[i].readOnly = true;

				}

			}

			lineElement.markedForRemoval = true;

			hiddenfield.value = "yes";

		} else {

			for( i=0; i < cells.length; i++ ) {

				cells[i].style.textDecoration = "none";

			}



			for( i=0; i < inputs.length; i++ ) {

				if( inputs[i].type == "text" ) {

					inputs[i].style.background = "#FFF";

					inputs[i].readOnly = false;

				}

			}

			lineElement.markedForRemoval = false;

			hiddenfield.value = "no";

		}

	}

}


function toggleRemoveTextual( listid, idno, moduleid ) {
	var lineName = "Catalog" + moduleid + "List" + listid + "TextualLine[" + idno + "]";

	var lineElement = document.getElementById( lineName );

	if( lineElement ) {

		var cells = lineElement.getElementsByTagName( "td" );

		var inputs = lineElement.getElementsByTagName( "input" );

		var hiddenfieldName = "Catalog" + moduleid + "List" + listid + "RemoveTextualLine[" + idno + "]";
		var hiddenfield = document.getElementById( hiddenfieldName );

		if( !lineElement.markedForRemoval ) {

			for( i=0; i < cells.length; i++ ) {

				cells[i].style.textDecoration = "line-through";

			}



			for( i=0; i < inputs.length; i++ ) {

				if( inputs[i].type == "text" ) {

					inputs[i].style.background = "#F44";

					inputs[i].readOnly = true;

				}

			}

			lineElement.markedForRemoval = true;

			hiddenfield.value = "yes";

		} else {

			for( i=0; i < cells.length; i++ ) {

				cells[i].style.textDecoration = "none";

			}



			for( i=0; i < inputs.length; i++ ) {

				if( inputs[i].type == "text" ) {

					inputs[i].style.background = "#FFF";

					inputs[i].readOnly = false;

				}

			}

			lineElement.markedForRemoval = false;

			hiddenfield.value = "no";

		}

	}

}





