﻿function cTextFocus(text, box)
{				
	if( box.value == text )
	{									
		box.value = '';
	}
}

function cTextBlur(text, box)
{
	if( box.value == '' )
	{
		box.value = text;
	}
}

function changeFontSize( action )
{    
	var size = '';
	
	if( action == 'shrink' )
	{
		var cookie = readCookie( 'fontSizeSI' );
		
		if( cookie == 'large' )
			size = 'normal';
		else if( cookie == 'largest' )
			size = 'large';
	}
	else if( action == 'enlarge' )
	{
		var cookie = readCookie( 'fontSizeSI' );		
		if( cookie == null || cookie == 'normal' )
			size = 'large';
		else if( cookie == 'large' )
			size = 'largest';
	}

    if( size == 'normal' )
    {
        document.body.style.fontSize = '62.5%';
        eraseCookie( 'fontSizeSI' );
        createCookie( 'fontSizeSI', 'normal', 1 );
    }
    else if( size == 'large' )
    {
        document.body.style.fontSize = '80%';
        eraseCookie( 'fontSizeSI' );
        createCookie( 'fontSizeSI', 'large', 1 );
    }
    else if( size == 'largest' )
    {
        document.body.style.fontSize = '100%';
        eraseCookie( 'fontSizeSI' );
        createCookie( 'fontSizeSI', 'largest', 1 );
    }
}

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);
}







/* grab Elements from the DOM by className */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* toggle an element's display */
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

/* quick getElement reference */
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

/* check/uncheck all checkboxes */
function checkAll(ref) {
  var chkAll = document.getElementById('checkAll');
  var checks = document.getElementsByName('del[]');
  var removeButton = document.getElementById('removeChecked');
  var boxLength = checks.length;
  var allChecked = false;
  var totalChecked = 0;
  if ( ref == 1 ) {
    if ( chkAll.checked == true ) {
      for ( i=0; i < boxLength; i++ ) {
        checks[i].checked = true;
      }
    }
    else {
      for ( i=0; i < boxLength; i++ ) {
        checks[i].checked = false;
      }
    }
  }
  else {
    for ( i=0; i < boxLength; i++ ) {
      if ( checks[i].checked == true ) {
        allChecked = true;
        continue;
      }
      else {
        allChecked = false;
        break;
      }
    }
    if ( allChecked == true ) {
      chkAll.checked = true;
    }
    else {
      chkAll.checked = false;
    }
  }
  for ( j=0; j < boxLength; j++ ) {
    if ( checks[j].checked == true ) {
      totalChecked++;
	}
  }
  removeButton.value = "Remove ["+totalChecked+"] Selected";
}


/* popup in new window of img size */
function PopupPic(sPicURL, height, width ) { 
	window.open("Popup/imagePopup.html?"+sPicURL, "", "resizable=1,HEIGHT="+ height +",WIDTH=" + width );
}

//-------------------------------------------------------------------------------------------------------------------------------------

//Post link to facebook
function fbs_click() {
	u = location.href;
	t = document.title;
	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
	return false;
}



function GoPrevPlace(e) {
    e.preventDefault();
    var current = $(".location .place .acc:visible");
    if (current.attr("status") != "first") {
        var previous = current.prev();
        //current.hide();
        $(".location .place .acc").hide();
        previous.show();
        
        current = current.prev();
    }
    CheckForEnds(current);
}

function GoNextPlace(e) {
    e.preventDefault();
    var current = $(".location .place .acc:visible");
    if (current.attr("status") != "last") {
        var next = current.next();
        //current.hide();
        $(".location .place .acc").hide();
        next.show();

        current = current.next();
    }
    CheckForEnds(current);
}

function CheckForEnds(current) {
    if (current.attr("status") == "last")
        $(".location .place .controls .next").css("visibility","hidden");
    else
        $(".location .place .controls .next").css("visibility", "");

    if (current.attr("status") == "first")
        $(".location .place .controls .prev").css("visibility", "hidden");
    else
        $(".location .place .controls .prev").css("visibility", "");
}
