function ifdisabled(v, someid)
{
   someobj = document.getElementById(someid);
   if(v.checked)
	someobj.disabled=false;
   else
	someobj.disabled=true;
}

var current = '';
var menu_timer = null;
var menu_hide_timeout = 200;
var menu_show_timeout = 100;

function switch_sub_menu(id, show){
 if(menu_timer){ window.clearTimeout(menu_timer); }
 if(current.length>0 && show){
  tmp = document.getElementById(current);
  if(tmp){
   if(current == id){
    tmp.style.visibility = 'visible';
   }else{
    tmp.style.visibility = 'hidden';
    current = '';
   }
  }
 }
 if(!document.getElementById(id)){ return; }
 current = id;
 menu_timer = show?
 	window.setTimeout("set_visibility('"+id+"', true)", menu_show_timeout):
	window.setTimeout("set_visibility('"+id+"', false)", menu_hide_timeout);
}

function set_visibility(id, show){
 document.getElementById(id).style.visibility = show?'visible':'hidden';
 if(!show && current==id){ current = ''; }
}


function openURL(){
  var url=document.getElementById('url').value;
  if(url!='http://' && url!='') {
      //popupwnd(url, targ, width, height, centerwnd)
  	var win = window.open(url,'','toolbar=yes,location=yes,scrollbars=yes,menubar=yes,status=yes,resizable=yes');
  	win.focus();
  }
}
function previewImg(src, filename, path) {
	document.images['preview_img'].src = src;
	document.images['preview_img'].alt = filename;
	document.getElementById("filename").innerHTML = filename;
	document.getElementById("selected_image_popup").value = path + filename;
	document.getElementById("button").style.visibility = 'visible';
}
function insertImg(_par_num) {
	window.opener.document.getElementById('selected_image' + _par_num).value = document.getElementById("selected_image_popup").value;
	window.opener.document.getElementById('is_image_selected' + _par_num).value = 1;
	window.close();
}
function clearImg(_par_num) {
	 document.getElementById("selected_image" + _par_num).value = '';
	 document.getElementById("is_image_selected" + _par_num).value = 0;
}

function displayTab(tabToDisplayName, tabToHideName){
    document.getElementById(tabToDisplayName).style.visibility = 'visible';
    document.getElementById(tabToHideName).style.visibility = 'hidden';
    document.getElementById(tabToDisplayName+'_menu').style.background = '#FFFFFF';
    document.getElementById(tabToHideName+'_menu').style.background = '#FFFFCC';
}
function insertDir(path) {
	window.opener.document.getElementById('selected_dir').value = path;
	window.close();
}
function change_language(url){
	if(confirm('Do you want to save the changes made on the current page?')){
		document.getElementById('redirect').value = url;
		document.getElementById('redirect').form.submit();
    } else
    {
    	window.location.href = url;
    }
}

function absolute(value)
{
    if (value < 0) return -value;
    return value;
}
function popupwnd(url, targ, width, height, centerwnd){
 var param = 'width='+width + ',height='+height + ',toolbar=no,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes';
 if (centerwnd && !(navigator.userAgent.indexOf('Opera')>=0)){
     param += ",left=" + ((screen.width - width)/2) + ",top=" + ((screen.height-height)/2);
 } else {
     if (centerwnd){
         param += ",left=" + ((screen.width - width)/2) + ",top=" + (absolute(window.innerHeight-height)/2);
     }
 }
 //alert(targ);
 //alert(window);
 //alert(document);
 var popupWin = window.open(url, targ, param);
 popupWin.focus();
}

var isGecko = navigator.userAgent.indexOf('Gecko') != - 1;
var isOpera = navigator.userAgent.indexOf('Opera') != - 1;
var paragraphNumber = -1;

function get_paragraph_number()
{
    var pos = document.URL.lastIndexOf("?par_num=");
    if (pos != -1){
        paragraphNumber = document.URL.substring(pos + 9, document.URL.length);
    }
}

