
// 3/5/07 - SMT 13253 - BA - added this file to hold common JS functions
// 3/12/07 - SMT 13253 - BA - added the popup window functions
//3/28/07 - BA - SMT 13324 - added the emailArticle function
//5/15/2007 - SMT 13512 - BA - added the content wizard functions
// 08/29/2007 smt 13807 DMaison, added shareArticle function 

//only used on this page
var iCustomer = {
	defaults: {
		popupWidth: '700',
		popupHeight: '550'
	}
}


/**************************************************
 DESCRIPTION: launches printable version
***************************************************/
function left(str, n) {
	alert(this);
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n) {
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


/**************************************************
 DESCRIPTION: generic function that populates the 
	onLoad event with multiple functions
***************************************************/
//update print.asp to use jQuery and then DELETE!
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/**************************************************
 DESCRIPTION: creates a standard popup window
***************************************************/
//only used for the "Add Content Containers" admin link in lib/containers.asp
function popup(url) {
	void window.open(url, 'winPopup', 'height='+ iCustomer.defaults.popupHeight +', width='+ iCustomer.defaults.popupWidth +', scrollbars, toolbar, resizable');
	return false;
}

/**************************************************
 DESCRIPTION: converts the given link to a popup
***************************************************/
//DELETE! - not used
function convertLinkToPopup(link) {
	//make sure the DOM is available
	if( document.getElementById && document.getElementsByTagName ) {
		link.onclick = function() {
			//if there is already a javascript pseudo protocol, don't popup new window
			if(left(this.getAttribute('href'),11) != 'javascript:')
				return popup(this.getAttribute('href'));
			else
				return true;
		};
	}
}

/**************************************************
 DESCRIPTION: converts all links descending from
	passed object into popup windows
***************************************************/
//DELETE! - not used
function createPopupsForDescendants(objRoot) {
	//make sure the DOM is available
	if( document.getElementById && document.getElementsByTagName ) {
		//make sure the root object exists
		if(objRoot) {
			var links = objRoot.getElementsByTagName( 'a' );
			for( var i=0; i < links.length; i++ ) {
				convertLinkToPopup(links[i]);
			}
		}
	}

}

/**************************************************
 DESCRIPTION: converts all links to popup windows
***************************************************/
// only used on Print.asp (also calls above 2 functions), so move there and/or refactor/delete
function linksToPopups() {
	createPopupsForDescendants(document);
}
