var gAdminPath = 'http://'+document.location.hostname+'/qcms/';
var QApp = new function(){ //a
 var t = navigator.userAgent.toLowerCase();
	this.isDOM = document.getElementById?1:0;
	this.isNS = t.indexOf('mozilla')!=-1&& t.indexOf('compatible')==-1?1:0;
	this.isIE = t.indexOf('msie')!=-1?1:0;
	this.isOP = t.indexOf('opera')!=-1?1:0;
	
 	t = navigator.appVersion.toLowerCase();
	this.isMAC = t.indexOf('mac') >= 0;
	this.isWIN = t.toLowerCase().indexOf( 'win' ) >= 0;
	this.isGNU = t.toLowerCase().indexOf( 'unix' ) >= 0;
	this.isNS4 = false;
	
	if(this.isNS){
	  this.ver = parseFloat( navigator. appVersion );
	  this.isNS4 = (this.ver < 5);
	}else if(this.isIE){
	  this.ver = parseFloat( t.substring(t.toLowerCase().indexOf( "msie" ) + 4 ) );
	}else{
	  this.ver = 0;
	}
	
	this.i =0;
	this.ui = function(){return "Q"+(this.i++);};
}
 if(document.all && !document.getElementById){
    document.getElementById = document.all;
 }


function closeToc()
{
  var colFrame =   top.frames['content'];
	var colsArr = colFrame.cols.split(",");
	colFrame.cols= '0,'+colsArr[1]+','+ colsArr[2];
}

function closePreview()
{
  var colFrame =   top.frames['content'];
	var colsArr = colFrame.cols.split(",");
	colFrame.cols = colsArr[0]+','+colsArr[1]+',0';
}
function loadPreview( _url )
{	
  if(_url != '')
	{
		_url = 'kDomain'+ _url +'?ranstr='+Math.random();
		var _frame =top.frames['previewContent'].document.location = _url;
	}
}

function refreshNav(){
   var navFrame =  top.frames['explorerbar'].document;
	navFrame.location = gAdminPath +'shellx/navigation.php?ranstr=editor&blah='+Math.random();
}
function highlightNav( _id ){
	if(_id != '' && _id != null ){
	  var xbar =   top.frames['explorerbar'];
		if(xbar.document && xbar.document.getElementById('td' + _id)){
			xbar.document.getElementById('td' + _id).onclick();
		}
	}
}
function setFunc( _func ){
   var actbar =  top.frames['actionbar'];
	if(actbar.document && actbar.document.forms){
	newDoc =actbar.document.forms['newDoc'];
		if(newDoc.id != '')
		{
			newDoc.func.value = _func;
			newDoc.submit();
		}
		else
		{
			alert('no document selected');
		}
	}
}
function moveNode()
{ 
 var actbar = top.frames['actionbar'];
 actbar.document.location = 'actions.php?func=moveNode&id='+ nodeToMove +'&moveNodeBefore=' +moveNodeBefore;
	nodeToMove = 0;
	moveNodeBefore = 0;
}
var nodeToMove = 0;
var moveNodeBefore = 0;
var activeElement = 0;

function wipeContentPage()
{
	top.frames['frmeditor'].document.location = '/qcms/res/html/blank.html';
}

function goContentPage( _page,_dataid, _id )
{
top.frames['frmeditor'].document.location =  _page +'?c='+_dataid+'&nodeID='+_id;
}

function setActiveElement(_editor,_dataid, _nodeid)
{
	goContentPage( _editor,_dataid, _nodeid );
	activeElement = _nodeid;
}
function openMedia(path){
var width = 770;
	var height = 525;
	var properties = "width=500,height=525,toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;
	popupHandle = window.open( gAdminPath+'/import/filebrowser.php?pad='+path, 'WebMediaBrowser', properties);
	setTimeout('popupHandle.focus();',250);
}



function openWin(url,name,args) {
	popupWin = window.open(url,name,args);
	popupWin.focus();
}