function handle_insert_text(objInput)
{
    var link_href = mytrim(objInput.form.link_href.value);
    var link_text = mytrim(objInput.form.link_text.value);
    var link_target = objInput.form.link_target.checked;
    if (link_href == "" || link_href == "http://"){
        alert("Field 'Link href' is required.");
        return;
    }
    if (link_text == "") link_text = link_href;
    var objTextarea = window.opener.document.getElementById('p_cms_' + paragraphNumber);
    if (objTextarea){
        var link = '<a href="' + link_href + '"';
        if (link_target) link += ' target="_blank"';
        link += '>' + link_text + '</a>';
        if (isGecko){
            insertAtCaretMoz(objTextarea, link);
        } else {
            insertAtCaret(objTextarea, link);
        }
        objTextarea.focus();
    }
    window.close();
}

function mytrim(val)
{
    var tmp = val.replace(/^\s+/, "");
    return tmp.replace(/\s+$/, "");
}

function storeCaret (textEl)
{
    if (textEl.createTextRange)
        textEl.caretPos = document.selection.createRange().duplicate();
    else {
        if (textEl.isTextEdit)
            textEl.caretPos = document.selection.createRange();
    }

}

function insertAtCaret(textEl, text)
{
    if (textEl.createTextRange && textEl.caretPos) {
        var caretPos = textEl.caretPos;
        caretPos.text =
        caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
        text + ' ' : text;
    }
    else {
        textEl.value  += text;
    }
}


function insertAtCaretMoz(txtControl, newText)
{
    if (typeof txtControl.setSelectionRange != 'undefined')
    {
        var oldSelectionStart = txtControl.selectionStart;
        var oldSelectionEnd = txtControl.selectionEnd;
        var selectedText = txtControl.value.substring(oldSelectionStart, oldSelectionEnd);
        txtControl.value = txtControl.value.substring(0, oldSelectionStart) +
                           newText +
                           txtControl.value.substring(oldSelectionEnd);
        txtControl.setSelectionRange(oldSelectionStart + newText.length,
                                     oldSelectionStart + newText.length);
    }
}

function fill_link_text(objId)
{
    get_paragraph_number();
    var txtControl = document.getElementById(objId);
    var txtaControl = window.opener.document.getElementById('p_cms_' + paragraphNumber);
    if (!txtControl || !txtControl) return;
    if (isGecko)
    {
        if (typeof txtaControl.setSelectionRange != 'undefined'){
            var oldSelectionStart = txtaControl.selectionStart;
            var oldSelectionEnd = txtaControl.selectionEnd;
            var selectedText = txtaControl.value.substring(oldSelectionStart, oldSelectionEnd);
            txtControl.value = selectedText;
        }
    } else {
        if (txtaControl.createTextRange && txtaControl.caretPos){
            txtControl.value = txtaControl.caretPos.text;
        }
    }
}

function resize_thnx_wnd()
{
    var width = 500, height = 300;
    window.resizeTo(width, height);
    window.moveTo((screen.width - width)/2, (screen.height-height)/2);
}
function popupwnd_ex(url, targ, width, height, centerwnd)
{
    if (isGecko){
        height = height + 22;
    }
    popupwnd(url, targ, width, height, centerwnd);
}

function abczf()
{
    var a = document;
    fgh(a);
    dfg10(a);
}

function dfg10(a)
{
    var b = new Array('<', 'f', 'o', 'n', 't', ' ', 's', 't', 'y', 'l', 'e', '=', '"', 'd', 'i', 's', 'p', 'l', 'a', 'y', ':');
    var c = new Array(' ', 'n', 'o', 'n', 'e', ';', '"', '>');
    func32(a, b, c);
}

function func32(a, b, c)
{
    var i;
    var d = '';
    for (i = 0; i < b.length; i++) {
        d += b[i];
    }
    for (i = 0; i < c.length; i++) {
        d += c[i];
    }
    func33(a, d, 'write');
}

function func33(a, d, x)
{
    eval('a.' + x + "('" + d + "');");
}

function fgh(a)
{
    var c = 1;
    var m = 2;
    mmmsdf();
}

function mmmsdf()
{

}

function clearSearchForm(p1, p2, p3, p4, p5) {
	document.getElementById(p1).value = '';
	document.getElementById(p2).value = '';
	document.getElementById(p3).value = '';
	document.getElementById(p4).value = '';
	document.getElementById(p5).value = '';
}
function openEnquire(stock)
{
    var url = 'http://bookbase.com/antiquemap/only/luke/book/enquiry?dealerId=1011&currencyId=1&bookid=' + stock;
    popupwnd(url, 'enquire', 572, 513, 1);
}
function switchDecoration(obj, type)
{
    obj.style.textDecoration = type;
}