function ge (id) { return document.getElementById (id); }

function get_left (e) {
	x		= e.offsetLeft;
	pe	= e.offsetParent;
	while (pe != null) {
		x  += pe.offsetLeft;
		pe	= pe.offsetParent;
	}
	return x;
}

function loginScreen(){
	ge('login_member').innerHTML = '<div class="border" style="padding: 10px;"><form method=post action="?i=action"><input type=hidden name="action" value="loginM">'+
									'<input type=text value="username" id="username_m" name="username_m" class="m_login" onFocus="checkValue(\'username_m\',\'username\');" onBlur="checkValue(\'username_m\',\'username\');">'+
									'<input type=password name="password_m" id="password_m" value="password" class="m_login" onFocus="checkValue(\'password_m\',\'password\');" onBlur="checkValue(\'password_m\',\'password\');">' +
									'<input type=submit value="Submit" class="m_login"> ' +
									'</div>';
}

function loginScreenEditor(){
	ge('login_member_editor').innerHTML = '<div class="border" style="padding: 10px;"><form method=post action="?i=action"><input type=hidden name="action" value="loginM">'+
									'<input type=text value="username" id="username_m" name="username_m" class="m_login" onFocus="checkValue(\'username_m\',\'username\');" onBlur="checkValue(\'username_m\',\'username\');">'+
									'<input type=password name="password_m" id="password_m" value="password" class="m_login" onFocus="checkValue(\'password_m\',\'password\');" onBlur="checkValue(\'password_m\',\'password\');">' +
									'<input type=submit value="Submit" class="m_login"> ' +
									'</div>';
}

function goto(url){
	if(navigator.userAgent.indexOf('MSIE') >= 0){
		var referLink = document.createElement('a');
		referLink.href = url;
		document.body.appendChild(referLink);
		referLink.click();
	}else{
		location.href=url;
	}
}

function checkValue(fieldname,valuename){
	if(ge(fieldname).value == valuename){
		ge(fieldname).value='';
	}else if(ge(fieldname).value == ''){
		ge(fieldname).value = valuename;
	}
}


function get_top (e) {
	y		= e.offsetTop;
	pe	= e.offsetParent;
	while (pe != null) {
		y  += pe.offsetTop;
		pe	= pe.offsetParent;
	}
	return y;
}

function AjaxReq (url,handler){
	var client = null;
	try	{	// Firefox, Opera 8.0+, Safari
		client=new XMLHttpRequest ();
	} catch (e) {  // Internet Explorer
		try {
			client=new ActiveXObject("Msxml2.XMLHTTP");    
		} catch (e) {
			try {
				client=new ActiveXObject("Microsoft.XMLHTTP");      
			} catch (e) {      
				return false;
			}    
		}  
	}
	//client.onreadystatechange = handler;
	client.onreadystatechange = function () {  
		if (client.readyState == 4 && client.status == 200 && handler){
			handler(client.responseText); 
		}else{
			handler('loading, plz wait ...'); 
		}
	}
	
	client.open("GET", url);
	client.send(null);
	return true;
}


function showImages(txt,sceneID){
	ge ('picContainer_'+sceneID).innerHTML = txt;
	$('a.thickbox, area.thickbox, input.thickbox').unbind ('click');
	tb_init('a.thickbox, area.thickbox, input.thickbox');
}

function removeFromShoppingCart(dvd,pos){
	if(confirm('Are you sure you wish to remove this scene from the dvd compilation?')){
		goto('index.php?i=shoppingBasket&action=r&id='+dvd+'&p='+pos);
	}
}


function popToolTip (txt){
	ge ('tooltip').innerHTML = 'loading...';
	ge ('tooltip').innerHTML = txt;
}

function hreffer (txt){
	eval(txt);
}

/*** Tooltip functions ***/
function add_tt (element, text, cls) {
	var e			= ge (element);
	if(text == 'niches' || text == 'sites' || text == 'shoppingCart'){
		e.onclick	= function () { show_tt (element, text, cls); }
	}else{
		e.onmouseover	= function () { show_tt (element, text, cls); }
		e.onmouseout	= function () { hide_tt (); }
	}
	
}

function show_tt (element, text, varID) {
	var e	= ge (element);
	var tt	= ge ('tooltip');
	
	tt.innerHTML = 'loading...';
	
	if (e && tt) {
		tt.style.display	= 'none';
		if(text == 'niches'){
			tt.style.width = 204 + 'px';
			AjaxReq('incl/dynJ.php?action=showNiches&r='+Math.random(), popToolTip );
		}else if(text == 'sites'){
			AjaxReq('incl/dynJ.php?action=showSites&r='+Math.random(), popToolTip );
		}else if(text == 'previewThumb'){
			AjaxReq('incl/dynJ.php?action=previewThumb&dvdID='+varID+'&r='+Math.random(), popToolTip );
		}else if(text == 'showModel'){
			AjaxReq('incl/dynJ.php?action=showModel&serieID='+varID+'&r='+Math.random(), popToolTip );
		}else if(text == 'shoppingCart'){
			AjaxReq('incl/dynJ.php?action=addDvdChoice&dvdID='+varID+'&r='+Math.random(), hreffer );
		}else if(text == 'title_descr'){
			tt.innerHTML = 'Give a name and a volume number to your DVD (max 25 characters)';
		}else if(parseInt(text) == text){
			tt.innerHTML = '<br><Table width=100 border=0 cellpadding=2 cellspacing=0><tr><td align=center>Your vote:</td></tr><tr><td align=center><b>'+text+' out of 10</b></td></tr><tr><td align=center>click to vote</td></tr></table>';
		}else{
			tt.innerHTML		= 'target is not set';	
		}
		if(text == 'shoppingCart'){
			var eraf = e.offsetWidth + 1;
			var vdt = e.offsetHeight - 2;
		}else if(text == 'previewThumb'){
			var eraf = e.offsetWidth + 1;
			var vdt = -22;
		}else{
			var eraf = 0;
			var vdt = 0;
		}
		tt.style.left		= get_left (e) + e.offsetWidth - eraf + 'px';
		tt.style.top		= get_top (e) - vdt + 'px';
		tt.style.display	= 'block';
	}
}

function hide_tt () {
	e = ge ('tooltip');
	if (e) e.style.display = 'none';
}





