
////////////////////////////////////////////////////////////////////////////////////////////
// COOKIE SCRIPTS
////////////////////////////////////////////////////////////////////////////////////////////

function Cookie(neverExpire) {
	//	 Properties.
	this.neverExpire = Cookie.arguments.length > 0 ? (testBoolean = new Boolean(neverExpire) ? neverExpire : false ) : false ;

	//  Methods.
	this.hasCookie = hasCookie ;
	this.getNeverExpire = getNeverExpire ;
	this.setNeverExpire = setNeverExpire ;
	this.getCookieNames = getCookieNames ;
	this.destroyCookie = destroyCookie ;
	this.destroyAllCookie = destroyAllCookie ;
	this.setCookieValue = setCookieValue ;
	this.getCookieValue = getCookieValue ;
	this.getAllCookieValue = getAllCookieValue ;
}

function getNeverExpire() {
	return this.neverExpire ;
}

function setNeverExpire(neverExpire) {
	this.neverExpire = Cookie.arguments.length > 0 ? (testBoolean = new Boolean(neverExpire) ? neverExpire : false ) : false ;
}

/*
	Public Method hasCookie.
	Find cookie by cookieName. The method return boolean true when found or return false when other.
	If no argument, the method will return true when found any cookie.
*/
function hasCookie(cookieName) {
	if(hasCookie.arguments.length == 0) {
		return document.cookie.length > 0 ;
	} else {
		return (document.cookie.length > 0 && document.cookie.indexOf(cookieName+"=") >= 0)
	}
}

/*
	Public Method getCookieName.
	Return String Array of cookieName.
*/
function getCookieNames() {
	if(hasCookie())
		var cookieNames = document.cookie.toString().split(";") ;
	for(i = 0 ; i < cookieNames.length ; i++)
		cookieNames[i] = cookieNames[i].substring(0, (cookieNames[i].indexOf("=") >= 0 ? cookieNames[i].indexOf("=") : cookieNames.length)) ;

	return cookieNames ;
}

/*
	Public Method destroyCookie.
	Clear value containded in cookieName and expire it.
*/
function destroyCookie(name) {
	expDate =  new Date() ;
	expDate.setTime (expDate.getTime() - 1);  
	document.cookie = name + "=null; expires=" + expDate.toGMTString() ;
}

/*
	Public Method destroyAllCookie.
	Clear all cookie values.
*/
function destroyAllCookie() {
	if(hasCookie()) {
		var cookieNames = getCookieNames() ;
		for(i = 0 ; i < cookieNames.length ; i++) {
			destroyCookie(cookieNames[i]) ;
		}
	}
}

/*
	Public Method setCookieValue.
	Set value to cookie. Argument name passed as String, value passed as String. Method will replace exist value.
*/
function setCookieValue(name, value) {
	//	 Default expire at 365 days.
	expDate = new Date() ;
	expDate.setTime(expDate.getTime() + (365 * 24 * 60 * 60 * 1000)) ;
	document.cookie = name + " = " + escape(value) + " ;expires=" + expDate.toGMTString() + " ;path=/";
//	document.write('$'+document.cookie+'<br>') ;alert() ;
}

/*
	Public Method getCookieValue.
	Return the value contained in cookieName or null value when can not found cookieName.
*/
function getCookieValue(name) {
	if(hasCookie(name)) {
		var start = document.cookie.indexOf(name+"=") + name.length + 1 ;
		var end = document.cookie.indexOf(";", start) > 0 ? ( document.cookie.indexOf(";", start)) : document.cookie.length ;
		if(this.neverExpire)
			setCookieValue(name, unescape(document.cookie.substring(start, end))) ;
		return unescape(document.cookie.substring(start, end)) ;
	} else {
		return null ;
	}
}

