////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//													UTILITY FUNCTIONS												  //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function contntDiv() 
{
	return $('pageContent');
}

function agentSelectChanged(event) {
	populateSelect($('suburbSelect'), "loading Suburbs...", "data/getSuburbsForAgent.php", Form.Element.serialize($('agentSelect')));
}

function set_delay_height(element,height)
{
	var element = $(element) 
	element.style.height = height;
}

function link(linklocation)
{
	window.opener.document.location.href=linklocation
}

function sortPropListFeatures(selectField)
{
	
	var convertedString = "";
	//Loop through the values from the selected field (multiple select)
	for (var count = 0; count < selectField.options.length ;count++)
		{
		
			//To make sure that a '/' is not inserted before the first value
			if (count > 0)
				{
					//Use the '/' to seperate the different
					convertedString += "|";
				}
			//Find the position of the brackets
			//If the amount is 1, then no brackets will be found
			firstIndex = selectField.options[count].text.lastIndexOf("[");
			lastIndex  = selectField.options[count].text.lastIndexOf("]");

			//Check to see if the amount is greater than 1
			if (firstIndex > 0 && lastIndex > 0 && lastIndex > firstIndex)
				{
					var amount      = parseFloat(selectField.options[count].text.substring(firstIndex + 1 , lastIndex), 10);
					var description = selectField.options[count].text.substring(0, firstIndex);
					var valueID     = selectField.options[count].value;
					//Add the ID, value description , amount seperated by ','
					convertedString += valueID + "," + description + "," + amount;
				}
			else
				{
					var description = Trim(selectField.options[count].text);
					var valueID     = selectField.options[count].value;
                    //Add the ID, value description , amount of 1 seperated by ','
					convertedString += valueID + "," + description + ",1";
				}
		}
	//Assign the string to hidden variable
	return convertedString;		
	
}
/////////////////////////////////////////////////////////////////-------------------------------
function createOverlay()
{
            if(!document.getElementById('overlay'))
            {
                        var objBody = document.getElementsByTagName("body").item(0);
                        var objOverlay = document.createElement("div");
                        objOverlay.setAttribute('id','overlay');
                        objOverlay.style.display = 'none';
                        //objOverlay.onclick = function() { displayTeams(); return false; }
                        objBody.appendChild(objOverlay);
            }
}

function getPageScroll()
{
            var yScroll;

            if (self.pageYOffset) 
			{
                yScroll = self.pageYOffset;
            } 
			else if (document.documentElement && document.documentElement.scrollTop)
			{  // Explorer 6 Strict
                yScroll = document.documentElement.scrollTop;
            } 
			else if (document.body) 
			{// all other Explorers
                        yScroll = document.body.scrollTop;
            }
            arrayPageScroll = new Array('',yScroll) 
            return arrayPageScroll;
}

// getPageSize()

// Returns array with page width, height and window width, height

// Core code from - quirksmode.org

// Edit for Firefox by pHaez

function getPageSize()
{
            var xScroll, yScroll;

            if (window.innerHeight && window.scrollMaxY)
			{    
                xScroll = document.body.scrollWidth;
                yScroll = window.innerHeight + window.scrollMaxY;
            } 
			else if (document.body.scrollHeight > document.body.offsetHeight)
			{ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } 
			else 
			{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            var windowWidth, windowHeight;

            if (self.innerHeight) 
			{       // all except Explorer
                windowWidth = self.innerWidth;
                windowHeight = self.innerHeight;
            } 
			else if (document.documentElement && document.documentElement.clientHeight) 
			{ // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } 
			else if (document.body) 
			{ // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }           
            // for small pages with total height less then height of the viewport
            if(yScroll < windowHeight)
			{
               pageHeight = windowHeight;
            } 
			else 
			{ 
               pageHeight = yScroll;
            }
            // for small pages with total width less then width of the viewport
            if(xScroll < windowWidth)
			{           
                pageWidth = windowWidth;
            } 
			else 
			{
                pageWidth = xScroll;
            }
            arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

            return arrayPageSize;
}

function displayTeams()
{
        var arrayPageSize = getPageSize();
        var arrayPageScroll = getPageScroll();

        if($('addfinish').visible())
        {
                Effect.Fade($('addfinish'),{queue: 'end', scope: 'togglebar', duration:1})
                $('overlay').style.display = 'none';
        }
        else
        {
                createOverlay();             
                $('addfinish').style.top = (arrayPageScroll[1] + (arrayPageSize[3] / 2)) + "px";
                $('addfinish').style.left = (arrayPageSize[2] / 3) + "px";
                Effect.Appear($('addfinish'),{queue: 'end', scope: 'togglebar', duration:1})
                $('overlay').style.height = (arrayPageSize[1]) + "px";
                $('overlay').style.display = 'block';
        }
}