// JavaScript Document
//gets the document properties in order to use them as there are many types of browers with different versions

function getDocID(tagLayer)

{

            var tagProp = "";//holds the proerties of tagLayer

 

            //gets the whichLayer Properties depending of the differnt bowers the user is using

            if (document.getElementById)//this is the way the standards work

                        tagProp = document.getElementById(tagLayer);

            else if (document.all)//this is the way old msie versions work

                        tagProp = document.all[tagLayer];

            else if (document.layers)//this is the way nn4 works

                        tagProp = document.layers[tagLayer];

                       

            return tagProp;

}//end of getDocID()

 

//starts up the page

function startUp()

{

            var oldonload=window.onload;//holds any prevs onload function from the js file

 

            //gets the onload window event checks if there is a function that is already in there

            window.onload=function(){

                        if(typeof(oldonload)=='function')

                                    oldonload();

                                                                                                                                                                                   

                        //finds which browser the user is using for Firefox it is the defult

                        //for IE

                        if (navigator.userAgent.indexOf('MSIE') != -1)

                        {                                                          

                                    //checks if browser is IE 8

                                    if(navigator.appVersion.indexOf('MSIE 8') != -1)

                                    {

                                                
												var divNavContact = getDocID('divNavContact');
												var divNavListings = getDocID('divNavListings');
												var divNavHistory = getDocID('divNavHistory');
												var divNavFacilities = getDocID('divNavFacilities');
												var divNavDirector = getDocID('divNavDirector');
 

                                                //checks if there the page is in the Product Details

                                                if(divNavContact != null)

                                                {

                                                            divNavContact.style.padding = "5px 9px 3px 11px;";
															divNavListings.style.padding = "5px 9px 3px 11px;";
															divNavHistory.style.padding = "5px 9px 3px 11px;";
															divNavFacilities.style.padding = "5px 9px 3px 11px;";
															divNavDirector.style.padding = "5px 9px 3px 11px;";

                                                }//end of if

 

                                    }//end of if

                        }//end of if

                        //for Safari and Mac

                        else if (navigator.userAgent.indexOf('Safari') !=-1 || navigator.platform.indexOf("Mac") > -1)

                        {

                                   

                        }//end of if else

                        //for firefox

                        else if (navigator.userAgent.indexOf('Firefox') !=-1)

                        {

                        }//end of if else

                        //for Opera

                        else if (navigator.userAgent.indexOf('Opera') !=-1)

                        {

                                   

                        }//end of if else

            }//end of window.onload=function()

}//end of startUp()


//Adds text to any part of the body of a HTML
function addNode(tagParent,strText,boolAddToBack, boolRemoveNode)
{
  var strNode = document.createTextNode(strText);//holds the test which will be added
   
  //gets the properties of the node
  tagParent = getDocID(tagParent);
  
  //checks if the user whats to replace the node in order to start with a clean slate
  //it also checks if there is a chode node to replace
  if (boolRemoveNode == true && tagParent.childNodes.length > 0)
	//replaces the current node with what the user wants
	tagParent.replaceChild(strNode,tagParent.childNodes[0]);
  else
  {
  	//checks if the user whats to added to the back of the id or the front
  	if(boolAddToBack == true)
		tagParent.appendChild(strNode);
  	else
		//This is a built-in function of Javascript will add text to the beginning of the child
  		insertBefore(strNode,tagParent.firstChild);
  }//end of if else
  
  //returns the divParent in order for the user to use it for more uses
  return tagParent;
}//end of addNode()

//removes from view all tags in tagContainer with the expection of tagActive
//It assumes the tagActive and tagContiner already have the properties
function classToggleLayer(tagContainer,tagActive,strClassName,strTAGName)
{
	var arrTAG = tagContainer.getElementsByTagName(strTAGName);//holds all strTAGName in tagContainer
	
	//goes around the for each tag that getElementsByTagName found in tagContainter
	for(var intIndex = arrTAG.length - 1; intIndex > -1 ; intIndex--) 
	{
		//checks if the class name is the same as strClassName and it is not active if it is active then change the dispaly to block
		if(arrTAG[intIndex].className == strClassName && arrTAG[intIndex].id != tagActive.id)
			arrTAG[intIndex].style.display = arrTAG[intIndex].style.display? "":"";
		else if(arrTAG[intIndex].id == tagActive.id && tagActive.style.display == "")
			arrTAG[intIndex].style.display = arrTAG[intIndex].style.display? "":"block";
	}//end of for loop
}//end of classToggleLayer()

//does the display the a message in a on the page weather then an alert
function displayMessage(tagMessage,strMessText,boolAddToBack, boolRemoveNode)
{
	//gets the message properties and sets the text furthermore it does the display
	tagMessage = addNode(tagMessage,strMessText,boolAddToBack, boolRemoveNode);
	tagMessage.style.display = "block";	
	
	return tagMessage;
}//end of displayMessage()

