//================== Shawno_24-Oct-07: Prevent <Enter> from submitting form =================//
var nav = window.Event ? true : false;
if (nav) {
   window.captureEvents(Event.KEYDOWN);
   window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
   document.onkeydown = MicrosoftEventHandler_KeyDown;
}

function NetscapeEventHandler_KeyDown(e) {
  if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; }
  return true;
}

function MicrosoftEventHandler_KeyDown() {
  if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
    return false;
  return true;
}
//=============== end of Shawno_24-Oct-07: Prevent <Enter> from submitting form ==============//
var Cookie = {
	getCookie: function(name){
		var cookie = document.cookie;		
		var patern = "[^%;$]"+name + "=([^%;$]*)";
	//alert(patern);
		var re = new RegExp(patern, "i"); //var re = /mkt=(\w+)($%|;)/;
		var result = cookie.match(re);		
		return result? result[1]:'';
	},
	setCookie: function(name,value,expires,path,domain,secure){
	     var tmp = name + "=" +escape(value) +
        ( (path) ? " ;path=" + path : " ;path=" +"/") + 
        ( (domain) ? " ;domain=" + domain : "") +
        ( (expires) ? ( " ;expires=" + expires.toGMTString() ) : "") +
        ( (secure) ? " ;secure" : "");
        document.cookie = tmp;
	},
	deleteCookie: function(name) {
		var exp = new Date(); 
		exp.setTime (exp.getTime() - 1); 
		var cval = Get_Cookie (name); 
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}	
}
var Global = {	
	getQueryString: function(name) {
		var re = new RegExp( "[?&]" + name + "=([^&$]*)", "i" );
		var offset = location.search.search( re );
		if ( offset == -1 ) return null;
		return RegExp.$1;
	},
	logError:function(err){
		try {document.forms[0].wb_jsE.value = document.forms[0].wb_jsE.value 
			+ "#"+ err + "@"+getPageInfo('all'); } catch(e){}
	},
	markDone:function(){
		try {document.forms[0].wb_jsD.value ="@"+getPageInfo('sid'); } catch(e){}
	},
	getPageInfo:function(op){
		try { 
			var rtn	
			switch (op) {
			case "asso":
				rtn = associationName;
				break;
			case "assoS":
				rtn = associationNameS;
				break;
			case "lang":
				rtn = lang;
				break;
			case "pageId":
				rtn = pageId;
				break;
			case "pageType":
				rtn = pagetype;
				break;
			case "prdType":
				rtn = prdType;
				break;
			case "prdID":
				rtn = prdID;
				break;
			case "sid":
				rtn = sid;
				break;
			case "browser":
				var appName = navigator.appName;
				if (appName.indexOf('Microsoft')>-1) {
					rtn = 'IE';
				} else if (appName.indexOf('Netscape')>-1) {
					rtn = 'Mozilla';
				} else {
					rtn = appName;
				}
				break;
			case "all":
				rtn = getPageInfo('browser')+";"+getPageInfo('pageId')+";"
				break;
			default:
				rtn = eval(op);
				break;
			}
			return rtn;	
		} catch (e) { return '' }
	}
}
 //backward compatible functions
function getPageInfo(name) {
	return Global.getPageInfo(name);
}
function getQueryString(variable) {
  var query = window.location.search.substring(1);
  query = query.toLowerCase();
  variable = variable.toLowerCase();
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}

function Get_Cookie(name) {
	return Cookie.getCookie(name);
}
function Set_Cookie(name,value,expires,path,domain,secure) {
	Cookie.setCookie(name,value,expires,path,domain,secure);
}
function Delete_Cookie (name) { 
	Cookie.deleteCookie(name)
}
MKT={
	masso:null,
	getMktCode:function() {
		var mktCode = getQueryString("mkt");
		//if (!mktCode) mktCode = Get_Cookie( "mkt" );
		if (mktCode && mktCode.lastIndexOf('%')>0)	
			mktCode = mktCode.substring(0,mktCode.length-1);
		if (mktCode) { 
			mktCode = mktCode.toUpperCase();				
		}		
		return mktCode;
	},	
	saveMktCode:function() {			
		Delete_Cookie("%mkt");
		var mktCode = MKT.getMktCode();
		//alert('ge_forms.js===' + mktCode);
		if (mktCode) { 
			//Delete_Cookie("mkt");
			//Delete_Cookie("masso");
			MKT.masso = getPageInfo('asso') || getPageInfo('assoS');	
			Set_Cookie("mkt", mktCode);				
			Set_Cookie("masso", MKT.masso);
		};
		//var mkt = Get_Cookie('mkt');
		//alert(document.cookie + "\n"+ "Get_Cookie:"+ mkt);
	}
};
MKT.saveMktCode();

