

var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById ) ? true : false;
var isOp = (navigator.appName == "Opera") ? true : false;
if (isNS4 || isNS6) window.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT ) //Event.MOUSEMOVE | Event.CLICK | Event.MOUSEUP | Event.MOUSEDOWN
	document.onmousemove=move;

var pic = -1; //Bild welches die maus drauf ist
var isover = -1;
var mouseX = 0; 
var corrX = -20;
var mouseY = 0; 
var corrY = -30;
var qvars;

var winW = 0;


    

if (isIE4 || isIE5 && !isOp) { corrX = corrX-2; corrY = corrY-2; } //untested on IE4!

function getScreenWidth() {
    if ( parseInt(navigator.appVersion)>3) { 
        if (document.body && document.body.offsetHeight) { winW = document.body.offsetWidth; } 
        else if (window.innerHeight) { winW = window.innerWidth; } else if (screen.width){ winW = screen.width; }
    }
    
}

function mouseonpic(element,variables) {
    getScreenWidth();
    qvars = variables+'&screen='+winW;
    window.status = pic+'/'+element.id; 
    if(pic != element.id) { 
        movediv(); 
        pic = element.id;
    }
}

function view() {
    window.location = "/viewer.php"+qvars;
}

function mark() {
    PopUp("/mark.php"+qvars+'&a=add');
}

function mail() {
    window.location = "/sendmail.php"+qvars;
}

function hide() {
	if (isNS4) { document.layers['click'].left = -1000; document.layers['click'].top = -1000; }
	else if (isIE4 || isIE5) { document.all('click').style.pixelLeft = -1000; document.all('click').style.pixelTop = -1000; }
	else if (isNS6) { document.getElementById('click').style.left = -1000+'px'; document.getElementById('click').style.top = -1000+'px'; }
}

function fullimg() {
    var Winfullimg = window.open( "/img.php"+qvars+"&w=&h=", 'fullimg', 'resizable=1,scrollbars=1,location=yes,directories=no,status=yes,menubar=yes,toolbar=yes');
	Winfullimg.focus();
}


function movediv() {
	if (isNS4) { document.layers['click'].left = mouseX; document.layers['click'].top = mouseY; }
	else if (isIE4 || isIE5) { document.all('click').style.pixelLeft = mouseX; document.all('click').style.pixelTop = mouseY; }
	else if (isNS6) { document.getElementById('click').style.left = mouseX+'px'; document.getElementById('click').style.top = mouseY+'px'; }
}

function move(e) {  //on mouse move
	if (isIE4 || isIE5) {
		mouseX = event.clientX + document.body.scrollLeft + corrX;
		mouseY = event.clientY + document.body.scrollTop + corrY;
	} else { // NS
		mouseX = e.pageX + corrX;  
		mouseY = e.pageY + corrY;	
	 }

}



function PopUp(url) {	

    if (document.body && document.body.offsetHeight) {
        X = document.body.offsetWidth;
        Y = document.body.offsetHeight;
    } else if (window.innerHeight) {
        X = window.innerWidth;
        Y = window.innerHeight;
    } else if (screen.height )  { //&& navigator.appName != 'Opera'
        X = screen.width;
        Y = screen.height;
    } else { 
        X = 600;
        Y = 600;
    }	
	
	X = (X - 400 ) / 2;
	Y = (Y - 400 ) / 2;
	var Win = window.open( url, 'help', 'width=400,height=400,top='+Y+',left='+X+',resizable=1,scrollbars=1,location=no,directories=no,status=no,menubar=no,toolbar=no');
	Win.focus();
 }

//<a href="javascript:PopUp('/help.php?t=title')">[help]</a>

function cleanit(thefield){if(thefield.defaultValue==thefield.value){thefield.value='';};}

function mkoutput() { 
    if (document.form.a.value == 'redirect') { document.form.a.value = 'output'; }
	else if (!document.form.c2.value && !document.form.c1.value && !document.form.bg.value && (!document.form.h.value || document.form.h.value == document.form.w.value) && document.form.q.value == quality && document.form.logo.value == logo && (document.form.w.value == '128' || document.form.w.value == '256' || document.form.w.value == '512')) {
		document.form.a.value = 'redirect';
	}
}

hexvals = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","a","b","c","d","e","f");

function ishex(char2check) { //in_array(hexvals,char2check)
    for (j=0; j<hexvals.length; j++) {
        if (char2check == hexvals[j]) {
            return true;
        }
    }
    return false;
}

function mkfill() { 
    
    //document.form.bg.value = document.form.bg.value.toUpperCase();
    
    if (document.form.a.value == 'redirect') { 
        document.form.a.value = 'fill'; 
    }
    if (document.form.bg.value.length==7 && document.form.bg.value.charAt(0)=='#') {
        for (i=1; i<7; i++) {
            if (!ishex(document.form.bg.value.charAt(i))) { return false; } 
        }
        document.getElementById('showbg').style.backgroundColor = document.form.bg.value;
    } else if (document.form.bg.value.length==6) {
        for (i=0; i<6; i++) {
            if (!ishex(document.form.bg.value.charAt(i))) { return false; } 
        }
        document.getElementById('showbg').style.backgroundColor = '#'+document.form.bg.value;
    }
    return true;
}

//function cropform(pos, elementid) { 
    ////alert(elementid+' -> '+pos);
    //document.getElementById(elementid).value = pos;
//}