// JavaScript Document

//ERROR HANDLING
//onerror=handleErr;
var txt="";
var obj_slideShow = null;

function supportsPNG24(){
	// Assume the user is not using an old browser
	var return_bool = true;
	var agent = navigator.userAgent.toLowerCase();
	var ieoffset = agent.indexOf("msie ");
		 
	if((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1))
		if (parseFloat(agent.substring(ieoffset + 5, agent.indexOf(";", ieoffset))) < 7) return_bool = false;
	
	return return_bool;
}
	  
function handleErr(msg,url,l){
	txt="There was an error on this page.\n\n";
	txt+="Error: " + msg + "\n";
	txt+="URL: " + url + "\n";
	txt+="Line: " + l + "\n\n";
	txt+="Click OK to continue.\n\n";
	alert(txt);
	return true;
}


function openEmailLink(){
	var email= decodeBase64(openEmailLink.arguments[0]);
	location.href='mailto:'+email+'&subject='+openEmailLink.arguments[1];
}


//Clear field
function doClear(theText) {
  if (theText.value == theText.defaultValue) {
    theText.value = ""
  }
}
 
function clearField(field){
  document.main.getElementById(field).value="";	
}

//Submit form
function submitForm(){
 if(document.main.onsubmit()){
	document.main.submit();
 }
}

//Popup
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Popup
function MM_openBrWindowReturnLink(theURL,winName,features) { //v2.1
  return window.open(theURL,winName,features);
}

//Show Hide Header Fields
function showLayer(layer){
  if(document.getElementById(layer).style.visibility!='visible'){
    document.getElementById(layer).style.visibility='visible';
  } else{
    document.getElementById(layer).style.visibility='hidden';
  }
}

//Scroll Functions
var nn = 1;

function stopAll(){
  clearTimeout(timeOutId);
}

function move_up() {
  //nn = 1;
  if(nn==1){
    scroll_clipper.scrollTop = scroll_clipper.scrollTop-20;
	timeOutId = setTimeout("move_up()",50);
  }
}
  
function move_down() {
  //nn = 1;
  if(nn==1){
    scroll_clipper.scrollTop = scroll_clipper.scrollTop+20;
	timeOutId = setTimeout("move_down()",50);
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  
  //alert(selObj.value);
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuDetail(targ,selObj,restore){ //v3.0 

  var qty = document.getElementById('qty').value;
  
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"?q="+qty+"'");
  if (restore) selObj.selectedIndex=0;
}

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];}
}


function checkNum(txt,event){
	var key = Number(event.keyCode);
	if ((key>=48 && key<=57) || (key>=96 && key<=105)){
		//alert(key + "\n\ntrue");
		return true;
	} else {
		//txt.value = txt.value.substring(0,txt.value.length-1);
		reg = /[^0-9]/g;
		txt.value =  txt.value.replace(reg,"");
		//alert(key + "\n\nfalse");
		//return false;
	}
}

// ***** STRING FUNCTIONS *****
function Trim(str){
	str = LTrim(str);
	return RTrim(str);
}

function RTrim(str){
	while(str.charAt((str.length-1))==" "){
		str = str.substring(0,str.length-1);
	}
	return str;
}


function LTrim(str){
	while(str.charAt(0)==" "){
		str = str.replace(str.charAt(0),"");
	}
	return str;
}

function centerDiv(div,w,h){
  if((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >=4)){ 
    windowwidth = window.innerWidth;
    windowheight = window.innerHeight;
  } else if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >=4)){ 
    windowwidth = document.body.clientWidth;
    windowheight = document.body.clientHeight;
  } else { 
    windowwidth = screen.width;
    windowheight = screen.width-100;
  }

  xScreen = (windowwidth-Number(w))/2;
  yScreen = (windowheight-Number(h))/2;

  xFinal = xScreen;
  yFinal = yScreen-15;
  
  if (window.innerHeight){
	pos = window.pageYOffset
  } else if (document.documentElement && document.documentElement.scrollTop){
    pos = document.documentElement.scrollTop
  }	else if (document.body){
    pos = document.body.scrollTop
  }
  
  div.style.left=String(xFinal)+'px';
  div.style.top=String(yFinal+pos)+'px';
  div.style.visibility='visible';
}


