/* CHECK FORM FIELDS
------------------------------------------------------- */
function valid(form) {
	var field1 = form.requiredname; 	// name field
	var field2 = form.requiredemail; 	// email field  
	var field3 = form.requiredphone; 	// name phone
	var field4 = form.requiredcompany; 	// name company

	var str1 = field1.value;
	var str2 = field2.value;
	var str3 = field3.value;
	var str4 = field4.value;

	
	if (str1 == "") {
		alert("Please enter your name");
		field1.focus();
		return false;
	}
	
	if (str3 == "") {
		alert("Please enter your Phone");
		field3.focus();
		return false;
	}
	
	if (str4 == "") {
		alert("Please enter your company name");
		field4.focus();
		return false;
	}	
	
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(str2) && reg2.test(str2)) { // if syntax is valid
		return true;
	}
	alert("Please enter a valid email");
	field2.focus();
	field2.select();
	return false;

}

/* Toggle Sidebar 
------------------------------------*/
function toggleSidebar(objDiv) {
   var mySidebar = document.getElementById(objDiv);    
   var mySidebarTxt = document.getElementById('togSidebarTxt');
   var myContent = document.getElementById('maincontent');

   if (mySidebar.style.display == "none") {
       mySidebar.style.display = "";
	   mySidebarTxt.innerHTML = "Hide Menu";
	   mySidebarTxt.title = "Hides the menu";
	   myContent.style.width = "758px"; 	/* same as -> /css/base.css -> #maincontent -> {width} */
   }
   else {
       mySidebar.style.display = "none";
	   mySidebarTxt.innerHTML = "Show Menu";
	   mySidebarTxt.title = "Displays the menu";
	   myContent.style.width = "958px";
   }
}


/* TOGGLE DISPLAY 
------------------------------------*/
function toggleDiv(objDiv){
   var myElement = document.getElementById(objDiv); 
   if (myElement.style.display == "none" || myElement.style.display == ""){
		if (navigator.appName=="Microsoft Internet Explorer") { // if IE
			try {myElement.filters[0].Apply(); } catch (ex) {}
		}
		
       myElement.style.display = "block";

		if (navigator.appName=="Microsoft Internet Explorer") { // if IE
		   try {myElement.filters[0].Play(); } catch (ex) {}
		}
   }
   else {
       myElement.style.display = "none";
   }
}



/* Check All
------------------------------------*/
function checkAll() {
	for (a=0; a<document.forms[0].elements.length; a++) {
		if (!document.forms[0].elements[a].checked) {
			document.forms[0].elements[a].checked=true;
		} 
		else {
			document.forms[0].elements[a].checked=false;
		}
	}
}


/* Tabbed Navigation
------------------------------------*/
function stepTab(name, obj) {
	var obj = obj.parentNode;
//	var lis = $('navlist').getElementsByTagName('li');	
	var lis = document.getElementById('navlist').getElementsByTagName('li');	
	
	for(var i=0; i<lis.length; i++) {
		var childName = name+(i+1);
		var child = $(childName);
					
		if(lis[i] == obj) {
			lis[i].className = "active";
			child.style.display = "";
		}
		else {
			lis[i].className = "";
			child.style.display = "none";
		}
	}
}

/* AJAX 
------------------------------------*/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function makeRequest(url, containerid) {
	var httpRequest;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	} 
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!httpRequest) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	httpRequest.onreadystatechange = function() { 
//		alertContents(httpRequest);
		loadpage(httpRequest, containerid)
	};
	httpRequest.open('GET', url, true);
	httpRequest.send('');

}

function loadpage(httpRequest, containerid){
	try {
		
		if(httpRequest.readyState < 4){
			document.getElementById("status").innerHTML = "<div id='loading' style='display:block;'>Loading...<br /><img src='/images/loading-01.gif' /></div>";
		} 
		else if(httpRequest.readyState == 4 && httpRequest.status == 200){
			document.getElementById("status").innerHTML = "<div id='loading' style='display:none;'>Loading...<br /><img src='/images/loading-01.gif' /></div>";
			document.getElementById(containerid).innerHTML = httpRequest.responseText;
		}
		else {
			alert('Problem with the request: \n' + httpRequest.statusText);
		}		
	}
	catch(e) {
		alert('Caught Exception: ' + e.description);
	}
}


/* Auto Breadcrumbs 
------------------------------------*/
function breadcrumbs(){
	sURL = new String;
	bits = new Object;
	var x = 0;
	var stop = 0;
	var output = "<a href='/' class='home'>Home</a> &raquo; ";
	
	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 += "../";
		}
	
		/* old basic output	
		output += bits[i] + "/\">" + bits[i] + "</a> &raquo; ";
		*/
		
		// lets convert the text "this-is-my-string" to "This Is My String"		
		output += bits[i] + "/\">" + bits[i].toLowerCase().replace(/\b[a-z]/g, cnvrt).split("-").join(" ") + "</a> &raquo; ";
		
	}
	function cnvrt() {
		return arguments[0].toUpperCase();
	}
	
	document.write(output + document.title);
}

/* Cookie plugin
 * http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
 ------------------------------------*/
 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);
}




/* RSS Feed Reader
------------------------------------- */
// load the AJAX Feed API
google.load("feeds", "1");

function OnLoad() {
	var feedControl = new google.feeds.FeedControl();
	
	// Enter the feed URL's to be loaded and their titles
	feedControl.addFeed("http://feeds.lexblog.com/SecuringInnovation", "Securing Innovation");
	feedControl.addFeed("http://www.priorartdatabase.com/pqm/rss/", "Prior Art Database");
	
	feedControl.setLinkTarget(google.feeds.LINK_TARGET_BLANK);
	feedControl.setNumEntries(10);
	feedControl.draw(document.getElementById("feedControl"), 
					 {drawMode : google.feeds.FeedControl.DRAW_MODE_TABBED});
}

google.setOnLoadCallback(OnLoad);
	  


/* Avoid JS flickering when DOM isn't ready by hiding elements
--------------------------------------------------------------------- */
document.write('<style type="text/css">#whatsnew, .alert{display:none}</style>');


/* Set up global vars for jQuery
------------------------------------- */
var obj = null;
function doClose() {
	$(obj).slideUp('normal'); 
}
function doOpen() {
	$(obj).slideDown('normal'); 
}



/* All onload procedures go here
------------------------------------- */
$(document).ready(function(){
						   
	// Animate Alert messages with a timed delay
	obj = $(".alert");
	setTimeout("doOpen()", 50);
	
	
	$('#sue a.close').click(function() {
		/* (this) refers to the link. Its parent() is the <div> with id named #sue  */
		obj = $(this).parent();
		$(this).html("Closing...")
		setTimeout("doClose()", 1000);
		return false;
	});
	
	
	//zebra tables
	$(".dataTable tr:even").addClass("even");
	
	// Highlight row on Hover
	$(".dataTable tr").mouseover(function() { $(this).addClass("over");}).mouseout(function() { $(this).removeClass("over"); });	

		
});// End document.ready



