// the functions in this file require the supplementary library lib.js

// These defaults should be changed the way it best fits your site
var _POPUP_FEATURES = '';
var _POPUP_SMALL_FEATURES = 'width=350,height=400,scrollbars=1,resizable=1,status=0,toolbar=0';
var _POPUP_MEDIUM_FEATURES = 'width=450,height=450,scrollbars=1,resizable=1,status=0,toolbar=0';
var _POPUP_LARGE_FEATURES = 'width=600,height=600,scrollbars=1,resizable=1,status=0,toolbar=0';
var _POPUP_LARGER_FEATURES = 'width=700,height=700,scrollbars=1,resizable=1,status=0,toolbar=0';

function raw_popup(url, target, features,id) {
	//alert("Raw_POp memthod. " + url);
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target )) target   = '_blank';
    //alert("Features.." + features + ", Target.. " + target + ", URL.." + url);
    var theWindow = window.open(url, target, features);

    // set focus to window, throw error if window does not exist
    try { 
    theWindow.focus(); 
    //print temporary cards and receipts
   //Commented for defect # 2004
   /*if(id=='detail'||id=='temp'){
    	//alert("Calling to open the printer window.."+id);
	    theWindow.print();
    }*/
    //Commented for defect # 2004
    }
    catch(er) {
	//alert("Unable to open new window, please check for a pop-up blocker");
    }
}

function offset_popup(url, target, offset){
    var width = 600;
    var height = 600;
    if(offset != null){
        offset = parseInt(offset);
        width = screen.width - (2 * offset);
        height = screen.height - (2 * offset);
    }
    var features = "left=" + offset + ",top=" + offset + ",width=" + width + ",height=" + height + ",scrollbars=1,resizable=1,status=0,toolbar=0";
    raw_popup(url, target, features);
}


function link_popup(src, features, url,id) {
	//alert("target..." + src.getAttribute('target') );
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features,id);
     //window.open(src.getAttribute('href'), '_new', '');
}

function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}

function event_popup_features(features) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { link_popup(e.currentTarget, features); e.preventDefault() }
}


// redefining default features
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=190,height=140';

listen('load', window, function() {
	listen('click', 'popup-listen', event_popup );
	listen('click', 'popup-feat'  , event_popup_features('location=0,statusbar=1,menubar=1,width=190,height=300') );
	mlisten('click', getElementsByClass('popup','a'), event_popup );
});


//Added for defect # 152 & 154 - Start
function window_popup(src, features) {
     var newWIndowObj = window.open(src.getAttribute('href'), '_new', 'menubar=1,resizable=1,location=1,status=1,scrollbars=1,titlebar=1,toolbar=1,left=10,width=900,height=575');
}

//Added for defect # 152 & 154 - End


