//<![CDATA[

//--------------------------------------------------------------------
// This code sets the default status for all pages
//--------------------------------------------------------------------
window.defaultStatus = "ByteCan - Worldwide Telecommunication Solutions";

//--------------------------------------------------------------------
// Setup menu DHTML system
//--------------------------------------------------------------------
addEvent(window, "load", function(){
	if (TransMenu.isSupported()) TransMenu.initialize();
});


//--------------------------------------------------------------------
// Gives focus to the first text input
//--------------------------------------------------------------------
addEvent(window, "load", function(){

	var inputs = document.getElementsByTagName("input");
	if ( null != inputs && inputs.length > 0 )
	{
		for( var i=0; i<inputs.length; i++)
		{
			var input = inputs[i];
			if ( input.type != "text" && input.type != "password" )
			{
				continue;
			}
			else
			{
				if (input.focus) input.focus();
				break;
			}
		}
	}	
});

//--------------------------------------------------------------------
// Opens the specified name and url in a new window
//--------------------------------------------------------------------
function openWindow(name, url)
{
	var newWin = window.open(url,'newWin','');
	if (newWin && newWin.focus)	
		newWin.focus();
}

//--------------------------------------------------------------------
// Opens a new window to display project photos
//--------------------------------------------------------------------
function openPhoto( file )
{
	//get screen mouse click coords
	var screenW = screen.width;
	var screenH = screen.height;
	
    var posx = 0;
	var posy = 0;
	
	if (!e) var e = window.event;
	if (e && e.pageX && e.pageY) 	
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e && e.clientX && e.clientY) 	
	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	var photoWin = window.open('/services/pop.html?file=' + file, 'photoWin', 'height=440,width=520,left=' + posx + ',top=' + posy + ',resizable=1,scrollbars=1,menubars=0,statusbar=0');
	if (photoWin && photoWin.focus)
		photoWin.focus()
}

//--------------------------------------------------------------------
// Changes main project photo to the specified
//--------------------------------------------------------------------
var photoDirPath = "/projects/images/";
function changePhoto( id )
{
	if (document.images)
	{
		document.images["RightContentPhoto"].src = photoDirPath + id + ".jpg";
	}
}


//----------------------------------------------------------
// Returns true if the specified string is empty or equivalent
//----------------------------------------------------------
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

//----------------------------------------------------------
// Attaches a function to the event of specified object
// @param obj the object the event is being attached to
// @param eventType the event type (e.g. "load")
// @param fn the function to attach
//----------------------------------------------------------
function addEvent(obj, eventType, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(eventType, fn, true);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on" + eventType, fn);
		return r;
	}
	else
	{
		return false;
	}
}

//----------------------------------------------------------
// Cookie cutter approach to retrieving event source
//----------------------------------------------------------
function getEventSrc(e)
{
	//get a reference to the ie/windows event object
	if (!e) e = window.event;
	
	//DOM-Compliant name of the event source
	if(e.target)
		return e.target;
	
	//IE/Windows name of event source property
	else if (e.srcElement)
		return e.srcElement;
}

//----------------------------------------------------------
// Browser safe get object function
//----------------------------------------------------------
function getObject( id ) 
{
	if ( document.all ) 
		return document.all.item( id );
	else if ( document.getElementById ) 
		return document.getElementById( id );
}

//----------------------------------------------------------
// Toggles the display state of the specified object
//----------------------------------------------------------
function toggleDisplay( id )
{
	var obj = getObject(id);
	if ( obj.style && obj.style.display )
	{
		if (obj.style.display == "none")
			obj.style.display = "block";
		else
			obj.style.display = "none";
	}
}

//----------------------------------------------------------
// Get HTTP Request Object
//----------------------------------------------------------
function getHttpRequestObject()
{
	var xmlhttp=false;
	try 
	{//IE
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{//IE old
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{//Mozilla and Safari
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) 
	{//Ice Browser
		try 
		{
			xmlhttp = window.createRequest();
		} 
		catch (e) 
		{
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

//----------------------------------------------------------
// Trims leading and trailing spaces from specified string
//----------------------------------------------------------
function trimString(s) 
{
	s = s.replace( /^\s+/g, "" );// strip leading
	return s.replace( /\s+$/g, "" );// strip trailing
}

//----------------------------------------------------------
// Returns true if the url specified is valid
//----------------------------------------------------------
function isUrl(url)
{
	var urlPattern = /^(?:(?:ftp|http|gopher|nntp|news|file|mailto|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'&lt;&gt;()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'&lt;&gt;()\[\]{}\s\x7f-\xff]+)*)?/;
	return urlPattern.test(url.toLowerCase());
}

//----------------------------------------------------------
// Used to change images for menu
//----------------------------------------------------------
function changeImages() 
{
 	if (document.images) 
 	{
  		for (var i=0; i<changeImages.arguments.length; i+=2) 
  		{
    		document[ changeImages.arguments[i] ].src = eval(changeImages.arguments[i+1] + ".src");
   		}
 	}
}

//]]>
