function OpenCataloguePopup () {
    $.getScript("/javascript/catalogue.js.php"); 
    OpenPopup("/sections/prophoto/ajax/order_catalogue.php");
}

function OnSubjectChange(elm, ref) {
    subjectuuid = elm.options[elm.selectedIndex].value;
    document.location.href = '/sections/prophoto/packages.php?subjectUuid=' + subjectuuid + '&ref=' + ref
}

function OnInputFocus(elm) {
    orgtext = elm.getAttribute("realname");
    value = elm.value;
    realtype = elm.getAttribute("realtype");
    faketype = elm.getAttribute("faketype");
    name = elm.getAttribute('name');


    if (value == orgtext) {
        /*
        elm.value = '';
        elm.type = realtype; 
        elm.setAttribute("class", "textbox");
        */
        oldElm = jQuery(elm); 

        // Duplicate stuff:
        newElm = jQuery("<input type="+realtype+" onblur='OnInputBlur(this)' onfocus='OnInputFocus(this)'></input>");
        newElm.attr('realname', orgtext);
        newElm.attr('value', '');
        newElm.attr('realtype', realtype);
        newElm.attr('faketype', faketype);
        newElm.attr('class', 'ftextbox');
        newElm.attr('name', name);
        newElm.css('width', oldElm.css('width'));

        oldElm.replaceWith(newElm);
        // we need a short sleep here:
        newElm.trigger('focus');
        setTimeout("addElementTrigger()", 100);
    }
    return true;
}

function addElementTrigger() {
   newElm.trigger('focus');
}

function OnInputBlur(elm) {

    orgtext = elm.getAttribute("realname");
    value = elm.value;
    realtype = elm.getAttribute("realtype");
    faketype = elm.getAttribute("faketype");
    name = elm.getAttribute('name');

    if (faketype == null || faketype == "null") faketype = realtype;

    if (value == '') {
        oldElm = jQuery(elm);
        /*
        elm.value = orgtext;
        elm.type = faketype; 
        elm.setAttribute("class", "textboxhelp");
        */

        newElm = jQuery("<input type="+faketype+" onblur='OnInputBlur(this)' onfocus='OnInputFocus(this)'></input>");
        newElm.attr('realname', orgtext);
        newElm.attr('value', orgtext);
        newElm.attr('realtype', realtype);
        newElm.attr('faketype', faketype);
        newElm.attr('class', 'ftextboxhelp');
        newElm.attr('name', name);
        newElm.css('width', oldElm.css('width'));


        oldElm.replaceWith(newElm);
 
    }
    return true;
}

this.imagetooltip = function(){	
	/* CONFIG */		
    xOffset = 10;
    yOffset = 30;		

	/* END CONFIG */		
    jQuery("a.image-tooltip").click(function(e) { return false; } );
	jQuery("a.image-tooltip").hover(function(e) {											  
		jQuery("body").append("<img style='position: absolute;' id='image-tooltip' src='"+ this.href +"'/>");
		jQuery("#image-tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
        },

	    function(){
		    jQuery("#image-tooltip").remove();
        });	

	    jQuery("a.image-tooltip").mousemove(function(e){
		    jQuery("#image-tooltip")
		    	.css("top",(e.pageY - xOffset) + "px")
		    	.css("left",(e.pageX + yOffset) + "px");
	    }
    );			

};


