var myimages = new Array();
var imgupload_hash='';
var imgupload_chid=0;
var viewportwidth = 0;
var viewportheight = 0;
var emailOK = 0;
var usernameOK = 0;
var ccodeOK = 0;
function preloading(){
	for (x=0; x<preloading.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = preloading.arguments[x];
	}
}

  
function rollover(obj,img){
	obj.src = 'templates/images/'+img;
}
function randomChar(str) 
// Given  : str is a nonempty string 
// Returns: a random character from the string 
{  
    return str.charAt(randomInt(0, str.length-1)); 
}
function randomInt(low, high) 
// Given   : low <= high 
// Returns : a random integer in the range [low, high] 
{ 
    return Math.floor(Math.random()*(high-low+1)) + low; 
}  


function generateRandSeq(len)
  // Assumes: len >= 0
  // Returns: random sequence of letters, length len
  {
	  var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      var i, seq = "";
      for (i = 1; i <= len; i = i + 1) {
          seq += randomChar(letters);
      }
      return seq;
  }

function startscoretrivia()
{
	$.ajax({
			 type: "GET",
			 url: 'scoretrivia.php',
			 beforeSend: function(){
				 document.getElementById('scoretrivia').innerHTML = '<img src="../images/ajax-loader.gif" alt="score trivia"/>';
			 },
			 success: function(msg){
				 //alert( "Status: " + msg );
				 //window.location.href='categories.php';
				 document.getElementById('scoretrivia').innerHTML = msg;
			 }
	});

}
	
function newCaptcha(){
	var chars = generateRandSeq(5); 
	/*ajx.url = 'captcha.php?r='+chars;
	ajx.handleResp = function(){
		if(ajx.req.readyState == 4 && ajx.req.status == 200){
			if(document.getElementById('validation') != null)
				document.getElementById('validation').innerHTML = ajx.req.responseText;
		}else{
			
		}
	}
	ajx.doReq();*/
	$.ajax({
			 type: "GET",
			 url: 'captcha.php?r='+chars,
			 success: function(msg){
				 //alert( "Status: " + msg );
				 //window.location.href='categories.php';
				 document.getElementById('validation').innerHTML = msg;
			 }
	});
}

function getViewPortDim(){
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth;
	  viewportheight = window.innerHeight;
	}
	
	
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth;
	   viewportheight = document.documentElement.clientHeight;
	}
	
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	//alert(viewportwidth + ' ' + viewportheight);
}




function initSlider(){

featuredcontentslider.init({

	id: "slider1",  //id of main slider DIV

	contentsource: ["inline", ""],  //Valid values: ["inline", ""] or ["ajax", "path_to_file"]

	toc: "#increment",  //Valid values: "#increment", "markup", ["label1", "label2", etc]

	nextprev: ["", ""],  //labels for "prev" and "next" links. Set to "" to hide.

	revealtype: "click", //Behavior of pagination links to reveal the slides: "click" or "mouseover"

	enablefade: [true, 0.2],  //[true/false, fadedegree]

	autorotate: [true, 12000],  //[true/false, pausetime]

	onChange: function(previndex, curindex){  //event handler fired whenever script changes slide

		//previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)

		//curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)

	}

})
}

	function isValidEmailAddress(emailAddress) {
		pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
		
	}
	
	function isEmailAddressExist(email){
		var ajx = new Ajax();
		ajx.url = 'helper.php?checkemail='+email;
		ajx.handleResp = function(){
			if(ajx.req.readyState == 4 && ajx.req.status == 200){
				if(ajx.req.responseText == 'Yes'){
					emailOK = 0;
					$("label#_error1b").show();
				}else{
					emailOK = 1;
					$("label#_error1b").hide();
				}
				$("img#emailx").hide();
			}else{
				$("img#emailx").show();
			}
		}
		ajx.doReq();
	
	}
	
	function isUsernameExist(username){
		var ajx = new Ajax();
		ajx.url = 'helper.php?checkuser='+username;
		ajx.handleResp = function(){
			if(ajx.req.readyState == 4 && ajx.req.status == 200){
				if(ajx.req.responseText == 'Yes'){
					usernameOK = 0;
					$("label#_error2a").show();
				}else{
					usernameOK = 1;
					$("label#_error2a").hide();
				}
				$("img#userx").hide();
			}else{
				$("img#userx").show();
			}
		}
		ajx.doReq();
	
	}
	function checkCCode(code){
		if(code.length < 5) return;
		var ajx = new Ajax();
		ajx.url = 'helper.php?checkccode='+code;
		ajx.handleResp = function(){
			if(ajx.req.readyState == 4 && ajx.req.status == 200){
				if(ajx.req.responseText == 'Yes'){
					ccodeOK = 1;
					$("label#_error5a").show();
				}else{
					ccodeOK = 0;
					$("label#_error5a").hide();
				}
				$("img#codex").hide();
			}else{
				$("img#codex").show();
			}
		}
		ajx.doReq();
	
	}

	function breadcrumbs(){
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
  var output = "<a href=\"/\">Home</a>  >  ";
  sURL = location.href;
  sURL = sURL.slice(8,sURL.length);
  chunkStart = sURL.indexOf("/");
  sURL = sURL.slice(chunkStart+1,sURL.length)
  while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
      bits[x] = sURL.slice(0,chunkStart)
      sURL = sURL.slice(chunkStart+1,sURL.length);
    }else{
      stop = 1;
    }
    x++;
  }
  for(var i in bits){
    output += "<a href=\"";
    for(y=1;y<x-i;y++){
      output += "../";
    }
    output += bits[i] + "/\">" + bits[i] + "</a>  >  ";
  }
  document.write(output + document.title);
}

function toggleLink(id)
{
	if(document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = '';
	else
		document.getElementById(id).style.display = 'none';
}
