// JavaScript Document

/**

 * gets content from URL and writes it

 * to a specified area.

 *

 * author: Dave Cooke

 * Date: Jan. 25, 2008

 * Notes: see http://www.w3schools.com/dom/dom_http.asp

 */

 function getNewsItem(urlObject)

 {

	var url = "http://umanitoba.ca/ip/dcooke/html-retiever2.php?var1="+urlObject;

	//prompt("",url);

	new Ajax.Request(url,

    {

    method:'get',

    onSuccess: function(transport){

      var response = transport.responseText || "no response text";

      //prompt("Success! \n\n", response);

	  var theContent = $('midText');

      //theContent.update(url).setStyle({ background: '#dfd' });

	  theContent.update(response);

    },

    onFailure: function(){ alert('Something went wrong...') }

    });

 }//end function getNewsItem.

 /**

  * callSoapService

  *

  * calls the soap client on the server which will

  * call the function required.

  *

  */

 function callPHPFunction()

 {

	 	var url = "http://umanitoba.ca/ip/dcooke/retrieve-info2.php";

		//prompt("",url);

		new Ajax.Request(url,

		{

		

		method:'get',

		onSuccess: function(transport){

			//alert("hererer");

		  var response = transport.responseText || "no response text";

		  //prompt("Success! \n\n", response);

		  var theContent = $('midText');

		  //theContent.update(url).setStyle({ background: '#dfd' });

		  theContent.update(response);

		},

		onFailure: function(){ alert('Something went wrong...') }

		});	 

 }//end callSoapService

 /**

  * hideContacts

  *

  * Hides all contacts except the contact that was passed as

  * a parameter. 

  * This function tries to grab all elements from the document

  * that have the class name "fullInfo". It then iterates through

  * the list of elements and hides all those elements ACCEPT the

  * one element that has the contactID value as its element ID.

  * 

  * requires: protocol.js, Effect.js (from scriptaculous http://script.aculo.us/)

  * param: contactID (css element id)

  * author: Dave Cooke

  * date: Feb 20th, 07

  */

function hideContacts(contactID) {

	//var contacts = document.getElementsByName("fullInfo");

	var contacts = document.getElementsByClassName("fullInfo");

	var contactsNum = contacts.length;

	//alert("hideContacts: "+contactID);

	//alert("contactsNum: "+contactsNum);

	//only do the loop if contactID exists.

	if(contactID)

	{

		for (i=0; i<contactsNum; i++)

		{  

			//get the current object that contains the div and contact info

			selectedNode = contacts[i];

			//get the class of the div...used for debugging

			selectedNodeClass = contacts[i].className;

			//get the ID of the div

			ident = selectedNode.identify();

			//determine if the current ID is the same as the contactID

			//passed as a parameter. If it isn't then make sure that the full

			//contact information for this node is not shown.

			if(contactID != ident )

			{

				//alert("selectedNodClass == contactID:  "+selectedNodeClass+" = "+contactID+" = "+contactID.indexOf(selectedNodeClass));

				Effect.BlindUp(selectedNode,{duration:0});

			}//end if.

	

		}//end for loop

	}//end if.

}//end hideContacts

/**

 * expandContact

 *

 * Displays all the contact information for the given

 * contact which is identified by the contactID (css element ID)

 *

 * requires: protocol.js, Effect.js (from scriptaculous http://script.aculo.us/)

 * param: contactID (css element ID)

 * author: Dave Cooke

 * date: Feb 20th, 07

 *

 */

function expandContact(contactID)

{

	

	Effect.BlindDown(contactID,{duration:1});

	hideContacts(contactID);

	

}//end makeContactsWindow

/**

 *

 * showMedia

 *

 * uses window.js and prototype.js libraries from

 * scriptaculous to display a web page.

 *

 * auth: Dave Cooke

 * date: Mar. 14, 2008

 *

 */

function showMedia(html)

{

//var win = new Window({className: "dialog",  width:600, height:400, zIndex: 1000000, resizable: true, title: "Media Room", url: html,showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})

var win = new Window({className: "alphacube",  width:600, height:400, zIndex: 1000000, resizable: true, title: "News Release", url: html,showEffect:Effect.Appear, hideEffect: Effect.DropOut, draggable:true, wiredDrag: true})
//var win = new Window({className: "alphacube",  width:600, height:400, zIndex: 1000000, resizable: true, title: "News Release", showEffect:Effect.Appear, hideEffect: Effect.DropOut, draggable:true, wiredDrag: true})

//var win = new Window({className: "dialog", title: "Sample", zIndex:1000000, url: html, width:600, height:400, destroyOnClose: true, recenterAuto:false});

//win.getContent().innerHTML= ;

//win.getContent().update(response);

//win.setStatusBar("Media Room");

win.showCenter();

//win.show();

}//end function

