

function setBrowserTitle(_t) {
    //alert("setBrowserTitle(" + t + ")");
    document.title=_t;
}

function setBrowserAnchorLink(_l) {
    //alert("setBrowserAnchorLink(" + l + ")");
    // There seems to be a bug in Firefox 3.0.X which causes the Gliffy application to reload when setting the location hash (GLIFFY-1788)
    if( lz.embed.browser.isFirefox && lz.embed.browser.version < 3.5 ) {
        //do nothing to avoid bug
    } else { 
        window.location.hash=_l;
    }
}

function setCookie(_key,_value) {
    //alert("setCookie:" + _key + ":" + _value );
    var cookieVal = '';
    cookieVal += _key + '=' + _value; 
    cookieVal += ' ; expires=Friday, 13-Dec-20 13:13:13 GMT';
    cookieVal += ' ; path=/'; 
   
    document.cookie=cookieVal; 
} 

function setSaveWarning(b) {
    //this MUST be the first line.  Otherwise, Firefox seems to delay execution
    saveWarning = b;		
    //alert('setSaveWarning:' + b ); 
    //#alert('actual saveWarning is:' + saveWarning );
}
	
function flashPutHref(href) { 
	if( lz.embed.browser.isSafari ) location.href = href; 
}
	
function flashPutTitle(title) { 
    var codes = title.split(',');
    var newtitle = ''; 

    //decode UTF-8 encoded string (see utils.lzx for more info)
    for( var i = 0; i < codes.length; i++ ) {
       newtitle = newtitle + String.fromCharCode(Number(codes[i]));
    }

	document.title = newtitle; 
} 

//thanks to http://www.quirksmode.org for this function
function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') 
            c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) 
            return c.substring(nameEQ.length,c.length);
    }
    return null;
} 
	


function setParamStr() { 
   
    if( typeof paramStr != 'undefined' && paramStr != '' ) { 
        lz.embed.setCanvasAttribute('paramStr', paramStr ); 
    }     

    
}
         
function setEmailParam() { 
    if( paramBundle.e != null ) {
		lz.embed.setCanvasAttribute('emailParam', paramBundle.e ); 
        
    }     
}

function closeCurrentWindowAndReloadOpener(action) { 
    if( action == 'RELOAD' ) { 
        window.opener.location.reload(true); 
    } 
    self.close();
}

function setDidParam() { 
    if( didParam != null ) {
        lzSetCanvasAttribute('didParam', didParam ); 
    }
} 


function checkIt(string) {
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}

// this function is used from IE to export to svg or jpg via the IFrame
function exportFile(args) {
	//alert("ExportFile:  args: " + args);
	// for export, we don't need to have the save warning on, cuz the app will save, 
	saveWarning = false;
	var appCtxt = args.substring(args.lastIndexOf("|") + 1);
	var params = args.substring(0, args.lastIndexOf("|"));
	
	//alert("appCtxt: " + appCtxt);
	//alert("params: " + params);
	
	var hf = document.getElementById('ExportIFrame');
	
	var api = "/clientexportimage";
	//alert("apiPath: " + appCtxt + api + params);
	hf.src = appCtxt + api + params;
}

	
// this function is used from IE to export the xml image map via the IFrame
function exportImageMap(args) {
	var appCtxt = args.substring(args.lastIndexOf("|") + 1);
	var params = args.substring(0, args.lastIndexOf("|"));
	
	var hf = document.getElementById('ExportIFrame');
	var api = "/clientexportimagemap";
	hf.src = appCtxt + api + params;
	
}

// File/Image Upload
function uploadFile(args) {
	var q = args.substring(0, args.indexOf("|")); // query
	var wwh = args.substring(args.indexOf("|") + 1); // width, height and path
	var awh = wwh.split('|');
	var w = awh[0]; // width
	var h = awh[1]; // height
	var path = awh[2]; // path
	var url = "/gliffy/uploadFile.jsp" + q;
	var fctn = "width=400,height=100"  + ",left=" + (w/2 -75) + ",top=" + (h/2) + ",screenX=" + (w/2-75) + ",screenY=" + (h/2);
	window.open(url,'',fctn);
}
	
function uploadImage(args) {
	var q = args.substring(0, args.indexOf("|")); 
	var url = "/gliffy/uploadImage.jsp" + q;
	var fctn = "width=500,height=380,left=200,top=230,screenX=200,screenY=230";
	window.open(url,'',fctn);
}

function completeUpload(filename) {
	lz.embed.setCanvasAttribute('fileUploadComplete', filename); 
}
	
function completeImageUpload(args) {
	lz.embed.setCanvasAttribute('imageUploadComplete', args); 
}


//commerce
function launchAccountSelection(args) {
	var q = args.substring(0, args.indexOf("|"));
	//alert("here");
	var url = args;
	window.open(url);
}

function paymentComplete(args) {
	//alert("in gliffy.js paymentComplete()");
	lzSetCanvasAttribute('paymentComplete', args); 
}


function loadPage(args) {
	window.location=args;
}
	
function getObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId);
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId);
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}