function cLang(langCode){ //--- change lang
	var EWDB = 'affinity.nsf';
//1. get current page info : path, pagename, type and langCode
	var curURL = window.location.href;
	
	//-FIX FOR '&MPATH='.  If this parameters is contained in the query string, then remove it
	//-prior to flipping the language...
	var pos_mpath = curURL.toLowerCase().indexOf("&mpath=");
	if (pos_mpath != -1){
		// Extract everything BEFORE and AFTER the mpath part....
		var mpath = curURL.substring(pos_mpath + 1, curURL.length);
		var mpathBegin = curURL.substring(0, pos_mpath);

		var mpathEnd = "";
		var pos_mpathEnd = mpath.indexOf("&");
		
		if (pos_mpathEnd != -1){
			mpathEnd = mpath.substring(pos_mpathEnd, mpath.length);
		}
		
		curURL = mpathBegin + mpathEnd
	}
	//-END OF FIX FOR &MPATH=
	
	var p
	p = curURL.lastIndexOf('/');
	var curPath = curURL.substring(0, p);
	var curType = (curPath.toLowerCase().indexOf(EWDB)>0)? 'EW':'Form';
	var curPageReq = curURL.substring(p+1, curURL.length);
	p = curPageReq.indexOf('?');
	var curPage = (p>=0)? curPageReq.substring(0, p):curPageReq;
	var curReq = (p>=0)? curPageReq.substring(p+1, curPageReq.length): (curType=='EW')?'':'Open';
	var curLang, formLangP;
	var curAnchor='';
	switch (curType) {
	case 'EW':
		p = curPage.indexOf('#');
		if (p>=0) {
			curAnchor = curPage.substring(p, curPage.length);
			curPage = curPage.substring(0,p);
		}
		curLang = curPage.substring(0, 2)
		curLang = (curLang.toLowerCase() == 'f_')? 'F':'E';
		break;
	case 'Form':
		formLangP = curReq.toLowerCase().indexOf('&lang=');
		if (formLangP>=0) {
			curLang = curReq.substring(formLangP+6, formLangP+7);
			curLang = ( (curLang != 'E')&& (curLang !='F') )?'E':curLang;
		} else {			
			curLang = document.forms[0].lang.value;
			if (curLang=="" | curLang==null){
				curLang = lang;
			}
		}
		break;
	}
//2. change page lang
	if (!langCode) langCode = (curLang=='F')?'E':'F';
	if (langCode == curLang) return 0; //no change
	
	switch (curType) {
	case 'EW':
		curPage = (langCode=='F')? 'f_' + curPage:curPage.substring(2, curPage.length);
		
		//----New stuff for assocation name flip: Start ----
		// Attemp to get as code from query string first, otherwise use default assoCode....
		var qAsso = getQueryString("as");
		if (qAsso==null | qAsso==""){
			curAsso = associationName;
		} else {
		   curAsso = qAsso;
		}
		
		if (langCode=="E"){
		   if (curAsso.substring(0,2)=="f_"){
		      curAsso = curAsso.substring(2,curAsso.length);
		   }
		} else {
		   if (curAsso.substring(0,2) != "f_"){
		      curAsso = "f_" + curAsso
		   }
		}
		
		curReq = "open&as=" + curAsso;
		//----New stuff for assocation name flip: End ----
		
		break;
	case 'Form':
		//-- New method for handling language flip while in applications (CI, TL, GI).  If on the first 
		//-- page of the application process, then allow to flip back n' forth between languages.  However,
		//-- once the application process has been started (QueryString contains 'ParentUNID'), then reroute
		//-- back to site's homepage and flip language.
		curAsso = associationName;
		curPage = curAsso;
	
		if (langCode=="E"){
		   if (curAsso.substring(0,2)=="f_"){
		      curAsso = curAsso.substring(2,curAsso.length);
		      curPage = curAsso;
		   }
		} else {
		   if (curAsso.substring(0,2) != "f_"){
		      curAsso = "f_" + curAsso;
		      curPage = curAsso;
		   }
		}
		
		//==Start of DSP12-Jul-06: New coding for lanugage flip in applications....
		var flipType = ((curURL.toLowerCase().indexOf("parentunid")>0) | (curURL.toLowerCase().indexOf("/apply/")>0))? 'home':'flip';
        if (flipType=='flip'){
        	//-- First page of any automated form -- it's OK to flip language here.  Remove the as= from 
        	//-- the query string.  
        	var pos = curURL.toLowerCase().indexOf("&as=");
        	if (pos != -1){
        		var qsBegin = curURL.substring(0, pos);
        		var qsAsso = curURL.substring(pos+1, curURL.length);
        		var qsEnd = ""
        		pos = qsAsso.indexOf("&");
        		if (pos != -1){
        			qsEnd = qsAsso.substring(pos, qsAsso.length);
        		}
        	}
        	qsNew = qsBegin + qsEnd;

        	//-- Now, extract the path, page & parms into seperate variables...
			curPath = qsNew;
        	var pos = qsNew.toLowerCase().indexOf(".nsf");
			if (pos != -1){
        		curPath = qsNew.substring(0, pos+4);
			}

        	var posEnd = qsNew.toLowerCase().indexOf("?");
        	var curReq = "";
        	if (posEnd != -1){
        		curReq = qsNew.substring(posEnd+1, qsNew.length);
        		//-- Remove the '#' from the end of the qs...
        		if (curReq.substring(curReq.length-1, curReq.length) == "#"){
        			curReq = curReq.substring(0, curReq.length-1);
        		}

				curPage = qsNew.substring(pos+5,posEnd);
        	}
        	
			curReq = curReq + "&as=" + curAsso;        	
        } else {
            //--- already within application process - reroute back to home page of site...
            curPage = cLang_getHomePage(curAsso);
			curPath = "/can/affinity/affinity.nsf/public";
			curReq = "open&as=" + curAsso;
        }
		//==end of DSP12-Jul-06: New coding for lanugage flip in applications....
		
		//break;
	}
//	alert(curPath + '\n' + curPage + '\n'+ curReq + '\n'+ curType + '\n'+ curLang);
//	alert( "New page URL:" + curPath+'/'+curPage+ ((curReq=='')? '': ('?'+curReq)) + curAnchor );
	window.location = curPath+'/'+curPage+ ((curReq=='')? '': ('?'+curReq)) + curAnchor;
}

