// JavaScript Document

function clearExtLink() {
	if ( document.linkForm.linkTo.value != -3 )
		document.linkForm.extLink.value = 'http://';
}

function checkExternalLink() {
	if ( document.linkForm.linkTo.value != -3 ) {
		document.forms['linkForm'].elements['linkTo'].focus()
		//document.linkForm.linkTo.focus();
		alert('Extern länk måste vara vald först!');
	}
}

function changeButtonValue( button, checkbox ) {
	if ( checkbox.checked )
		button.value = 'Publicera';
	else
		button.value = 'Spara';
}

function stripBlanks(fld) {
	var result = "";
	var c = 0;
	for (i=0; i<fld.length; i++) {
	  if (fld.charAt(i) != " " || c > 0) {
	    result += fld.charAt(i);
	    if (fld.charAt(i) != " ") c = result.length;
	    }
	  }
	return result.substr(0,c);
}

function validField(fld) {
	fld = stripBlanks(fld);
	if (fld == '') {
		alert("Du måste skriva in ett Namn!");
		return false;
	}
	return true;
}

function SelectEditorPage(id) 
{ 
	strMenuAddress = "index.php?p="+id;
	window.opener.document.getElementById('txtUrl').value = strMenuAddress;  
	window.opener.document.getElementById('cmbLinkProtocol').value=''; 
	window.close(); 
} 

function SelectPictureLink(id) 
{ 
	strMenuAddress = "index.php?p="+id;
	window.opener.document.getElementById('txtLnkUrl').value = strMenuAddress;  
	window.opener.document.getElementById('cmbLnkTarget').value='_self'; 
	window.close(); 
} 

function InternalLinks( caller ) {
	w = 200;
	h = 80;
	wOff = (screen.width/2)-(w/2);
	hOff = (screen.height/2)-(h/2);
	properties="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,dependent=yes";
	properties+=",width="+w+",height="+h;
	properties+=",left="+wOff+",top="+hOff;
	id="Internallink";
	if ( caller == 'link' )
		url = "../../../editor/internalLink.php?c=link";
	else
		url = "../../../editor/internalLink.php?c=image";
	
	if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
	{
		var oWindow = oEditor.window.open( url, id, properties ) ;
		if ( oWindow )
			oWindow.opener = window ;
		else
			alert( oEditor.FCKLang.BrowseServerBlocked ) ;
    }
    else
		window.open( url, id, properties ) ;
	
	//window.open(url,id,properties);
}

function loadIndex()
{
	window.opener.location.href = window.opener.location.pathname;
}

function verify(prod){
	msg = "Säker att du vill ta bort länken: " + prod + " ?\n (sidorna kommer ej försvinna)";
	return confirm(msg);
}

function openWindow(url,width,height) {
	if ( height == 0 ) height = 950;
	wOff = (screen.width/2)-(width/2);
	hOff = (screen.height/2)-(height/2);
	if ( url.indexOf("editMain") >= 0 ) {
		if ( width < 500 ) width = 800;
		url += "&w="+width+"&h="+height;
	}
	if ( url.indexOf("editNews") >= 0 ) {
		if ( width < 220 ) width = 220;
		url += "?w=" + width + "&h=" + height;
	}
	properties="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,dependent=yes";
	properties+=",width="+width+",height="+height;
	properties+=",left="+wOff+",top="+hOff;
	id=new Date();
	id=id.getSeconds()+"_"+id.getMinutes()+"_"+id.getHours();
	window.open(url,id,properties);
}

function loadRev( rev, width, height )
{
	window.location.href = window.location.pathname + "?rev=" + rev + "&w=" + width + "&h=" + height;
}

function loadMainRev( rev, pageID, width, height )
{
	window.location.href = window.location.pathname + "?rev=" + rev + "&pageID=" + pageID + "&w=" + width + "&h=" + height;
}

function loadPrev( prev )
{
	window.opener.location.href = window.opener.location.pathname + "?preview=" + prev ;

}

