//080110
var msub=false;

var SUBM_LEFT=120;
var ITEM_HEIGHT=19;
var MENU_TIME=500;

function validate_form(thisform){  
//article desc,text,cat
  with (thisform) {
    if (desc.value == "")  { alert("Enter title"); desc.focus();  return false;    }
   // if (text.value == "")  { alert("Enter text"); text.focus();  return false;    } 
    if (cat.value == "")  { alert("Select category"); cat.focus();  return false;    } 
  }                

}

function toggleBox(nr) {
  var box =document.getElementById("box"+nr);  
  if (box.style.display == "block" || box.style.display == "") 
   box.style.display = "none"; 
  else  
    box.style.display = "block"; 
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}

function drop(item,nr) {
	//alert("drop");
	if (typeof(st) != "undefined") clearTimeout(st); // evt aanroep van vorige selectie cancellen
	var subm =document.getElementById("sub");
	var menu = document.getElementById("menubox");
  var pos = findPos(menu);
	subm.innerHTML = "";
	var text = eval(document.getElementById(item));
	subm.innerHTML = text.innerHTML;
	subm.style.left = parseInt(pos[0]) + SUBM_LEFT;
	subm.style.top = parseInt(pos[1]) + nr*ITEM_HEIGHT;
  subm.style.display = "block";
}

function hideSub() {
	if (typeof(st) != "undefined") clearTimeout(st); // evt aanroep van vorige selectie cancellen
	st = window.setTimeout("hideSub2()",MENU_TIME);
}	

function hideSub2() {
	//alert(msub);
	if (msub == false) {
		var elm = document.getElementById("sub");
		elm.style.display = "none";
	}
}	

function msgWin(msg) {
  //alert(window.innerWidth+  "," + document.body.clientWidth) ;
	//alert("msgwin");
	var elm = document.getElementById("msgwin");
	//elm.innerHTML = msg;
    elm.innerHTML = "<div class='msgwinclose' onclick='closeMsgwin();'>X</div><p align='center'>" + msg + "</p>";
    var left= 200;
    var top = 150; //(window.innerHeight/2)-100;
	elm.style.display = 'block';
	elm.style.left = left;
	elm.style.top = top;
	//elm.innerHTML = "left :" + left + " top : "+top;
	//elm.innerHTML = elm.innerHTML + "<BR><p align='center'><input type='button' value='OK' onclick='closeMsgwin();'></p>";
}

function closeMsgwin() {
	var elm = document.getElementById("msgwin");
	elm.style.display = 'none';

}

function ftvlaunch(video,quality,pid) {
	  var LeftPosition = (screen.width) ? (screen.width-665)/2 : 0;
	  var TopPosition = (screen.height) ? (screen.height-430)/2 : 0;
	  var popwin = window.open('http://www.zoomin.tv/videoplayer/index.cfm?id='+video+'&mode=normal&quality='+ quality +'&pid=ftv','MTV6_window',',toolbar=no,width=665,height=430,top='+TopPosition+',left='+LeftPosition+',directories=no,status=no,statusbar=0,scrollbars=no,resizable=no,menubar=no');
      popwin.focus();
}

function player(video,title) {
	  var LeftPosition = (screen.width) ? (screen.width-380)/2 : 0;
	  var TopPosition = (screen.height) ? (screen.height-320)/2 : 0;
	  var popwin = window.open('/nerdz/player.php?title='+title+'&id='+video,'MTV6_window',',toolbar=no,width=380,height=320,top='+TopPosition+',left='+LeftPosition+',directories=no,status=no,statusbar=0,scrollbars=no,resizable=no,menubar=no');
      popwin.focus();
}
	
function confirmit(id) {
	if (confirm('Delete ?'))
	{
		return window.location.href = "index.cfm?fuseaction=delete_FlashCommercial&tijd=%7Bts%20%272006%2D05%2D31%2014%3A58%3A43%27%7D&pk_flashcommercialid="+nummer;
	}
}