//--DSP05-01-2007: Additional function for cLang() function to validate 'irregular' home pages.  Homepages for old sites, 
//  such as CAA, have an underscore at the end of the page name (i.e. /Public/caa_) instead of it being just the same as
//  the assocation code.  The following function will determine if the site has an irregular homepage name and will fix
//  accordingly.
function cLang_getHomePage(curAsso){
	var curHomepage = curAsso;
	
	//- Check for CAA 2.0 club....
	if (curAsso.substring(0,3)=="caa"){
		curHomepage = "caa_";
		return curHomepage;
	}
	if (curAsso.substring(0,5)=="f_caa"){
		curHomepage = "f_caa_";
		return curHomepage;
	}
	return curHomepage;	
}
//-- dhtml functions
function toggle(id) {
	el = document.getElementById(id);
	if (el != null) {
		var display = el.style.display ? '' : 'none';
		el.style.display = display;
	}
}
function isHidden(id) {
	el = document.getElementById(id);	
	bIsHidden = (el.style.display == 'none')? true:false;
	return bIsHidden;	
}
function hideTxt(id) {
	el = document.getElementById(id);
	if (el != null)	{ el.style.display = "none"; }
}
function hideTxt2(id) {
	el = document.getElementById(id);
	if (el != null)	{ el.style.visibility = "hidden"; }
}
function showTxt(id) {
	el = document.getElementById(id);
	if (el != null) el.style.display = '';
}
function showTxt2(id) {
	el = document.getElementById(id);
	if (el != null)	{ el.style.visibility = "visible"; }
}
function autoHideShowTxt(id){
    el = document.getElementById(id);
    sDisplayMode = el.style.display;
    if (sDisplayMode==""){
        hideTxt(id);
    } else {
        showTxt(id);
    }
}
function changeObjText(id, message) {
	var evalTxt;
	if (document.layers) { // browser is NN		 
		 evalTxt = "msgObj = window.document."+id;
	}
	else { //assume IE 
		 evalTxt = "msgObj = document.getElementById('"+id+"')";
	}	
	eval(evalTxt);
	if (msgObj) {
		msgObj.innerHTML = message;
	}	
}
function get_IndexFromSelect(objSelect, valueToFind){
   var objValue;
   var chkValue = "ppamcto";
   
   for (var i = 1; i < objSelect.length; i++){
      objValue = objSelect[i].value;
      if (objValue == valueToFind){
         return i;
      }
   }
   
   return 0;
}
function submitonce(theform) {//must used after submit
	if (document.all||document.getElementById){
		for (i=0; i<theform.length; i++){
			var tempobj = theform.elements[i];
			var objType = tempobj.type;
			if(objType!=null && objType!="") objType = objType.toLowerCase();
			switch(objType) {
			case "button":
			case "submit":
			case "reset":
			case "input":
			case "select":			
			case "text":
			case "radio":
			case "select-one":
				tempobj.disabled = true;				
			}
		}
	}
}
//--- open functions ---//
function op(pageurl){
	as = associationName;
	if (pageurl.toLowerCase().indexOf('?open')<0) pageurl = pageurl+"?Open";
	var rtn = pageurl+"&as="+as;
	window.location = rtn;
}
function op_NewWin(pageurl, winWidth, winHeight, winName){
	as = associationName;
	if (pageurl.toLowerCase().indexOf('?open')<0) pageurl = pageurl+"?Open";
	var rtn = pageurl+"&as="+as;
        openWindow( rtn, winWidth, winHeight, winName);
}
function openWindow( url, winWidth, winHeight, winName, openFullWindow) {
	var winTop = (screen.height / 2) - (winHeight / 2);
	var winLeft = (screen.width / 2) - (winWidth / 2);
	var winNM = winName? winName:"win";
	if ( openFullWindow && openFullWindow !="") {
		winFeatures = "";
	} else {
		winFeatures ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + winLeft + ",top=" + winTop + ",width=" + winWidth + ",height=" + winHeight;
	}       
	var thisWin = window.open(url, winNM, winFeatures);
	thisWin.focus();
}
function openCrippledWindow( url, winWidth, winHeight, winName) {
       // This type of window has no features -- no scroll bars, no menus, not resizeable, etc -- untouchable.
       var winTop = (screen.height / 2) - (winHeight / 2);
       var winLeft = (screen.width / 2) - (winWidth / 2);
       if (winName==null | winName==""){
           var winNM = "win";
       } else {
           var winNM = winName;
       }
       winFeatures ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + winLeft + ",top=" + winTop + ",width=" + winWidth + ",height=" + winHeight;
       win = window.open(url, winNM, winFeatures);
       win.focus();
}