function chkFrm(daform){
  out = '';
 
 if (daform.elements.length>5){
   if(daform.Naam.value ==''){
     out += '- Naam moet ingevuld zijn.\n';
	 }
    if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(daform.Email_adres.value))){
     out += '- e-mailadres is ongeldig.\n';
	 } 
   if(daform.tekst.value ==''){
     out += '- U heeft geen reactie geschreven.\n';
	 } 

 
 }
}

function openEditor(id){
var width = 600;
	var height = 400;
	var properties = "width="
	        +width+",height="
					+height+", toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;
	popupHandle = window.open( '/lib/ceditor.asp?id='+id, 'WebFormBrowser', properties);
	setTimeout('popupHandle.focus();',250);
}
function openItemEditor(query){

var width = 600;
	var height = 400;
	var properties = "width="
	        +width+",height="
    	+height+", toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;
	popupHandle = window.open( gAdminPath+'lib/editor.php?'+query, 'WebFormBrowser', properties);
	setTimeout('popupHandle.focus();',250);

}
function openHelp(query){

var width = 600;
	var height = 400;
	var properties = "width="
	        +width+",height="
    	+height+", toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;
	popupHandle = window.open( gAdminPath+'lib/help.php?'+query, 'HELP', properties);
	setTimeout('popupHandle.focus();',250);

}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// functions by Dim
//
function OnChange(dropdown)
{
	// require URLMinusQuerystring()
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value;
	var baseURL  = URLMinusQuerystring() + '?lang=' + SelValue;
	top.location.href = baseURL;
	//alert(baseURL);    
	return true;
}

function URLMinusQuerystring()
	{
	var strNaam = new String( document.location );
	var intA = strNaam.lastIndexOf('?');
	var cleanURL = strNaam.substr( 0, strNaam.length - (strNaam.length - intA));	
	return cleanURL;
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// /functions by Dim
//

function openForm(path){
var width = 615;
	var height = 400;
	var properties = "width="
	        +width+",height="
					+height+", toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;
	popupHandle = window.open( path, 'WebFormBrowser', properties);
	setTimeout('popupHandle.focus();',250);
}

// Check postcode
function checkform() {
   var pc = document.forms(0).zipcode;
   var nmr = document.forms(0).housenr;

   if ((pc.value == "") || (!(pc.value.length == 6))) {
     alert("U heeft een onjuiste postcode ingevuld.");
     return (false);
   }
   // eerste 4 letters postcode
   var chars = "0123456789";
   for (var i = 0; i < 4; i++) {
     if (chars.indexOf(pc.value.charAt(i)) == -1) {
       alert('U heeft een onjuiste postcode ingevuld.');
       pc.focus();
       return false;
     }
   }
      
   // laatste 2 letters postcode
   var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   for (var i = 4; i < 6; i++) {
     if (chars.indexOf(pc.value.charAt(i)) == -1) {
       alert('U heeft een onjuiste postcode ingevuld.');
       pc.focus();
       return false;
     }
   }
      
   // Huisnummer
   if (nmr.value == "") {
     alert('U heeft het huisnummer onjuist ingevuld.');
     pc.focus();
     return false;
   }
      
   // Alleen cijfers huisnummer
   var chars = "0123456789";
   for (var i = 0; i < nmr.value.length; i++) {
     if (chars.indexOf(nmr.value.charAt(i)) == -1) {
       alert('U heeft een onjuist huisnummer ingevuld.');
       nmr.focus();
       return false;
     }
   }
  return true;
}
function openItemEditorRAW(query,editor){

var width = 600;
	var height = 400;
	var properties = "width="
	        +width+",height="
    	+height+", toolbar=no,status=no,resizable=yes,scrollbars=yes";
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var leftvar = Math.round((screenX - width) / 2);
	var rightvar = Math.round((screenY - height) / 2);
	properties += ",left=" + leftvar +",top=" + rightvar;

	popupHandle = window.open( ''+editor+"&t="+query, 'WebFormBrowser', properties);
	setTimeout('popupHandle.focus();',250);

}
