//
//
// 8layer Technologies Inc.
// name:    Allan de Guzman
// email:   lance_genz at yahoo dot com
// ability: mataas tumalon... =)
//
// Grab, modify and share.
// Isabuhay ang Opensource
// Use Firefox: www.mozilla.com/firefox =)
// Use KahelOS: http://www.kahelos.org/

// Update Content if theme is selected
// START

var $$ = jQuery.noConflict();
function UpdateGalleryContent(targeturl, targetmode) {
  var url = targeturl;
  var mode = targetmode;

  $$(document).ready(function() {
    if (mode) {
      $$('#home-gallery-tab-desktop').removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-inactive');
      $$('#home-gallery-tab-events').removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-inactive');
      $$('#home-gallery-tab-light').removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-inactive');
      $$('#home-gallery-tab-server').removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-inactive');
      $$('#home-gallery-tab-comics').removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-inactive');
      $$("#home-gallery-tab-"+mode).removeClass('home-gallery-tab-active home-gallery-tab-inactive').addClass('home-gallery-tab-active');
    }
    $$('#home-gallery-container').load(url,'');
    return false;
  });
}

function UpdateGalleryEventContent(targeturl) {
  var url = targeturl;

  $$(document).ready(function() {
    $$('#home-gallery-container').load(url,'');
    return false;
  });
}

function loadGallery () {
  UpdateGalleryContent('home-gallery.inc.php');
}

function scrollContent () {
  jQuery.fn.extend({
    scrollTo : function(speed, easing) {
      return this.each(function() {
        var targetOffset = $$(this).offset().top;
        $$('html,body').animate({scrollTop: targetOffset}, speed, easing);
      });
    }
  });
  $$('#scrollto').scrollTo(2000);
}

function UpdateFileView(targeturl, targetRec, targetFile, targetAction, targetPages) {
	var url = targeturl;
	var id = targetRec;
	var file = targetFile;
	var targetaction = targetAction;
	var targetpages = targetPages;

	var dataString = 'id='+ id + '&rotate=' + targetaction + '&file=' + file + '&pages=' + targetpages;
	$$.ajax({
		type: "POST",
		url: "?mod=rotate",
		data: dataString,
		success: function(msg){
			$$("#fileview-img").html(msg);
		}
	});
/*
	$$(document).ready(function() {
		$$('#contentWrap').load(url,'');
		return false;
	});*/
}

function checkActivities() {
	setTimeout("location.replace('session-expired.php');", 900000);
}

function UpdateRecord(targetRec, targetMod, targetElement) {
	var id = targetRec;
	var module = targetMod;
	var targetElement = targetElement;

	var dataString = 'id='+ id + '&module=' + module;

	$$.ajax({
		type: "POST",
		url: "?mod=dp",
		data: dataString,
		success: function(msg){
			$$('#generate-result').html("<div id='message'></div>");
			$$('#message').html("Generating...")
			.fadeOut(1500, function() {
				$$("#"+targetElement).html(msg);
			});
			$$("#"+targetElement).fadeOut(1500);
		}
	});
}

function generatePassword() {
	var genpasswd = getPassword(10, '{}*[]', 1, 1, 1, 0, 1, 1, 1, 0);
	var dataString = 'genpasswd='+ genpasswd;
	$$.ajax({
		type: "POST",
		url: "?mod=gp",
		data: dataString,
		success: function(msg){
			$$('#generate-result').html("<div id='message'></div>");
			$$('#message').html("Generating...")
			.fadeIn(1500, function() {
				$$("#generate-result").html(msg);
			});
		}
	});
}

function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "~!@#$%^&*()-_=+[{]}|<.>/? ";
	var charSet = extra;
	
		if (number == true)
			charSet += numberChars;
		if (lower == true)
			charSet += lowerChars;
		if (upper == true)
			charSet += upperChars;
		if (other == true)
			charSet += otherChars;
		return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
		if (length > 0)
			rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
			for (var idx = 1; idx < length; ++idx) {
				rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
			}

			// start check if there is a numeric value
			var addNum = false;
			var NumSymbol = new String("1234567890");
			el = trim(rc);

			// checking...
			for(i=0;i<el.length;i++) {
				// checking...
				if (NumSymbol.indexOf(el.charAt(i))!=-1) {
					// found 1 numeric value :)
					addNum = true;
				}
			}

			// add 8 if there is no numeric val found
			if (addNum==false) {
				rc += "8";
			}

			// end of checking if there is a numeric value

		return rc;
}

	function HideSearch() {
		$$(document).ready(function() {
			// enable tooltip for "download" element. use the "slide" effect
			$$("#searchbox").slideUp('slow', function() {
				document.getElementById('search-fold').style.display="none";
				document.getElementById('search-unfold').style.display="";
			});
		});
	}
	function ShowSearch() {
		$$(document).ready(function() {
			// enable tooltip for "download" element. use the "slide" effect
			$$("#searchbox").slideDown('slow', function() {
				document.getElementById('search-fold').style.display="";
				document.getElementById('search-unfold').style.display="none";
			});
		});
	}

	function checkAll(fields) {
		document.getElementById('span_check').style.display = 'none';
		document.getElementById('span_uncheck').style.display = 'block';
		document.frm.checkall.checked = false;
		document.frm.uncheckall.checked = true;
		for (i = 0; i < fields.length; i++)
			fields[i].checked = true;
	}

	function uncheckAll(fields) {
		document.getElementById('span_check').style.display = 'block';
		document.getElementById('span_uncheck').style.display = 'none';
		document.frm.checkall.checked = false;
		document.frm.uncheckall.checked = true;
		for (i = 0; i < fields.length; i++)
			fields[i].checked = false;
	}


