/**
 * @author Fabien
 */
function filterCpies(){
	
	var indus = $('slcIndustry').value;
	var region = $('slcRegion').value;
	
	var aIndustries = new Array();
	var toFindIndus = true;
	switch (indus) {
		case "Consulting":
			aIndustries.push("Consulting");
			break;
		case "CProducts":
			aIndustries.push("Consumer Products");
			break;
		case "FServices":
			aIndustries.push("Financial Services");
			break;
		case "Technology":
			aIndustries.push("Biotechnology");
			aIndustries.push("Information Technology");
			aIndustries.push("Internet and eBusiness");
			aIndustries.push("Telecommunications");
			break;
		case "Other":
			aIndustries.push("Consulting");
			aIndustries.push("Consumer Products");
			aIndustries.push("Financial Services");
			aIndustries.push("Information Technology");
			aIndustries.push("Internet and eBusiness");
			aIndustries.push("Telecommunications");
			toFindIndus = false;
			break;
	}
	
	var aRegions = new Array();
	var toFindRegion = true;
	switch(region) {
		case "Asia":
			aRegions.push("Asia");
			aRegions.push("World Wide");
		break;
		case "Europe":
			aRegions.push("Central and Eastern Europe");
			aRegions.push("Western Europe");
			aRegions.push("World Wide");
		break;
		case "MEast":
			document.location.href = "http://www.mba-exchange.com/MiddleEastTalentPool/Can/AutoRedirect.php?session="+document.getElementById("InterceptSession").value;
			//aRegions.push("Middle East");
			//aRegions.push("World Wide");
		break;
		case "NAmerica":
			aRegions.push("North America");
			aRegions.push("World Wide");
		break;
		case "Other":
			aRegions.push("Asia");
			aRegions.push("Central and Eastern Europe");
			aRegions.push("Western Europe");
			aRegions.push("Middle East");
			aRegions.push("North America");
			toFindRegion = false;
		break;
	}
	
	var allDiv = document.getElementsByTagName('div');
	for (var i = 0; i < allDiv.length; i++) {
		if ((allDiv[i].className == 'cpyNormal') || (allDiv[i].className == 'cpyHighlighted')) {
			if (indus == '' && region == '') {
				NormalCpy(allDiv[i]);
			}
			else {
				aSpans = allDiv[i].getElementsByTagName('span');
				var aCpyIndus = aSpans[0].innerHTML.split(',');
				var aCpyRegions = aSpans[1].innerHTML.split(',');
				
				var foundIndus = false;
				if (indus == '') {
					foundIndus = true;
				}
				else {
					var j = 0;
					while (j < aCpyIndus.length && !foundIndus) {
						var zFound = false;
						var k = 0;
						while (k < aIndustries.length && !zFound) {
							if (aCpyIndus[j] == aIndustries[k]) {
								zFound = true;
							}
							else {
								k++;
							}
						}
						if (zFound) {
							foundIndus = true;
						}
						else {
							j++;
						}
					}
					if (!toFindIndus) {
						foundIndus = !foundIndus;
					}
				}
				
				var foundRegion = false;
				if (region == '') {
					foundRegion = true;
				}
				else {
					var j = 0;
					while (j < aCpyRegions.length && !foundRegion) {
						var zFound = false;
						var k = 0;
						while (k < aRegions.length && !zFound) {
							if (aCpyRegions[j] == aRegions[k]) {
								zFound = true;
							}
							else {
								k++;
							}
						}
						if (zFound) {
							foundRegion = true;
						}
						else {
							j++;
						}
					}
					if (!toFindRegion) {
						foundRegion = !foundRegion;
					}
				}
				
				
				if (foundIndus && foundRegion) {
					HighLightCpy(allDiv[i]);
				}
				else {
					NormalCpy(allDiv[i]);
				}
			}
		}
	}
}


function HighLightCpy(elem)
{
	new Effect.Pulsate(elem, {
		pulses: 2,
		duration: 1
	});
	elem.className = 'cpyHighlighted';
}
function NormalCpy(elem)
{
	elem.className = 'cpyNormal';
}

var actualBloc = 0;

function filterPrograms()
{
	actualBloc = 0;
	new Effect.Appear('imgLoadingPrgrm');
	new Effect.Fade('divPrograms', {
		duration: .5,
		afterFinish: function() {
		new Ajax.Request('/AJAX/CompanyProfiles.php?session='+session, {
				method: 'post',
				parameters: {
					action: 'GetDevPrograms',
					type: 'public',
					cpyID : $('slcProgramCompanies').value,
					farID : $('slcProgramFunctions').value,
					idyID : $('slcProgramIndustries').value
				},
				onSuccess: function(r) {
					$('divPrograms').update(r.responseText);
					new Effect.Appear('divPrograms', { duration: .5 });
					new Effect.Fade('imgLoadingPrgrm');
				}
			});
		}
	});
}


function NextBlocProgram()
{
	$('blockProgram_' + actualBloc).hide();
	$('blockProgram_' + (actualBloc+1)).show();
	
	$('devPage_' + actualBloc).setStyle({
		fontWeight: 'bolder',
		textDecoration: 'underline'
	});
	actualBloc++;
	managePrevNext();
}

function PrevBlocProgram()
{
	$('blockProgram_' + actualBloc).hide();
	$('blockProgram_' + (actualBloc-1)).show();
	
	$('devPage_' + actualBloc).setStyle({
		fontWeight: 'bolder',
		textDecoration: 'underline'
	});
	
	actualBloc--;
	managePrevNext();
}

function goToBloc(nb)
{
	$('blockProgram_' + actualBloc).hide();
	$('blockProgram_' + nb).show();
	
	$('devPage_' + actualBloc).setStyle({
		fontWeight: 'bolder',
		textDecoration: 'underline'
	});
	
	actualBloc = nb;
	managePrevNext();
}

function managePrevNext()
{
	$('devPage_' + actualBloc).setStyle({
		fontWeight: 'normal',
		textDecoration: 'none'
	});
	if(actualBloc > 0) {
		$('PrevButton').show();
	}
	else {
		$('PrevButton').hide();
	}
	if(actualBloc < ($('nbPages').value-1)) {
		$('NextButton').show();
	}
	else {
		$('NextButton').hide();
	}
}


/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod )
{
	if (nod != null) {
		return (nod.nodeType == 8) || // A comment node
		((nod.nodeType == 3) && is_all_ws(nod)); // a text node, all ws
	}
}