function validateEmailAddress(email){

	var at="@"
	var dot="."
	var lat=email.indexOf(at)
	var lemail=email.length
	var ldot=email.indexOf(dot)
	var domainType = email.substring(ldot);
	
	if (domainType.length<3){
		return false;
	}
	
	if (email.indexOf(at)==-1){
	   return false
	}

	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lemail){
	   return false
	}

	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lemail){
	    return false
	}

	 if (email.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
	    return false
	 }

	if (email.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (email.indexOf(" ")!=-1){
		 return false
	 }
	 return true;
}

//ENCODING & DECODING
function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

var END_OF_INPUT = -1;

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}
function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
    return END_OF_INPUT;
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}

var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function toHex(n){
    var result = ''
    var start = true;
    for (var i=32; i>0;){
        i-=4;
        var digit = (n>>i) & 0xf;
        if (!start || digit != 0){
            start = false;
            result += digitArray[digit];
        }
    }
    return (result==''?'0':result);
}

function pad(str, len, pad){
    var result = str;
    for (var i=str.length; i<len; i++){
        result = pad + result;
    }
    return result;
}

function encodeHex(str){
    var result = "";
    for (var i=0; i<str.length; i++){
        result += pad(toHex(str.charCodeAt(i)&0xff),2,'0');
    }
    return result;
}

function decodeHex(str){
    str = str.replace(new RegExp("s/[^0-9a-zA-Z]//g"));
    var result = "";
    var nextchar = "";
    for (var i=0; i<str.length; i++){
        nextchar += str.charAt(i);
        if (nextchar.length == 2){
            result += ntos(eval('0x'+nextchar));
            nextchar = "";
        }
    }
    return result;
}



//************************************************
//***************** SECURITY *********************
//************************************************

function right(e){
return true;
}

function trapclick(){

}



function textsizer(e){
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
var actualkey=String.fromCharCode(unicode)
if (actualkey=="a")
document.body.style.fontSize="120%"
if (actualkey=="z")
document.body.style.fontSize="100%"
}
//document.onkeypress=textsizer


function displayunicode(e){
	var unicode=e.keyCode? e.keyCode : e.charCode
	if (unicode==44){
		//alert('Showing Special');
		showSpecial();
	}
}

function showSpecial(){
	//alert('Specializing...');
	div = document.getElementById('divSpecial');
	div.innerHTML = flashPSHTML;
	setTimeout('clearSpecial()',2500);
}

function clearSpecial(){
	//alert('Clearing...');
	div = document.getElementById('divSpecial');
	div.innerHTML = '';
}

function displayFadeDive(){
	document.getElementById("fadeDiv").style.height = (document.body.scrollHeight - 20) + "px";
	document.getElementById("fadeDiv").style.width = (document.body.scrollWidth - 20) + "px";
	document.getElementById("fadeDiv").style.visibility = "visible";
}
	
function hideFadeDiv(){
	document.getElementById("fadeDiv").style.visibility = "hidden";
}



