// JavaScript Document

//var base_url = 'http://localhost/sites/princebandroom/';
var base_url = 'http://www.princebandroom.com.au/';


var temp=2;// variable to have the control of the auto assign cards to the flags(checkBox)


	function display_loader( output, msg ){
		/*
		var el = $(output);
		el.style.width = 100;
		el.style.height = 100;
		el.innerHTML ="<img src='"+loader_img+"'/><div class='output_msg'>"+msg+"</div>";
		*/
	}

	function cNum(e) {                        
	
		if(e){ // if the event object is present (NN only)
			e = e // var e = event
		} else {
			e = window.event // else e = winddow.event for IE
		}
	
		if(e.which){ // if there is syntax support for the property 'which' (NN only)
			var keycode = e.which // e.which is stored in variable "keycode"
		} else {
			var keycode = e.keyCode // otherwise for IE, var keycode stores e.keyCode syntax
		}
		
		// keycodes
		// backspace : 8
		// tab : 9
		// del : 46
		// left arrow : 37
		// right arrow : 39
		if((keycode!=8 )&&(keycode!=9)&&(keycode!=46)&&(keycode!=39)&&(keycode!=37)){ 
		 	var strCheck = '0123456789';
			var whichCode = (window.Event) ? e.which : e.keyCode; //e.which  = ff, e.keyCode = IE
			key = String.fromCharCode(whichCode);  // Get key value from key code
			if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
		}
				
	}// put this in the input box: onkeypress="return(cNum(event));"


	function confirmDelete(id, name, field){
		if(confirm("Are you sure you want to delete "+name+" ?")){
			document.getElementById(field).value=id;
			document.deleteForm.submit();
		}
	}


	function alertObj(obj){
		var x = obj;
		 t = "";
	
		 c = 0;
		for (a in x) {
			c = c+1;
			t += (a + ":" + x[a] + "  ,  ");
			if (c >= 5) {
				c = 0;
				alert(t);
				t = "";
			}
		}
		alert(t);
	}


	function updateField(fieldName, fieldValue){
		document.getElementById(fieldName).value = fieldValue;
	}
	
	
	function resetIt(theForm){

		for(i=0; i < theForm.length; i++){
					
			if(theForm[i].type != "hidden" && theForm[i].type != "button"){
				theForm[i].value="";
			}
		}
	}
	
	
	function countit( field ){
		var formcontent=document.getElementById(field).value;
		formcontent=formcontent.split(" ");
		
		return formcontent.length;
	}
	

	function addEvent( obj, type, fn ) {

		if (obj.addEventListener) {
			obj.addEventListener( type, fn, false );
			//EventCache.add(obj, type, fn);
		}
		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] );
			//EventCache.add(obj, type, fn);
		}
		else {
			obj["on"+type] = obj["e"+type+fn];
		}
	}

	
/**
 *	Decode a JSON response
 */	

function json_decode( response ){
	
	return eval( '(' + response + ')' );
	
}
	
	
/*****************************************************************************
*
*		DOM FUNCTIONS
*	
******************************************************************************/

/**
 *  removes all child nodes from the supplied element
 */
function removeChildNodes(ctrl)
{
  while (ctrl.childNodes[0])
  {
    ctrl.removeChild(ctrl.childNodes[0]);
  }
}





/*
* Written by Jonathan Snook, http://www.snook.ca/jonathan
*/
function getElementsByClassName(node, classname, tag)
{
    var a = [];
    var t = (tag == null) ? '*' : tag;
    var re = new RegExp("(^|\\s)" + classname + "(\\s|$)");
    var els = node.getElementsByTagName(t);
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

/*
* Cross-browser event handling, by Scott Andrew
*/
function addEvent(element, eventType, lamdaFunction, useCapture) {
	if (element.addEventListener) {
		element.addEventListener(eventType, lamdaFunction, useCapture);
		return true;
	} else if (element.attachEvent) {
		var r = element.attachEvent('on' + eventType, lamdaFunction);
		return r;
	} else {
		return false;
	}
}

/*
* Cross-browser style extraction, from the JavaScript & DHTML Cookbook
* <http://www.oreillynet.com/pub/a/javascript/excerpt/JSDHTMLCkbk_chap5/index5.html>
*/
function getElementStyle(elementID, CssStyleProperty) {
	var element = document.getElementById(elementID);
	if (element.currentStyle) {
		return element.currentStyle[toCamelCase(CssStyleProperty)];
	} else if (window.getComputedStyle) {
		var compStyle = window.getComputedStyle(element, '');
		return compStyle.getPropertyValue(CssStyleProperty);
	} else {
		return '';
	}
}

/*
* CamelCases CSS property names. Useful in conjunction with 'getElementStyle()'
* From <http://dhtmlkitchen.com/learn/js/setstyle/index4.jsp>
*/
function toCamelCase(CssProperty) {
	var stringArray = CssProperty.toLowerCase().split('-');
	if (stringArray.length == 1) {
		return stringArray[0];
	}
	var ret = (CssProperty.indexOf("-") == 0)
	? stringArray[0].charAt(0).toUpperCase() + stringArray[0].substring(1)
	: stringArray[0];
	for (var i = 1; i < stringArray.length; i++) {
		var s = stringArray[i];
		ret += s.charAt(0).toUpperCase() + s.substring(1);
	}
	return ret;
}
