/* Web design by First Coast Creative design@firstcoastcreative.net */

/* Browser Sniffer Class object

Read Article at http://www.firstcoastcreative.net/index.php?p=22
To use this as a means to style page based on browser type.

*/


function Initailize() {
	

	addEvent($('Store_Hours'),'mouseover',ShowStoreHours);
	addEvent($('Store_Hours'),'mouseout',rShowStoreHours);
	addEvent($('Store_Hours'),'click',redirect);
//	addEvent($('Consignors_Login'),'click',login);
//	addEvent($('signup'),'click',signup);
    addEvent($('homepic'),'click',showflash);
	addEvent($('homepic'),'mouseover',homepiccap);
	addEvent($('homepic'),'mouseout',rhomepiccap);
	RemoveCaption(id);
	
	
	
	
	
}

function historyChange(newLocation, historyData) {
            alert("A history change has occured: newLocation="+newLocation
                  + ", historyData="+historyData);
			
}



function signup(){
window.location="/clearinghouse/Consignors/?action=signup";	
	
}

function login(){
window.location="/clearinghouse/Consignors/";	
	
}

function ShowStoreHours() {
	
	ShowCaption('drimg','Store hours:',' 10 am - 6 pm Monday through Saturday','  12 pm - 6 pm Sunday','Address:',' 3729 Southside Blvd. Jacksonville, Florida 32216','350', 'onmouseover', 'right'); 
	
}

function rShowStoreHours(){
	
	RemoveCaption('_drimg');
	
}

function homepiccap() {
	
	
	ShowCaptionN('frimg','Click to see a panning photograph of our showroom.','350', 'onmouseover', 'right'); 
	
}

function rhomepiccap(){
	
	RemoveCaption('_frimg');
	
}

function showflash(){
	
	
new Element.show('flash');	



}




function redirect(){
	 window.location="?page=1home";

}

function BrowserType() {}

BrowserType.isAppleWebKit = function()
{
    var kitName = "applewebkit/";
    var tempStr = navigator.userAgent.toLowerCase();
    var pos = tempStr.indexOf(kitName);
    var isAppleWebkit = (pos != -1);

    return isAppleWebkit;
}

BrowserType.isInternetExplorer = function()
{
    if( document.all )
    {
		var agt = navigator.userAgent.toLowerCase();
		return agt.indexOf( "opera" ) == -1;
    }
    else
    {
        return false;
    }
}

BrowserType.isInternetExplorerMac = function()
{
    return navigator.appName.indexOf( "Microsoft Internet Explorer" ) > -1
        && navigator.appVersion.indexOf( "Macintosh" ) > -1;
}

BrowserType.isGecko = function()
{
    var ua = navigator.userAgent.toLowerCase();
    return ua.indexOf( 'gecko' ) > - 1;
}

BrowserType.getBrowserType = function()
{
    if( BrowserType.isInternetExplorerMac() )
    {
        return "iemac";
    }
    else if( BrowserType.isInternetExplorer() )
    {
        return "ie";
    }
    else if( BrowserType.isAppleWebKit() )
    {
        return "safari";
    }
    else if( BrowserType.isGecko() )
    {
        return "ff";
    }
    else
    {
        return "";
    }
}


// End Browser Sniffer Class


//pop up window

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

//pop up image window
function openImageWindow(image) {
var w = window.open("","", "resizable,status, width=800,height=800");
var d = w.document;
d.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
d.write('<html xmlns="http://www.w3.org/1999/xhtml">');
d.write('<head>');
d.write('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />');
d.write('<title>Image Viewer</title>');
d.write('</head>');
d.write('<body style="text-align:center; padding: 20px;">');
d.write('<img name="image" src=" ');
d.write(image);
d.write('" width= "400px"  style="border:1px solid #000;margin: 20px;"/>');
d.write('<br /><form><input type=button value="Close Window" onClick="javascript:window.close();"></form> </body></html> ');
d.close();
}	


///Dropdown Menu

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;


    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

/// Function to dynamically add a class to an element on a page by page basis, pick the div then make and assign new class with overrides
/* example: 

<script language="JavaScript">
change('front_promo', 'longpage');
</script>

*/

function change(id, newClass) {

	if (document.getElementById(id)) 
	{

	identity=document.getElementById(id);

	identity.className=newClass;
	}

}


/// Function to help long page layouts, pick the div then set the new height, no extra css needed
/* example: 

<script language="JavaScript">
change('content', '1200px');
</script>

*/

function changeHeight(id,newHeight) {
	if (document.getElementById(id)) 
	{
	element=document.getElementById(id);

	element.style.height=newHeight;
	}
}



//////////////////////////////////////////
// Max Length Functions for textarea
//
//////////////////////////////////////////


function addEvent(obj, evType, fn, useCapture){
        if (obj.addEventListener){
                obj.addEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
        }
        return false;
}
function removeEvent(obj, evType, fn, useCapture){
        if (obj.removeEventListener){
                obj.removeEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.detachEvent){
                var r = obj.detachEvent("on"+evType, fn);
                return r;
        }
        return false;
}

// Declare the namespace
var fdTextareaController;