/*******************************************************************************************************************************/

	function showLargeImage(img_obj, image_src, width, height, caption){
		var threshold = 0;
		var threshold_left = 0;
		var obj_object = document.getElementById(img_obj);
		var caption_height = caption ? (Math.ceil((caption.length * 6) / width) * 18) + 5:0;
		var client_height = (document.body.clientHeight/2) + document.body.scrollTop;
		var client_width = document.body.clientWidth/2;
		
		closeDivs(false);
		displayFadeDive();
		
		document.getElementById("largeGalleryImage").src = "../img/spacer.gif";
		
		document.getElementById("showImage").style.top = (client_height - (height/2)) + "px";
		document.getElementById("showImage").style.left = (client_width  - (width/2)) + "px";
		
		document.getElementById("largeGalleryImageSpan").style.top = (caption_height + 20) + "px";
		
		document.getElementById('largeGalleryDescription').style.width = width + "px";
		
		document.getElementById("largeGalleryImage").src = image_src;
		document.getElementById("largeGalleryImage").width = width;
		document.getElementById("largeGalleryImage").height = height;
		document.getElementById('largeGalleryDescription').innerHTML = caption;
		
		caption ? height += caption_height: height += 5;
		width += 40;
		document.getElementById("showImage").style.width = width + "px";
		document.getElementById("showImage").style.height = (height + 35) + "px";
		
		document.getElementById("largeGalleryClose").style.left = (width - 15) + "px";
		
		document.getElementById("showImage").style.visibility = "visible";
		
	}// end function
	/*************************************************************************/

	var loading_image = "/img/black.png";
	var current_video = null;
	var video_height = 0;
	var video_width = 0;
	
	function showVideoIe(){
			document.quicktimevideo.width = video_width;
			document.quicktimevideo.height = (video_height + 15);
			document.quicktimevideo.SetURL(current_video);	
	}
	
	
	function showVideo(video, width, height){
		
		current_video = video;
		video_height = height;
		video_width = width;

		var threshold = 0;
		var threshold_left = 0;
		var obj_movie = document.quicktimevideo;
		var obj_object_left = document.getElementById('ronnieBanner');
		var client_height = (document.body.clientHeight/2) + document.body.scrollTop;
		var client_width = document.body.clientWidth/2;
		var agent = navigator.userAgent.toLowerCase();
		
		var browser_is_ie = false
		
		if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1))
			browser_is_ie = true;
		
		closeDivs(false);
		displayFadeDive();
		
		document.getElementById("showVideo").style.top = client_height - (video_height/2) + "px";
		document.getElementById("showVideo").style.left = client_width  - (video_width/2) + "px";
		
		width += 40;
		document.getElementById("showVideo").style.width = width + "px";
		document.getElementById("showVideo").style.height = (height + 50) + "px";
		
		document.getElementById("videoClose").style.left = (width - 15) + "px";
		
		document.getElementById("showVideo").style.visibility = "visible";
		
		if(browser_is_ie){
			// This id for IE
			setTimeout(showVideoIe, 100);

		} else {
			if(document.getElementById('quicktimevideo'))
				document.getElementById('videoContent').removeChild(document.getElementById('quicktimevideo'));

			document.getElementById("videoContent").innerHTML = '';
			document.getElementById("videoContent").innerHTML = QT_GenerateOBJECTText(video , width, height + 15, "", "name", "quicktimevideo");// + 20
			document.getElementById("videoContent").style.left = "0px";
		}
		
		
		
		
	}// end function
	/*************************************************************************/

function closeDivs(show_flash_form_elements){
	
	if(document.getElementById("flashcontent"))
		document.getElementById("flashcontent").style.visibility = show_flash_form_elements ? "visible" : "hidden";
	
	if(document.getElementById("vision_media"))
		document.getElementById("vision_media").style.visibility =show_flash_form_elements ? "visible" : "hidden";
		


	
	document.getElementById('showImage').style.visibility = "hidden";
	document.getElementById("showVideo").style.visibility = "hidden";
	document.getElementById("fadeDiv").style.visibility = "hidden";
	
	document.getElementById("showVideo").style.top = "0px";
	document.getElementById("showVideo").style.left = "0px";
	
	document.getElementById("showImage").style.top = "0px";
	document.getElementById("showImage").style.left = "0px";
	
}

/*******************************************************************************************************************************/

