var rei = {};
function selectAll(){
  form1 = $('form1').get(0);
  cball = $('cball').get(0);
  for(var i=0;i<form1.elements.length;i++){
    var e = form1.elements[i];
    if (e.type=='checkbox' && e.id!='cball'){
    	e.disabled = cball.checked;
    }
  }
}

function ValidateForm(f) {
	if(f['CustomFields[1]'].value=="") {
	   	alert("Please Enter First name");
	   	f['CustomFields[1]'].focus();
	   	return false;
    }
	
	if(f.email.value==""){
		alert("Please Enter Email");
	   	f.email.focus();
   		return false;
	}
	else {
		var eid=f.email.value; 
		if (emailIsValid(eid)==false) {
			alert("Invalid Email")
			f.email.focus();
	  		return false;
		}
		else {
			return true;
		}
	}
 }

function emailIsValid(value){
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
   return emailPattern.test(value); 
}

var userAgent = navigator.userAgent.toLowerCase();
var browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )	
}

rei.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
} 


function showDialog(){
 gradeit();
 
 ShowModalWindow($("#grademe").get(0),'div','dialog','Title','&nbsp;','width','450');
 
 //$("#dialog").removeClass('nodisplay');
 //$("#dialog").dialog({ 
 //   modal: true, 
 //   width: 560,
 //   height: 370,
 //   overlay: { 
 //       opacity: 0.5, 
 //       background: "black" 
 //   } 
 // });
}

/**
 * faster way to load content in browser idea taken fron JQuery
 * it allows do not wait until data will be completely loaded
 * seems only opera can't load faster using this function - 
 * though in JQuery they say it can...
 */
function bindReady(){
	if ( bindReady.readyBound ) return;
	bindReady.readyBound = true;
	
	if (document.addEventListener){
	  document.addEventListener( "DOMContentLoaded", bindReady.ready, false ); 
	}
	// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
	// If IE is used and is not in a frame
	// Continually check to see if the document is ready
	if ( browser.msie && window == top ) (function(){
		if (bindReady.isReady) return;
		try {
			// If IE is used, use the trick by Diego Perini
			// http://javascript.nwbox.com/IEContentLoaded/
			document.documentElement.doScroll("left");
		} catch( error ) {
			setTimeout( arguments.callee, 0 );
			return;
		}
		// and execute any waiting functions
		bindReady.ready();
	})();
	if ( browser.safari || browser.opera ) {
		var numStyles;
		(function(){
			if (bindReady.isReady) return;
			if ( document.readyState != "loaded" && document.readyState != "complete" ) {
				setTimeout( arguments.callee, 0 );
				return;
			}
			bindReady.ready();
		})();
	}
}
bindReady.readyBound = false;
bindReady.isReady = false;
bindReady.ready = function(){
	bindReady.isReady = true;
	var i;
	for (i=0;i<bindReady.queue.length;i++){
	  var f = bindReady.queue[i];
	  f();
	}
}
bindReady.queue = [];
bindReady.add = function(f){
  if (bindReady.isReady) {
    f();
  }
  else {
  	bindReady.queue.push(f);
  }
}
bindReady();