/*
	Public Method getAllCookieValue.
	Return 2 Dimensions String Array, contain pair of name and value. No argument required.
*/
function getAllCookieValue() {
	var result ;
	if(hasCookie()) {
		result = new Array() ;
		var cookieNames = getCookieNames() ;
		for(i = 0 ; i < cookieNames.length ; i++) {
//			if(this.neverExpire)
//				setCookieValue(cookieNames[i], cookieNames[i], getCookieValue(cookieNames[i])) ;
			result[i] = new Array(cookieNames[i], getCookieValue(cookieNames[i])) ;
		}
	}
	return result ;
}


////////////////////////////////////////////////////////////////////////////////////////////
// ADMIN SITE SCRIPTS
////////////////////////////////////////////////////////////////////////////////////////////

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, radioObjCustom, newValue) {
	var valueSet = false;
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		if (newValue == null) {
			radioObj.checked = true;
			return;
		}
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	if (newValue == null) {
		radioObj[0].checked = true;
		return;
	}	
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
			valueSet = true;
		}
	}
	if ((valueSet == false) && (radioObjCustom)) {
		if (newValue != "") {
			radioObj[radioLength - 1].checked = true;
			radioObjCustom.value = newValue;
		}
	}
}


////////////////////////////////////////////////////////////////////////////////////////////
// LEFT NAVIGATION SCRIPTS
////////////////////////////////////////////////////////////////////////////////////////////

function writeLeftnav() {
	var lNav = "";
	lNav += writeNavbutton('Home', '/cvweb_sales/cvweb/MainHome.shtml');
    lNav += writeNavbutton('Membership', '');
	lNav += writeNavbutton('Events', '');
	lNav += writeNavbutton('Products', '');
	lNav += writeNavbutton('Subscriptions', '');
	lNav += writeNavbutton('Job Bank', '');
	lNav += writeNavbutton('My Account', '');
	document.getElementById('leftnav').innerHTML = lNav;
}

function writeLeftnavClas() {
	var lNav = "";
    lNav += writeNavbuttonClas('Members', '');
	lNav += writeNavbuttonClas('Committees', '');
	lNav += writeNavbuttonClas('Events', '');
	lNav += writeNavbuttonClas('Logout', '/cvweb_sales/clas/cgi-bin/logindll.dll/indlogoff');
	document.getElementById('leftnav').innerHTML = lNav;
}