function closeVideoDivs(){
	
	var loading_image = "/img/black.png";
	var agent = navigator.userAgent.toLowerCase();
	
	var browser_is_ie = false
	
	if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1))
		browser_is_ie = true;
	
	if(browser_is_ie && document.getElementById("showVideo").style.visibility){
		// This id for IE
		document.quicktimevideo.width = 320;
		document.quicktimevideo.height = 240;
		document.quicktimevideo.SetURL(loading_image);
	} else {
		if(document.getElementById('quicktimevideo'))
			document.getElementById('videoContent').removeChild(document.getElementById('quicktimevideo'));
		
		document.getElementById("videoContent").innerHTML = '';
		document.getElementById("videoContent").innerHTML = QT_GenerateOBJECTText(loading_image , 320, 240 + 15, "", "name", "quicktimevideo");// + 20
	}
	
	closeDivs(true);
}

	/**************************************************************************
	* "scrollDiv()" allows the Blog's listed by date menu to scroll with
	* the users view.  When we start using a doctype in the html_header.php
	* file this can be modified to allow for smooth scrolling in both browsers.
	* Right now is scrolls smoothly in Mozilla, and it is jumpy in IE.
	**************************************************************************/
	function scrollDiv(){
			var positionY = 0;
			var threshold = 0;
			if(!obj_object)
				var obj_object = document.getElementById("navigationCell");
		
			if (obj_object.offsetParent) {
				threshold = obj_object.offsetTop
				
				while (obj_object = obj_object.offsetParent) {
					threshold += obj_object.offsetTop
				}// end while
			}// end if
		


			if( typeof( window.pageYOffset ) == 'number' ) { 
			//Netscape compliant
			positionY = window.pageYOffset;
			} else if( document.body && document.body.scrollTop ) {
			//DOM compliant
			positionY = document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop ) { 
			//IE6 standards compliant mode
			positionY = document.documentElement.scrollTop;
			}
			

			if(document.addEventListener){

					if(positionY > threshold){
							document.getElementById("scrollingNav").style.position = "fixed";
							document.getElementById("scrollingNav").style.top = "15px";
					} else {
							document.getElementById("scrollingNav").style.position = "relative";
							document.getElementById("scrollingNav").style.top = "0px";
					}

			} else {
					if(positionY > threshold){
							document.getElementById("scrollingNav").style.top = positionY - threshold + "px";
					} else {
							document.getElementById("scrollingNav").style.top = "0px";
					}
			}// end if
			
	}

	/*************************************************************************/
	
	function activateScrolling(){
		/**************************************************************************
		* This sets the scroll bar to run "scrollDiv()" everytime the page 
		* is scrolled.
		**************************************************************************/
		if(document.addEventListener){
			document.addEventListener("scroll",function(){scrollDiv()}, false);
		} else {
			window.attachEvent("onscroll", function(){scrollDiv()});
		}
		/*************************************************************************/
	}
	
	

function adjustShowImage(){
	var width = 570;
	var height = 380;
	var client_height = (document.body.clientHeight/2) + document.body.scrollTop;
	var client_width = document.body.clientWidth/2;
	
	document.getElementById("showImage").style.top = (client_height - (height/2)) + "px";
	document.getElementById("showImage").style.left = (client_width  - (width/2)) + "px";
	
	document.getElementById("largeGalleryImageSpan").style.top = "20px";
	
	height += 5;
	width += 40;
	
	document.getElementById("showImage").style.width = (width +20) + "px";
	document.getElementById("showImage").style.height = (height +45) + "px";
	
	document.getElementById("largeGalleryClose").style.left = (width + 5) + "px";
	
	document.getElementById("largeGalleryNavigation").style.width = width + "px";
	
	document.getElementById("largeGalleryImage").width = width -40;
	document.getElementById("largeGalleryImage").height = height -5;
	
	
}


function showSlideShow(array_image_files,array_captions,int_frameNumber,string_show_name, string_gallery_location){
	closeDivs(false);
	displayFadeDive();
	adjustShowImage()

	if(obj_slideShow === null || obj_slideShow.getShowName() !== string_show_name){
		obj_slideShow = null;
		obj_slideShow = new SlideShow("showImage", "largeGalleryClose", "largeGalleryImageSpan", "largeGalleryImage", "largeGalleryDescription", .25, string_gallery_location, array_image_files, "/img/makeImageWithTrans.php?text=The%20Image%20Is%20Not%20Available.", array_captions,int_frameNumber,string_show_name);
		obj_slideShow.getCurrentFrame(int_frameNumber);
		document.getElementById("showImage").style.visibility = "visible";
		obj_slideShow.start();
	} else {
		obj_slideShow.getCurrentFrame(int_frameNumber);
		document.getElementById("showImage").style.visibility = "visible";
		obj_slideShow.start();
	}

}

function closeSlideShow(){
	stopSlideShow();
	closeDivs(true);
	document.getElementById("largeGalleryDescription").innerHTML = "";
	document.getElementById("largeGalleryImage").src = "/vision/gallery/large/loading.png";

}

function stopSlideShow(){
	obj_slideShow.stop();
}

function startSlideShow(){
	obj_slideShow.start();
}

function previousSlide(){
	obj_slideShow.getPreviousFrame();
}

function nextSlide(){
	obj_slideShow.getNextFrame()
}

function lastSlide(){
	obj_slideShow.getLastFrame()
}

function firstSlide(){
	obj_slideShow.getFirstFrame()
}