function pageRedirect(pageurl){
    	// Opens the new URL and carries over the marketing code with it.  This is mainly used for sites with Omniture tagging
    	// activated, and is called from an old, obsolete landing page.  Once redirected, the marketing code is passed to the 
    	// new URL, thus allowing Omniture to automatically pick it up and assign it to the user's session.
    
	mkt = getQueryString('mkt');
	if (mkt==null | mkt==""){
		mkt = "";
	} else {
		mkt =  "&mkt=" + mkt;
	}
    
	as = associationName;
	if (pageurl.toLowerCase().indexOf('?open')<0) pageurl = pageurl+"?Open";
	var rtn = pageurl+"&as="+ as + mkt;

	window.location = rtn;
}

String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}


//For use with Privacy and Confidentiality and Exchange of Info popup
//For use with Privacy and Confidentiality and Exchange of Info popup
function validatePrivacy() 
{
	var doc = document.forms[0];

	var origURL = window.location;

	if(doc.agree.checked)
	{
		var URL = getQueryString('TargetURL');
		var Title = getQueryString('Title');

		if (URL != "")
		{
			//Omniture Tagging functionality for Alumni Site
			if (Title != null)
			{			
				omniture_flagDownloadLink(this, URL)
				openWindow(URL, 700, 640, 'pdf');	
			}
			else
			{
				//alert(URL);
				openWindow(URL, 700, 640, 'pdf');				
			}
					
		}
		
		window.close();
		return true;
	}
	else
	{
		if(lang == "E")
			alert("Please acknowledge that you have read the notice on Privacy and Confidentiality.");
		else if(lang == "F")
			alert("Veuillez confirmer que vous avez lu l'Avis sur la vie priv\xE9e et la confidentialit\xE9.");			
		return false;
	}	
}