function popFlash(aURL)
{
	var day = new Date();
	var aTop = (screen.height/2) - 144;
	var aLeft = (screen.width/2) - 175;
	var id = day.getTime();
	//aURL = "/nerdz/uploads/" + aURL;
	eval("var page" + id + " = window.open(aURL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=352,height=288,left="+aLeft+",top="+aTop+"');");
}

var simple = false; 
function switched() {
  var elm = document.getElementById("editor");
  if (simple) { 
    var HTML = document.getElementById("simple").innerHTML ; 
    elm.innerHTML ="<textarea name='text' id='wysedit' >"+HTML+"</textarea>"; 
    WYSIWYG.attach('wysedit',full);//generate_wysiwyg('wysedit'); 
    simple = false;}
  else {
    var HTML = document.getElementById("wysedit").innerHTML ;  
    elm.innerHTML = "<textarea id='simple' name='text' rows='10' cols='60'>"+HTML+"</textarea>";
    simple = true;
  }

}

/* AJAX stuff --------------------------------------------------------------------------------*/
// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();
var menu_nr;

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() {
	var xmlHttp; 	// will store the reference to the XMLHttpRequest object
	// if running Internet Explorer
	if(window.ActiveXObject) 	{
		try	{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e)	{	xmlHttp = false;	}
	}
	// if running Mozilla or other browsers
	else	{
		try	{		xmlHttp = new XMLHttpRequest();	}
		catch (e)	{	xmlHttp = false;}
	}
	// return the created object or display an error message
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object, called by menu
function getcat(pcat,nr) {
	menu_nr = nr;
	// proceed only if the xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)	{
		//	alert ("getcat : "+pcat+","+nr);
		xmlHttp.open("GET", "/nerdz/getcat.php?cat=" + pcat, true);
		xmlHttp.onreadystatechange = getCatResponse;
		xmlHttp.send(null);
	}
	else
		// if the connection is busy, try again after one second
		//setTimeout('process()', 1000);
		//alert("busy");
		document.getElementById("sub").innerHTML = '<i>busy...</i>';
}

// executed automatically when a message is received from the server
function getCatResponse() {
	//	alert ("hsr");
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4) {
		// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) {
			//alert ("hsr -200");
			showArticlesCat();	
			// restart sequence			//setTimeout('getcat()', 1000);
		}
		// a HTTP status different than 200 signals an error
		else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function rate(id,val) {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)    {
        //    alert ("getcat : "+pcat+","+nr);
        xmlHttp.open("GET", "/nerdz/index.php?f=rate&id=" + id + "&val=" + val, true);
        xmlHttp.onreadystatechange = rateResponse;
        xmlHttp.send(null);
    }
    else
       document.getElementById("sub").innerHTML = '<i>busy...</i>';
}

function rateResponse() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
        //alert( xmlHttp.responseText);
        var res = xmlHttp.responseText;
          aSplit = res.split("=");
          id = aSplit[0];// find pos '=';
          val = aSplit[1];;
          var elm =eval(document.getElementById("rating"+id));  
          elm.innerHTML = val;
        }
        else {
            alert("There was a problem accessing the server: " + xmlHttp.statusText);
        }
    }
}
 
function showArticlesCat() {
  if (typeof(st) != "undefined") clearTimeout(st); // evt aanroep van vorige selectie cancellen

	var response;
  // = xmlHttp.responseText;
	var subm =document.getElementById("sub");
	var menu = document.getElementById("catbox");
	var pos = findPos(menu);
	subm.innerHTML = '<i>Latest articles :<BR></i>' + xmlHttp.responseText;
	subm.style.left = pos[0] + SUBM_LEFT + "px";
	subm.style.top = ITEM_HEIGHT + (pos[1] + menu_nr*ITEM_HEIGHT)+"px";
	subm.style.display = "block";
}