function writeNavbutton(btnName, btnLink) {

	btnHtml = "";

	if (getCookieValue('navstate') != btnName) {
		if (btnName != 'Home') {
			btnHtml += "<div class=\"navbutton\" onclick=\"destroyCookie('navstate');setCookieValue('navstate', '" + btnName + "');writeLeftnav();\" onmouseover=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_active.png)';\" onmouseout=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_inactive.png)';\">" + btnName + "</div>";
		} else {
			btnHtml += "<div class=\"navbutton\" onclick=\"destroyCookie('navstate');setCookieValue('navstate', '" + btnName + "');writeLeftnav();window.location.href = '" + btnLink + "';\" onmouseover=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_active.png)';\" onmouseout=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_inactive.png)';\">" + btnName + "</div>";
		}
	} else {
	
		switch(btnName)
		{
		case "Membership":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/MemberSearch.shtml'>Member Directory</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/MembershipApp.shtml'>Join Now</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/MembershipAppAdvanced.shtml'>Join Now (Advanced)</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/CommitteeSearch.shtml'>Committee Directory</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/Chapterdll.dll/List?sort=CHAPTERCD'>Chapter Directory</a></div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Events":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/eventsdll.dll/EventList?SESSIONALTCD=&SESSIONBEGDATE=>" + calcBegindate() + "&STATECD=&PROGRAMALTCD=&MAJORCAT=&SORT=SESSIONBEGDATE,PROGRAMALTCD,STATECD&ONWEBFLG=Y&REGONLINEFLG=Y&RANGE=1/25'>Upcoming Events</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/eventsdll.dll/EventList?ONWEBFLG=Y&REGONLINEFLG=Y&CALVIEW=now&sort=SESSIONBEGDATE&RESPONSEHEADERPAGE=main_template.htm'>Calendar of Events</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/EventSearch.shtml'>Advanced Search</a></div>";			
			btnHtml += "<div class=\"navbuttonC\"><a target='_blank' href='/cvweb_sales/cvweb/cgi-bin/exhibit.dll/ShowFloorPlan?SESSIONALTCD=ANNUALCONFERENCE08&WMT=none'>Show Floor Plan</a></div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Products":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/msascartlist.dll/ProductList?RANGE=1/25'>All Products</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/Products.shtml'>Advanced Search</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/msascartlist.dll/GetCart'>My Shopping Cart</a></div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Subscriptions":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			var memberid = getCookieValue("memberid");
		  	if (memberid == null) {
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/mainLoginSecurity.shtml'>My Subscriptions</a></div>";
			} else {
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/Subscriptiondll.dll/List?customercd=" + memberid + "'>My Subscriptions</a></div>";
			}
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Job Bank":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/JobBoard.dll/AppInfo?WRP=MyResume.htm'>Submit My Resume</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/JobBoard.dll/List?WNR=nrRedir.htm'>Apply for a Job</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/JobBoard.dll/AppList?WNR=nrRedir.htm'>View My Job Applications</a></div>";			
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "My Account":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			if (getCookieValue("customercd") == null) {
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/MainLogin.shtml'>Login</a></div>";						
			} else {
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/memberdll.dll/Info?WRP=MainLoginWelcome.htm'>My Homepage</a></div>";
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/memberdll.dll/Info?WRP=Customer_Update.htm'>Update Profile</a></div>";
				btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/cvweb/cgi-bin/logindll.dll/indlogoff'>Logout</a></div>";
			}
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		default:
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			break;
		}				
		
	}	
	
	return btnHtml;

}		

function writeNavbuttonClas(btnName, btnLink) {

	btnHtml = "";

	if (getCookieValue('navstate') != btnName) {
		if (btnName != 'Logout') {
			btnHtml += "<div class=\"navbutton\" onclick=\"destroyCookie('navstate');setCookieValue('navstate', '" + btnName + "');writeLeftnavClas();\" onmouseover=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_active.png)';\" onmouseout=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_inactive.png)';\">" + btnName + "</div>";
		} else {
			btnHtml += "<div class=\"navbutton\" onclick=\"destroyCookie('navstate');setCookieValue('navstate', '" + btnName + "');writeLeftnavClas();window.location.href = '" + btnLink + "';\" onmouseover=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_active.png)';\" onmouseout=\"this.style.backgroundImage='url(/cvweb_sales/img/nav" + navColor + "_inactive.png)';\">" + btnName + "</div>";
		}
	} else {
	
		switch(btnName)
		{
		case "Members":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/clas/cgi-bin/memberdll.dll/OpenPage?WRP=membership.htm'>Search Individuals</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/clas/cgi-bin/memberdll.dll/OpenPage?WRP=membership_reports.htm'>Membership Reports</a></div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Committees":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='javascript:nav_ViewCommittees();'>View/Manage My Committees</a></div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		case "Events":
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			btnHtml += "<div class=\"navbuttonB\"></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='javascript:nav_GetChapterEvents();'>Event Search</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/clas/cgi-bin/eventsdll.dll/EventList?ONWEBFLG=Y&REGONLINEFLG=Y&CALVIEW=now&sort=SESSIONBEGDATE'>Event Calendar</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='/cvweb_sales/clas/cgi-bin/admin.dll/LocationInfo'>Add an Event</a></div>";
			btnHtml += "<div class=\"navbuttonC\"><a href='javascript:nav_ManageChapterEvents();'>Manage/Update Events</a></div>";			
			btnHtml += "<div class=\"navbuttonB\"></div>";				
			break;    
		default:
			btnHtml += "<div class=\"navbuttonA\">" + btnName + "</div>";
			break;
		}				
		
	}	
	
	return btnHtml;

}		