/**

 *

 * fetchBlogPosts

 *

 * calls a PHP page on the web server and displays the results.<b> 

 * This function is using the scriptaculous prototype.js library

 * which is essentially using HTTPRequest.

 * auth: Dave Cooke

 * date: Mar. 14, 2008

 *

 */

function fetchBlogPosts()

{

		

	 	var url = '/about/media_room/php/GrabPosts.php';	 	

		//prompt("",url);

		new Ajax.Request(url,

		{		

		method:'get',

		onSuccess: function(transport){

		 				  	

		 var response = transport.responseText || "no response text";

		 //prompt("",response);

		 var theContent = $('midText');		  

		 theContent.update(response);

		},

		onException: function(transport, exception) {

		var ename = exception.name;

		var emsg = exception.message;

		var theContent = $('midText');

		theContent.update("ERROR: "+ename+", "+emsg);

		}

		});

		//prompt("","After the new Ajax.Request call");



}//end fetchBlogPosts.

/**

 * getFeaturedExpert

 * 

 * Retrieves the current featured expert

 * to be displayed on the media room page.

 *

 * auth: Dave Cooke

 * date: Apr. 15, 08

 */

function getFeaturedExpert()

{

	var url = "/about/media_room/php/getFeaturedExpert.php";

	new Ajax.Request(url,

	{		

		method:'get',

		onSuccess: function(transport){

		 				  	

		 var response = transport.responseText || "no response text";		  		  

		 var theContent = $('feedContent4');		  

		 theContent.update(response);

		}

		

	});

	//prompt("","After the new Ajax.Request call");	

}//end getFeaturedExpert

function ajaxRequest(url,divID)

{

	//prompt("",url + "          " + divID);	

	new Ajax.Request(url,

	{		
		
		method:'get',

		onSuccess: function(transport){

		 //prompt("","before var response");			  	

		 var response = transport.responseText || "no response text";

		 //prompt("",response);

		 var theContent = $(divID);		  

		 theContent.update(response);

		},

		onFailure: function()
		{ 
			alert('Something went wrong...');
		},

		onException: function(transport, exception)
		{

		/**

		Of course, this handler will now only restrict its activities to TypeError exceptions. All other errors will be ignored.

		The JavaScript 1.5 specification defines six primary error types, as follows:		

		EvalError - raised when the eval() functions is used in an incorrect manner;		

		RangeError - raised when a numeric variable exceeds its allowed range;		

		ReferenceError - raised when an invalid reference is used;		

		SyntaxError - raised when a syntax error occurs while parsing JavaScript code;		

		TypeError - raised when the type of a variable is not as expected;		

		URIError - raised when the encodeURI() or decodeURI() functions are used in an incorrect manner; 

		excerpt from http://www.alise.lv/ALISE/technolog.nsf/0/53d693d7d1a4f198c2257066003d6153?OpenDocument

		**/
		
		var ename = exception.name;

		var emsg = exception.message;

		var theContent = $(divID);

		theContent.update("ERROR: "+ename+", "+emsg);
		//prompt("",exception);
     	//prompt("",exception.message);

   		}

		

	});
	//prompt("","does test exist? : "+test);
	//prompt("","After the new Ajax.Request call");		
	//var myLightWindow = "";
	//myLightWindow = new lightwindow();
	

}//end ajaxRequest
function ajaxGalleryList(url,div)
{
	ajaxRequest(url,div);
	//if(!myLightWindow)
	//{
		//prompt("","making a lightwindow object...");
		//var myLightWindow = "";
		//myLightWindow = new lightwindow();
	//}//end if.
	//else
	//{
		//prompt("","myLightWindow already exists");
	//}
}//end ajaxGalleryList
/**

function sendData () {

	var url = 'process.php';

	var pars = Form.serialize('frm');

	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );

}

function showLoad () {

	$('load').style.display = 'block';

}

function showResponse (originalRequest) {

	var newData = originalRequest.responseText;

	$('load').style.display = 'none';

	$('status').innerHTML = newData;

}

**/

function search()

{

	var url = "/about/media_room/php/searchExpert.php";

	var pars = Form.serialize('searchForm');

	//prompt("",url + "        parms: "+ pars);	

	new Ajax.Request(url,

	{		

		method:'get',

		parameters:pars,

		onSuccess: function(transport){

		 //prompt("","before var response");			  	

		 var response = transport.responseText || "no response text";

		 //prompt("",response);

		 var theContent = $('searchResult');		  

		 theContent.update(response);

		},

		onException: function(transport, exception) {

		var ename = exception.name;

		var emsg = exception.message;

		var theContent = $('searchResult');

		theContent.update("ERROR: "+ename+", "+emsg);

		}

	});

	//prompt("","After the new Ajax.Request call");		

	

}//end ajaxRequest