//this is for the duel layers that sometimes is need
function duelToggleLayer(whichLayer,layer1,layer2)
{
	var activeLayer = "";//holds the active Layer	
	var style2 = "";//holds the style of layer1
	var style3 = "";//holds the style of layer2

	// this is the way the standards work
	if (whichLayer != ''){activeLayer = getDocID(whichLayer);}
	if (layer1 != ''){style2 = getDocID(layer1);}
	if (layer2 != ''){style3 = getDocID(layer2);}

	//Checks if there is an active layer
	if (activeLayer != "")
	{
		//checks if the activeLayer is already active and if so then skips code
		//since the layer cannot be turn off and leave a hole in the review layer
		if (activeLayer.style.display == "")
		{
			//removes the block from the display in order to make the layer to disapper	
			if (style2 != ''){style2.style.display = style2.style.display? "":"";}

			//checks if there is a style3
			if (style3 != ''){style3.style.display = style3.style.display? "":"";}
	
			//displays the new active Layer and updates its id
			activeLayer.style.display = activeLayer.style.display? "":"block";
		}//end of if
	}//end of if
}//end of duelToggleLayer()

//gets the document properties in order to use them as there are many types of browers with different versions
function getDocID(tagLayer)
{
	var tagProp = "";//holds the proerties of tagLayer

	//gets the whichLayer Properties depending of the differnt bowers the user is using
	if (document.getElementById)//this is the way the standards work
		tagProp = document.getElementById(tagLayer);
	else if (document.all)//this is the way old msie versions work
		tagProp = document.all[tagLayer];
	else if (document.layers)//this is the way nn4 works
		tagProp = document.layers[tagLayer];
		
	return tagProp;
}//end of getDocID()

//removes all new lines and replaces them with a <br/> html tag
function nl2br(strText)
{
	//checks if there is anything inside strText
	if (strText != "")
	{
 		var re_nlchar = "";//holds the different newlines that the OS uses
		strText = escape(strText);//in codes strText to be more like a URL to find the newlines
			
		//finds the either \r or \n or both since \r is for Linex and Apple and \n is for MS
		if(strText.indexOf('%0D%0A') > -1)
			re_nlchar = /%0D%0A/g ;
		else if(strText.indexOf('%0A') > -1)
			re_nlchar = /%0A/g ;
		else if(strText.indexOf('%0D') > -1)
			re_nlchar = /%0D/g ;
	
		//checks if there is any new lines in strText
		if (re_nlchar != "")
			//changes the strText back to normal with all of the newlines changes to <br/> tag
			return unescape(strText.replace(re_nlchar,'<br />'));
	}//end of if
	
	return strText;
}//end of nl2br()

//shoes and hides a <div> using display:block/none from the CSS
function toggleLayer(tagLayer,tagGrayOut)
{
	var tagStyle = '';//holds the style of tagLayer

	//gets the tagLayer and tagGrayOut Properties
	tagStyle = getDocID(tagLayer);
	tagGrayOut = getDocID(tagGrayOut);
	
	if (tagStyle != null){tagStyle.style.display = tagStyle.style.display? "":"block";}
	if (tagGrayOut != null)
	{
		tagGrayOut.style.display = tagGrayOut.style.display? "":"block";

		//for IE
		if (navigator.userAgent.indexOf('MSIE') != -1)
		{
			tagGrayOut.attachEvent('onclick',function () {
				toggleLayer(tagStyle.id,tagGrayOut.id)
			});
		}//end of if
		//for the other browsers
		else
		{
			tagGrayOut.addEventListener('click',function () {
				toggleLayer(tagStyle.id,tagGrayOut.id);
			},false);
		}//end of else
	}//end of if
}//end of toggleLayer()

//does the search bar onForcus Event
function searchBarForce(tagContainer,strClassName,strTAGName,strColor,strValue)
{
            //gets the search bar properties
            var arrTAG = getDocID(tagContainer).getElementsByTagName(strTAGName);//holds all strTAGName in tagContainer
 
            //goes around the for each tag that getElementsByTagName found in tagContainter
            for(var intIndex = arrTAG.length - 1; intIndex > -1 ; intIndex--)
            {
                        //checks if the class name is the same as strClassName
                        if(arrTAG[intIndex].className == strClassName)
                        {
                                    //changes the color and text to blank when the user frocus on the textbox
                            arrTAG[intIndex].style.color = strColor;
                        arrTAG[intIndex].value = strValue;
                        }//end of if
            }//end of for loop
}//end of searchBarForce()
 
//does the search bar onblur Event(focus off)
function searchBarFocusOff(tagContainer,strClassName,strTAGName,strColor,strValue)
{
            //gets the search bar properties
            var arrTAG = getDocID(tagContainer).getElementsByTagName(strTAGName);//holds all strTAGName in tagContainer
 
            //goes around the for each tag that getElementsByTagName found in tagContainter
            for(var intIndex = arrTAG.length - 1; intIndex > -1 ; intIndex--)
            {
                        //checks if the class name is the same as strClassName
                        if(arrTAG[intIndex].className == strClassName)
                        {
                                    if(arrTAG[intIndex].value=="")
                                    {
                                                //changes the color and text when the user leave the textbox
                                    arrTAG[intIndex].style.color = strColor;
                                                arrTAG[intIndex].value = strValue;
                                    }//end of if         
                        }//end of if
            }//end of for loop
}//end of searchBarFocusOff()

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

 

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

 

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

 

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

 