function calcBegindate() {
   	var today = new Date();
	year = today.getYear();
	if (year < 2000)    
	year = year + 1900; 
	var tdate = ( (today.getMonth() + 1) + "/" + (today.getDate()) + "/" + year );
	return tdate;
}

function getMobileColor(ncol) {
	mcol = ""
	if (ncol == "Black") {
		mcol = "#787878";	
	} else if (ncol == "Blue") {
		mcol = "#5A8DDA";
	} else if (ncol == "Gray") {
		mcol = "#A6A6A6";
	} else if (ncol == "Purple") {
		mcol = "#8A71A4";
	} else if (ncol == "Red") {
		mcol = "#A65A5A";				
	} else {
		mcol = "#8DA65A";
	}
	return mcol;
}

function displayLinks2() {
	//do nothing	
}


////////////////////////////////////////////////////////////////////////////////////////////
// SECURITY SCRIPTS
////////////////////////////////////////////////////////////////////////////////////////////

// check page access onLoad and redirect to the login page if necessery
function checkPageAccess(fromPage) {
  var memberid = getCookieValue("memberid");
  var ismember = getCookieValue("ismember");
  if ((memberid == "") || (ismember != "Y")) {
    location.href = "/cvweb_sales/cvweb/mainLoginSecurity.shtml?" + fromPage ;
  }
}


////////////////////////////////////////////////////////////////////////////////////////////
// CLAS SCRIPTS
////////////////////////////////////////////////////////////////////////////////////////////

function nav_DoHomePage() {
 var allcookies = document.cookie;
 var pos = allcookies.indexOf("USERCD");  if ( pos == -1)  {
  location.href = "/cvweb_sales/clas/Login.shtml";
 }
 else
 {
  location.href = "/cvweb_sales/clas/cgi-bin/employeedll.dll/home?WRP=myvantage.shtml";  }
}

var cList = "";
var cArr;

function nav_GetChapterEvents() {
	location.href = "/cvweb_sales/clas/cgi-bin/eventsdll.dll/EventList?ONWEBFLG=Y&COMPANYCD=" + document.frmNav.CHAPTERID.value + "&SESSIONBEGDATE=>getdate()-1&sort=SESSIONBEGDATE";	
}
			
function nav_ManageChapterEvents() {
	location.href = "/cvweb_sales/clas/cgi-bin/eventsdll.dll/EventList?ONWEBFLG=Y&COMPANYCD=" + document.frmNav.CHAPTERID.value + "&SESSIONBEGDATE=>getdate()-1&sort=SESSIONBEGDATE&RESPONSEBODYPAGE=Event_Update.htm&WHP=Event_Update_Header.htm";	
}                                                
                          		
function nav_ViewCommittees() {
	location.href = "/cvweb_sales/clas/cgi-bin/memberdll.dll/OpenPage?WRP=committee.htm";
	//location.href = "/cvweb_sales/clas/cgi-bin/committeedll.dll/List?COMPANYCD=" + document.frmNav.CHAPTERID.value + "&RESPONSEBODYPAGE=CommitteeList.htm&WHP=CommitteeListHeader.htm";	
}

function nav_AddCommittee() {
	location.href = "/cvweb_sales/clas/cgi-bin/committeedll.dll/Info?committeecd=" + document.frmNav.CHAPTERID.value + "&RESPONSEPAGE=CommitteeAdd.htm";	
}

function nav_AddCommitteeMember() {
	location.href = "/cvweb_sales/clas/cgi-bin/committeedll.dll/Info?committeecd=" + document.frmNav.CHAPTERID.value + "&RESPONSEPAGE=CommitteeOfficer.htm";	
}
function nav_UpdateCommitteeMember() {
	location.href = "/cvweb_sales/clas/cgi-bin/committeedll.dll/IndList?ic.committeecd=" + document.frmNav.CHAPTERID.value + "&ACTIVEFLG=Y&SORT=IC.CUSTOMERNAME";	
}

