function gofoward()
       {
		history.forward(1);
       }
function loadtabs(url)
       {
		parent.parent.tabs.location.href=url;
       }
function loadpartabs(url)
       {
         parent.parent.location.href=url
       }
function loadtasks(url)
       {
         parent.parent.tasks.location.href=url
       }
function loadcontent(url)
       {
         parent.parent.content.location.href=url
       }
function loadleft_task(url)
       {
         parent.left_task.location.href=url
       }              
function loadright_task(url)
       {
         parent.right_task.location.href=url
		}
function loadFrames(frame1,page1,frame2,page2) {
			eval("parent."+frame1+".location='"+page1+"'");
			eval("parent."+frame2+".location='"+page2+"'");
		}
function LoadPage(windowpath,pagename) 
    	{
			now = new Date();
			if (pagename.indexOf('?') == -1) 
				sep = '?';
			else 
				sep = '&';
			eval("frameloaded = (" + windowpath + "!= null);");
			locationloaded = false;
			if(frameloaded){
				eval("locationloaded = !!" + windowpath + ".location;");
			}
			if(locationloaded){
				eval(windowpath + ".location.replace('" + pagename + sep + "arg=" + (now.getTime()).toString() + "');");
			}
			else{
				window.setTimeout("LoadPage('" + windowpath + "','" +pagename+"')",200);
			}
		}
