function objectExists()
{
	if (typeof document.getElementById == 'undefined') 
	{
		return false;
	}
	else if (typeof document.createTextNode == 'undefined') 
	{
		return false;
	}
	else if (typeof document.getElementsByTagName == 'undefined') 
	{
		return false;
	}
	else {
		return true;
	}
}

function MM_openBrWindow(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}

/* -----------------------------------------------------------------------------------------
* Opens links with attribute rel="external" in a new window.
----------------------------------------------------------------------------------------- */
function externalLinks() 
{
	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && 
			anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
		
	}
}

/** -----------------------------------------------------------------------------------------
* Toggles an element's visibility.
* @param {id} targetId - the id of the element to be toggled.
----------------------------------------------------------------------------------------- */
function toggle (targetId) 
{
	if (document.getElementById) 
	{
		var target = document.getElementById(targetId);
		
		if (target.style.display == "none") 
		{
			target.style.display = "block";
		} else 
		{
			target.style.display = "none";
		}
	}	
}



/** -----------------------------------------------------------------------------------------
* Makes an element visibile.
* @param {id} targetId - the id of the element to be displayed.
----------------------------------------------------------------------------------------- */
function show (targetId) 
{
	if (document.getElementById) {
			var target = document.getElementById(targetId);
			
			if (target.style.display == "none") {
					target.style.display = "block";
			} else return false;
	}	
}


/** -----------------------------------------------------------------------------------------
* Hides an element.
* @param {id} targetId - the id of the element to be hidden.
----------------------------------------------------------------------------------------- */
function hide (targetId) 
{
	if (document.getElementById) {
			var target = document.getElementById(targetId);
			
			if ( (target.style.display == "block") || (target.style.display == "") ) {
					target.style.display = "none";
			} 			
	}	
}



/* ------------- Image Popups ------------- */

/** -----------------------------------------------------------------------------------------
* Adds the onclick popup attribute to appropriate links
----------------------------------------------------------------------------------------- */

function addImgPopTrigger () 
{
	if (!document.getElementsByTagName) return false;
	
	var links = document.getElementsByTagName("a");
	
	if (links) 
	{
		for (var i=0; i < links.length; i++) 
		{
			var anchor = links[i];
			
			if (anchor.className.match("popImg")) 
			{
				anchor.onclick = function() 
				{
					imgPop (this.href, this.title); 
					return false;
				}
			}
		} // end loop
		
	} else return false;
	return null;	
}

function imgPop (imageURL,imageTitle) 
{
	//pass both parameters in the URL
	var newWin = window.open( "assets/pop_img.htm?"+imageURL+"?"+imageTitle, "popImg",  'status=yes,scrollbars=no,resizable=yes,width=600,height=600');
}


function closeWin () 
{
	self.close()	
}

function removeRectagle() 
{
	if (!document.getElementsByTagName)
	{
		return false;
	}
	var links = document.getElementsByTagName('a');
	
	if (objectExists(links)) 
	{
        for (var i = 0; i < links.length; i++) 
		{
            links[i].onmousedown = function() 
			{
                this.blur();
                return false;
            }
        }
    }
}

/** 
* Obfuscates provided string.
* @param {string} text text to be obfuscated.
* @return {string}
*/
function obfuscate (text)
{
    var obfuscated = '';
    for (i = 0; i < text.length; i++) {
		obfuscated += "&#" + text.charCodeAt(i);
	}
	return (obfuscated);
}

/** 
* Writes the obfuscated mailto link to the page.
* @param {string} mailbox - Mailbox user name.
* @param {String} link_text - with the link text.
* @return {html mailto link}
*/
function writeAddress(mailbox,domain,link_text,mailto) 
{
    if(mailbox=='') {
        mailbox='info';
    } 
    if(domain=='') {
        var domain='domainname.com';
    }
    
    var email=mailbox+'@'+domain;
    var email_obf=obfuscate(email);
    
    if(mailto) {
        if(link_text=='') {
            var link_text_obf=email_obf;
        } else {
            var link_text_obf=obfuscate(link_text);
        }
        document.write('<a href="mailto:'+email_obf+'" '+'title="Start your email client to send message to: '+email_obf+'">'+link_text_obf+'</a>');
    } else {
        document.write(email_obf);
    }
}

window.onload=function(e)
{
	addImgPopTrigger ();
	//externalLinks ();
	//removeRectagle () ;
}