// Define anonymous function
(function() {

        // Create object private to the anonymous function
        function fdTextareaMaxlength(inp, maxlength) {
                this._inp       = inp;
                this._max       = Number(maxlength);
                var self        = this;

                self.maxlength = function() {
                        if(self._inp.disabled) return false;

                        if(self._inp.value.length > self._max) {
                                self._inp.value = self._inp.value.substring(0,self._max);
                                return false;
                        }

                        return true;
                }
                addEvent(self._inp, 'keypress', self.maxlength, false);
                addEvent(self._inp, 'blur',     self.maxlength, false);
                addEvent(self._inp, 'focus',    self.maxlength, false);

                // IE only event 'onpaste'

                // conditional compilation used to load only in IE win.

                /*@cc_on @*/
                /*@if (@_win32)
                addEvent(self._inp, 'paste', function(){ event.returnValue = false; self._inp.value = window.clipboardData.getData("Text").substring(0,self._max); }, true);
                /*@end @*/
        };

        // Construct the previously declared namespace
        fdTextareaController = {
                textareas: [],

                _construct: function( e ) {

                        var regExp_1 = /fd_max_([0-9]+){1}/ig;

                        var textareas = document.getElementsByTagName("textarea");

                        for(var i = 0, textarea; textarea = textareas[i]; i++) {
                                if(textarea.className && textarea.className.search(regExp_1) != -1) {
                                        max = parseInt(textarea.className.match(regExp_1)[0].replace(/fd_max_/ig, ''));
                                        if(max) fdTextareaController.textareas[fdTextareaController.textareas.length] = new fdTextareaMaxlength(textarea, max);
                                }
                        }

                },

                _deconstruct: function( e ) {
                        /* TODO: Clean up for IE memory leaks.. */
                }
        }
// Complete the anonymous function and call it immediately.
})();


addEvent(window, 'load', fdTextareaController._construct, false);
addEvent(window, 'unload', fdTextareaController._deconstruct, false);


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}




///// AJAX Page Laoder

function FccAjaxLoader(el,url,id,parent)
{
    
	try {
	var current = document.getElementsByClassName('selected' , parent);
    current[0].className='';
	
	}catch(err) {
	
	};
    
	new Effect.Appear('loading');	
	new Ajax.Updater(el,url,{onComplete:function(){ 
	new Effect.Highlight(el);
    new Effect.Fade('loading');
    $(id).className='selected';
    
	}
	,asynchronous:true});
	
	createCookie('el',el);
	createCookie('url',url);
	createCookie('id',id);
	createCookie('parent',parent);
	
	
	
}



function history() {
	
	var el = readCookie('el');
	var url = readCookie('url');
	var id = readCookie('id');
	var parent = readCookie('parent')
	
	if (url != ''){
	
	new Effect.Appear('loading');	
	new Ajax.Updater(el,url,{onComplete:function(){ 
	new Effect.Highlight(el);
    new Effect.Fade('loading');
    $(id).className='selected';
    
	}
	,asynchronous:true});
	
	}else{
		
	return;	
		
	}
	
	
	
	
	
	
}


function ShowCaption(el,text1,text2,text3,text4,text5,w,e,col) {
    



	try { new Element.show('_'+el); }catch(err){ };
	
	if(!$('_'+el))
	{
    
	element = Builder.node('div',{ className:'caption', id:'_'+el },[Builder.node('div', text1),Builder.node('div', text2),Builder.node('div', text3),Builder.node('div', text4),Builder.node('div', text5) ]);	
	$('bodywrap').appendChild(element);	
	
	}
	element.style.position ='absolute';

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
		{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			posx = e.clientX + document.body.scrollLeft
						+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
						+ document.documentElement.scrollTop;
			
			
		}
	
	///colum left (defualt right or center )
	

	
	switch(col) {
		case 'right': posx = posx + w/.6;
		case 'center': posx = posx - w/1.5;
		default: posx = posx - w;		
	}
	
	
	
	posy = posy + 15;
	
	element.style.width =  w +'px' ;
	element.style.left =  posx +'px' ;
	element.style.top =   posy +'px' ;
	

	
}



function ShowCaptionN(el,text1,w,e,col){
    



	try { new Element.show('_'+el); }catch(err){ };
	
	if(!$('_'+el))
	{
    
	element = Builder.node('div',{ className:'caption2', id:'_'+el },[Builder.node('div', text1)]);	
	$('bodywrap').appendChild(element);	
	
	}
	element.style.position ='absolute';

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
		{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			posx = e.clientX + document.body.scrollLeft
						+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
						+ document.documentElement.scrollTop;
			
			
		}
	
	///colum left (defualt right or center )
	

	
	switch(col) {
		case 'right': posx = posx + w/.6;
		case 'center': posx = posx - w/1.5;
		default: posx = posx - w;		
	}
	
	
	
	posy = posy + 15;
	
	element.style.width =  w +'px' ;
	element.style.left =  posx +'px' ;
	element.style.top =   posy +'px' ;
	

	
}

function RemoveCaption(id){

	Element.remove(id);

}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	
	else if (obj.attachEvent)
	
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}


function loadmap() {
	
  togglemap();
	
  if (GBrowserIsCompatible()) {
    
   	var map = new GMap2(document.getElementById("map"));
	
	var geocoder = new GClientGeocoder();
	
	var address = '1902 2nd Avenue North Jacksonville Beach, FL';
	

	  geocoder.getLatLng(
	    address,
	    function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
	        map.setCenter(point, 13);
	        var marker = new GMarker(point);
	        map.addOverlay(marker);
	        marker.openInfoWindowHtml('<strong>Pace Systems Group, Inc.</strong> <br /><em>Corporate Headquarters</em> <br />1902 2nd Avenue North<br />Jacksonville Beach, FL 32250-2734');
	      }
	    }
	  );
	
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	

	}
}