function misc_popup(url)
        {
         	miscPopup = window.open(url,'miscPopup',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes,width=680,height=550");
            miscPopup.focus();
        }
        
function info_popup(url)
        {
         	infoWin = window.open(url,'infoWin',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes");
            infoWin.focus();
        }
 
 //added 01/25/07 by CB
// creates new popup windows with a unique name that is passed in	       
function info_popup2(url,name)
        {
         	infoWin2 = window.open(url,name,"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes");
            infoWin2.focus();
        }        

function misc_window_med(url)
        {
         	miscWin_med = window.open(url,'miscWin_med',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,width=400,height=500,screenX=250,screenY=200");
            miscWin_med.focus();
        }
function misc_popup_med(url)
        {
         	miscPopup_med = window.open(url,'miscPopup_med',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=400,height=425,screenX=250,screenY=200");
            miscPopup_med.focus();
        }
        
function misc_popup_sm(url)
        {
         	miscWin_sm = window.open(url,'miscWin_sm',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=350,height=300,screenX=250,screenY=200");
            miscWin_sm.focus();
        }

function help_popup(url)
        {
         	miscWin = window.open(url,'miscWin',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=750,height=500");
            miscWin.focus();
        }
function siteHelp_popup(url)
        {
         	miscWin = window.open(url,'miscWin',"scrollbars=yes,toolbar=no,location=no,top=10,left=700,status=no,menubar=yes,width=900,height=650");
            miscWin.focus();
        }
function siteHelp_popupLg(url)
        {
         	miscWinLg = window.open(url,'miscWinLg',"resizable=yes,directories=yes,scrollbars=yes,toolbar=no,location=no,top=10,left=200,status=no,menubar=no,width=1020,height=650");
            miscWinLg.focus();
        }        
function email_window(url)
        {
         	email_window = window.open(url,'email_window',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=550,height=400");
            email_window.focus();
        }
                
function display_mvo(url)
        {
            mvoWin = window.open(url,'mvoWin',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=780,height=600");
            mvoWin.focus();
        }
function misc_window(url)
        {
            miscWindow = window.open(url,'miscWindow',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=680,height=500");
            miscWindow.focus();
        }
function reports_win(url)
        {
         	reportsWin = window.open(url,'reportsWin',"scrollbars=yes");
            reportsWin.focus();
        }
        
function reports_openWin(url)
        {
            reportsopenWin = window.open(url,'reportsopenWin',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes,width=1000,height=800");
            reportsopenWin.focus();
        }
function displaynewwin(url)
        {
            setDATWin = window.open(url,'setDateAndTimeWin',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=400,height=220,screenX=250,screenY=200");
            setDATWin.focus();
        }
function todoWin(url)
        {
            mytodolist = window.open(url,'mytodolist',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=700,height=400,screenX=150,screenY=200");
            mytodolist.focus();
        }
function displayContactsWebsite(url)
        {
            contactsWebsiteWin = window.open(url,'ContactWebsiteWin');
            contactsWebsiteWin.focus();
        }
function displayScheduleWin(url)
        {
            scheduleWin = window.open(url,'scheduleWin',"scrollbars=no,toolbar=no,location=no,status=yes,menubar=no,resizable=yes");
            scheduleWin.focus();
        }
function displayContactWin(url)
        {
            contactWin = window.open(url,'contactWin',"scrollbars=no,toolbar=no,location=no,status=yes,menubar=no,resizable=yes");
            contactWin.focus();
        }
function displayFlashWin(url)
        {
            flashWin = window.open(url,'flashWin',"scrollbars=no,toolbar=no,location=no,status=yes,menubar=no,resizable=yes");
            flashWin.focus();
        }
function displayFlashFormWin(url)
        {
            flashformWin = window.open(url,'flashformWin',"scrollbars=no,toolbar=no,location=no,status=yes,menubar=no,resizable=yes,width=450,height=500,top=200,left=300");
            flashformWin.focus();
        }
function displayPortalWin(url)
        {	
            portalWin = window.open(url,'portalWin');
            portalWin.focus();
        }
function displayGlobalWin(url)
        {	
            globalWin = window.open(url,'globalWin',"scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes");
            globalWin.focus();
        }
function closewin()
        {
        	top.close();
        }
function reload_frame()
		{ 
            parent.parent.tasks.location.reload()               
		}
function goToPage(URL_List)
		{
  			var URL = URL_List.options[URL_List.selectedIndex].value;
  			window.location.href = URL
		}
function webWizardWin(url)
        {
            WW_Window = window.open(url,'WW_Window',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes,width=960,height=600");
            WW_Window.focus();
        }
function webWizard(url)
        {
            webWizard_details = window.open(url,'webWizard_details',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes,width=700,height=600");
            webWizard_details.focus();
        }
function webWizardHelp(url)
        {
            WW_Help = window.open(url,'WW_Help',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=yes,width=650,height=400");
            WW_Help.focus();
        }
        
function salesPitchWin(url)
        {
            salesPitch = window.open(url,'salesPitch');
            salesPitch.focus();
        }
        
function infoRequestWin(url)
        {
        	infoRequest = window.open(url,'infoRequest',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=500,height=520,screenX=200,screenY=50");
            infoRequest.focus();
        }
        
function questionnaireWin(url)
        {
        	questionnaire = window.open(url,'questionnaire',"scrollbars=yes,toolbar=no,location=no,status=yes,menubar=yes,width=680,height=520,screenX=200,screenY=50");
            questionnaire.focus();
        }

function displayExtSitePreviewWin(url)
        {	
            extSitePreviewlWin = window.open(url,'extSitePreviewlWin',"scrollbars=yes,resizable=yes");
            extSitePreviewlWin.focus();
        }

function displayePreviewWin(url)
        {	
            extSitePreviewlWin = window.open(url,'extSitePreviewlWin',"scrollbars=yes,resizable=yes");
            extSitePreviewlWin.focus();
        }
function LoadTMWNewHireMovie(url)
        {
            miscWindow = window.open(url,'TmwMovies',"scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,width=330,height=400");
            miscWindow.focus();
        }


// AS: Parse through a string looking for emails, seperated by
//  spaces, commas, or semicolons.  Returns a four element array
//  with element [0] containing all of the emails in a simple
//  commas/newline delimited list and element [1] containg al of
//  the invalidly formatted emails in a comma/<BR> delimited list.
//  Finally, element [2] contains the number of emails in the first list
//  and [3] contians the number of emails in the second list.
function parse_emails(str_candidate_emails) {

	var ret = new Array(4);

	var candidate_emails = str_candidate_emails.split(/[\s,;]+/);
	var commalist = new String();
	var bademails = new String();

	var num1 = 0;
	var numbad = 0;

   for (i=0; i<candidate_emails.length; i++)
   {
	   // AS: Skip empty emails
	   if (candidate_emails[i].length == 0)
			 continue;
	   
	   if (-1 == candidate_emails[i].search(/^[\w\.\-\'_]+@([\w\-_]+\.){1,4}[a-zA-Z]{2,4}$/))
	   {
			// AS: If we've already put an entry into the list, then
			//  bademails won't be empty.  So, put a comma/carriage return.
			//  We deend on this carriage return for output formatting so don't remove it.
			if (bademails.length > 0)
				bademails += ",<br>";
				
			bademails += candidate_emails[i];           
			numbad++;
	   }

	   commalist += candidate_emails[i];
	   num1++;
	   if (i != candidate_emails.length - 1)
		   commalist += ", ";
	}

	ret[0] = commalist;
	ret[1] = bademails;
	ret[2] = num1;
	ret[3] = numbad;
	
	return ret;
}

function validate_rockmail_emails() {

	var toBox = document.rocketMail.elements[0];
	var to_emails = parse_emails(toBox.value);

	toBox.value = to_emails[0];
	// AS: We depend on the error_string hidden form elemnt
	//  to be elements[1], because primebase likes to hyphenate
	//  names which doesn't work in JavaScript.
	document.rocketMail.elements[1].value = to_emails[1];

	var fromBox = document.rocketMail.elements[2];
	var from_emails = parse_emails(fromBox.value);
	
	// AS: There can only be 1 from email address.
	if (from_emails[2] > 1)
		from_emails[1] = "There can only be one from email address.";
	else if (from_emails[3] > 0)
		from_emails[1] = "Invalid address: " + from_emails[1];
		
	document.rocketMail.elements[3].value = from_emails[1];

	return true;
}


function validate_ccList_emails() {

	var toBox = document.emailScheduleMgt['text-emailScheduleMgt-ccList'];
	var to_emails = parse_emails(toBox.value);

	toBox.value = to_emails[0];
	// AS: We depend on the error_string hidden form elemnt to be elements[1], because primebase likes to hyphenate names which doesn't work in JavaScript.
	//document.emailScheduleMgt.elements[1].value = to_emails[1];
	
	if (to_emails['text-emailScheduleMgt-ccList'] > 0)
		to_emails['text-emailScheduleMgt-ccList'] = "Invalid address: " + to_emails[1];
		
	document.emailScheduleMgt['hidden-emailScheduleMgt-emailErrorString'].value = to_emails[1];


	return true;
}


function validate_phys_emails() {

	var toBox = document.loggedInChildGlobal.elements[0];
	var to_emails = parse_emails(toBox.value);

	toBox.value = to_emails[0];
	// AS: We depend on the error_string hidden form elemnt
	//  to be elements[1], because primebase likes to hyphenate
	//  names which doesn't work in JavaScript.
	document.loggedInChildGlobal.elements[1].value = to_emails[1];
	//alert( "inside email validation " + to_emails[1] );  

	var fromBox = document.loggedInChildGlobal.elements[2];
	var from_emails = parse_emails(fromBox.value);
	
	// AS: There can only be 1 from email address.
	if (from_emails[2] > 1)
		from_emails[1] = "There can only be one from email address.";
	else if (from_emails[3] > 0)
		from_emails[1] = "Invalid address: " + from_emails[1];
		
	document.loggedInChildGlobal.elements[3].value = from_emails[1];

	return true;
}




// ADDED BY SK FOR COOKIE LOGIN ********************************************

//generic
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 = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}

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);
}

function contains(list, elem){
	if(list == null) return false;
	else return (','+list+',').indexOf(','+elem+',') > -1;
}

function removeElem(list, elem){
	var pos = (','+list+',').indexOf(','+elem+',');
	if(pos == -1) return (list);
	var leftList = list.substring(0,pos-1);
	var rightList = list.substring(pos+elem.length+1,list.length);
	if(leftList != '' && rightList != '') leftList += ',';
	return (leftList + rightList);
}

function toggleDisplay(elemId)
{
	if (document.layers)
	{
		current = (document.layers[elemId].display == 'none') ? 'block' : 'none';
		document.layers[elemId].display = current;
	}
	else if (document.all)
	{
		current = (document.all[elemId].style.display == 'none') ? 'block' : 'none';
		document.all[elemId].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(elemId).style.display == 'none') ? 'block' : 'none';
		document.getElementById(elemId).style.display = vista;
	}
}

//custom
function cookieGlobal(){
	var f = document.forms[0];
	var global_id = f.elements["hidden-globals-global_id"].value;
	if(global_id != '1000000') createCookie("lastGlobal", global_id,3652);
	var lastGlobal = readCookie("lastGlobal");
	//set to last global and go to login
	if(lastGlobal != null && global_id == '1000000'){ 
		f.elements["hidden-globals-global_id"].value = lastGlobal;
		f.action = '/login.lml';
		f.submit();
	}
}

function cookieLogin(){
	var f = document.forms[0];
	var hasCookie = false;
	var doSubmit = false;
	var cookie_ids = readCookie("cookie_ids");
	var global_id = f.elements["hidden-globals-global_id"].value;
	var rmlog_id = f.elements["hidden-rocketMail-rmlog_id"];
	if(!rmlog_id) rmlog_id = '';
	else rmlog_id = rmlog_id.value;
	// no cookie login when there is rocketmail
	if(rmlog_id == ''){
		//remember current global
		if(global_id != '1000000') createCookie("lastGlobal", global_id,3652);
		//is there a cookie?
		if(cookie_ids == null){
			cookie_ids = '';
			cookieGlobal();
		}
		// cookie has been set
		else{
			if(global_id == '1000000'){
				doSubmit = true;
				//change global_id from 1000000 if there is exactly 1 cookie
				if(cookie_ids.indexOf(',') == -1){
					global_id = cookie_ids;
					hasCookie = true;
				}
				//if global_id is 0 and several ids are set goto global selection
				else{
					f.action = '/vl/globals_login.lml';	
				}
			}
			// if global_id <> 0 do cookie login if cookie_ids contains the global id
			else{
				hasCookie = contains(cookie_ids,global_id);
				if(hasCookie) doSubmit = true;
			}
		}
		f.elements["hidden-globals-cookie_ids"].value = cookie_ids;
		//cookie for the current global -> login in now
		if(hasCookie){
			f.elements["hidden-globals-global_id"].value = global_id;
			var userModule = readCookie("userModule");
			if(userModule == null) userModule = '';
			f.elements["hidden-globals-userModule"].value = userModule;
			f.elements["hidden-login-user"].value = readCookie("user" + global_id);
			f.elements["hidden-login-password"].value = readCookie("password" + global_id);
			f.elements["command-login-login"].value = "x";
		}
		if(doSubmit) f.submit();
	}
}

function writeCookie(){
	var f = document.forms[0];
	var cookie_ids = readCookie("cookie_ids");
	var global_id = f.elements["hidden-globals-global_id"].value;
	if(cookie_ids == null){
		cookie_ids = '';
	}
	if(!contains(cookie_ids,global_id)){
		if(cookie_ids == '') cookie_ids = global_id;
		else cookie_ids = cookie_ids + ',' + global_id;
		createCookie("cookie_ids",cookie_ids,3652);
		createCookie("userModule",f.elements["hidden-globals-userModule"].value,3652);
		createCookie("user" + global_id,f.elements["hidden-login-user"].value,3652);
		createCookie("password" + global_id,f.elements["hidden-login-password"].value,3652);
		f.elements['hidden-globals-cookie_ids'].value = cookie_ids;
	}	
}

function eraseCookies(){
	var f = document.forms[0];
	var cookie_ids = readCookie("cookie_ids");
	var global_id = f.elements["hidden-globals-global_id"].value;
	if(contains(cookie_ids,global_id)){
		if(cookie_ids == global_id){
			cookie_ids = '';
			eraseCookie("cookie_ids");
			eraseCookie("userModule");
		}
		else{
			cookie_ids = removeElem(cookie_ids,global_id);
			createCookie("cookie_ids",cookie_ids,3652);
		}
		eraseCookie("user" + global_id);
		eraseCookie("password" + global_id);
		f.elements['hidden-globals-cookie_ids'].value = cookie_ids;
		f.submit();
	}
}


//added 06/06/06 by CB
// This function will be called by a button or link to book mark the site for the user with the appropriate global id.
// bmtitle => bookmark title 
// bmurl => global http name ex. cs.verilogix.net
// bmglobalid => user global id
function addBookmark(bmtitle, bmurl, bmglobalid, howtoUrl) {

//alert( "inside addBookmark. bmtitle = " + bmtitle );  

if( document.all )
  {
    // Internet Explorer	
	var urlAndGlobalid = "http://" + bmurl + "/index.htd?a-globals-global_id=" + bmglobalid; 
    window.external.AddFavorite( urlAndGlobalid, bmtitle);
  }
  else
  {
	// netscape, firevox, mozilla, etc
    // Open popup window with the link in it for the user to copy/past it into their bookmarks
    howtoBookmark = window.open(howtoUrl,'howtoBookmark',"scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width=680,height=200");
    howtoBookmark.focus();
  }
}

//added 10/19/06 by CB
// creates new popup windows based on the hight and width passed
function resizable_popup(url,winheight,winwidth)
	{
		resizableWin = eval('window.open("'+url+'","resizableWin","scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,width='+winheight+',height='+winwidth+'")');
        resizableWin.focus();
	}
	

//added 10/19/06 by CB
// Added the bottom three functions to open and close some collapsible menues in the MENS WEAERHOUSE NEWHIRE PORTAL
function hideLevel( _levelId) {
	var thisLevel = document.getElementById( _levelId );
	thisLevel.style.display = "none";
	}

function showLevel( _levelId) {
	var thisLevel = document.getElementById( _levelId );
	if ( thisLevel.style.display == "none") {
		thisLevel.style.display = "block";
		}
	else {
		hideLevel( _levelId);
		}
	}
	

function hideAllTables(){
	var tableids = document.getElementsByTagName('table');
	for(i=0; i<tableids.length; i++){
		if(tableids[i].id != ''){
			tableids[i].style.display='none';
		}	
	}
}	

function ClearAll(){
	var userlistcount = document.getElementById("UserList").options.length;
	if (document.getElementById("chkUnSelectAll").checked == true){	
		if (userlistcount !=0){
			for(var i=0; i < userlistcount; i++){
				document.getElementById("UserList").options[i].selected = false;
			}
		}
		document.getElementById("chkAllUser").checked = false;	
	}
}
	
function SelectALL(){
	var userlistcount = document.getElementById("UserList").options.length;
	if (document.getElementById("chkAllUser").checked == true){	
		if (userlistcount !=0){
			for(var i=0; i < userlistcount; i++){
				document.getElementById("UserList").options[i].selected = true;
			}
		}
		document.getElementById("chkUnSelectAll").checked = false;
	} else {
		if (userlistcount !=0){
			for(var i=0; i < userlistcount; i++){
				document.getElementById("UserList").options[i].selected = false;
			}
		}
	}
}

// CS - BLINKING FUNCTION (SHOULD WORK FOR ALL BROWSERS )
function doBlink() {
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
	blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

// CS - BLINKING FUNCTION (SHOULD WORK FOR ALL BROWSERS )
function startBlink() {
  if (document.all)
	setInterval("doBlink()",600)
}


