//functions common to front and back ends

//function for form tips
function tipobject(tipid,tiplabel,tiptext,width,xoffset,yoffset){
this.tipid=tipid;
this.tiplabel=tiplabel;
this.tiptext=tiptext;
this.width=width;
this.xoffset=xoffset;
this.yoffset=yoffset;
}


function puttipimg(tiplabel){
 if((tiparray[tiplabel]) || (mode=="setup")){
 if(mode=="setup"){
onclickstring = "edittip(this)";
}
else
{
onclickstring = "";
}
	 		document.writeln('<img src="images/tipimg.gif" width="15" height="15" border="0" name="tip_'+tiplabel+'" onMouseOver="showtip(this);" onMouseOut="hidetip();" onclick="'+onclickstring+'"> ');
	 } 
}


function scrolly(){
//from quirksmode.org/viewport/compatability.html
if(self.pageYOffset){
// all browswers except explorer
y = self.pageYOffset;
}
else if(document.documentElement && document.documentElement.scrollTop){
// explorer 6 strict
y = document.documentElement.scrollTop;
}
else if(document.body){
// all other explorers
y = document.body.scrollTop;
}
return y;
}


//start import from coatingworx

function windowsize()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return (w+","+h);
}

function centeroverlay(elementid){
overlaypanelwidth = document.getElementById(elementid).offsetWidth;
overlaypanelheight = document.getElementById(elementid).offsetHeight;
windowdims = windowsize().split(",");
windowwidth = windowdims[0];
windowheight = windowdims[1];
document.getElementById(elementid).style.left=(windowwidth/2)-(overlaypanelwidth/2)+"px";
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-(overlaypanelheight/2)+"px";

//this includes fix to nudge image up
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-((overlaypanelheight/2)+80)+"px";




/*
//this includes fix to nudge portraitimages up
//this will only work if centeroverlay is called again once image has loaded as we do not know image dims until it has loaded
if(overlaypanelheight > overlaypanelwidth){
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-((overlaypanelheight/2)+40)+"px";
}
else
{
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-(overlaypanelheight/2)+"px";
}
*/

}




function cleargreyout(){
document.getElementById('greyout').style.visibility='hidden';
}


function show_panel(panelid){
document.getElementById(panelid).style.display='';
centeroverlay(panelid);
}

function hide_panel(panelid){
document.getElementById(panelid).style.display='none';
}

function hide_imagepanel(){
hide_panel("image_panel");
cleargreyout();
document.getElementById("image_panel_image").src="images/loadingimage.jpg";
}

function show_imagepanel(){
show_panel("image_panel");
}

//end of import from newcoatingworx


function showtip(thetip){
thetip = thetip.name.replace(/tip_/,"");

if(!tiparray[thetip]){
return;
}

obj = tiparray[thetip];
tipbox.innerHTML= obj.tiptext;
tipbox.style.left=event.x-obj.xoffset;
tipbox.style.top=event.y+scrolly()-obj.yoffset;
//tipbox.style.top=event.y-Number(tipbox.style.height.replace(/px/,""));

if(obj.width){
tipbox.style.width=obj.width;
}
else
{
tipbox.style.width= tipwidthdefault;
}
tipbox.style.display = '';
}

function hidetip(){
tipbox.innerHTML= "";
tipbox.style.display = 'none';
}



function edittip(thetip){
thetip = thetip.name.replace(/tip_/,"");
if(tiparray[thetip]){
obj = tiparray[thetip];
tipid = obj.tipid;
}
else
{
tipid="";
}
location.href='admin_edittipform.php?tipid='+tipid+'&tiplabel='+thetip+'&tippagename='+tippagename;
}

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];}}
}
