//
// Javascript support for ie marketing i-squad site.
//

// moves entries from one box to another;
// Used for priv. assignment.
//

function cookietest () {
    if (document.cookie.length == 0) {
        window.location.href = "/cookie.html";
    }
}

function mouseHelp(message, region) {

    // default to id = helpregion
    // originally set up to use the upperrright place, but can also be used any time
    // you set up a named region initially set to display: none;
    
    if (!(region)) { 
        region = 'helpregion'; 
    }
    
    if (region == 'helpregion') {
        document.getElementById('upperright').style.display = 'none';
        document.getElementById('whatsthis').style.display = 'block';
    }
    
    document.getElementById(region).firstChild.nodeValue = message;
    document.getElementById(region).style.display = 'block';
}

function clearMouseHelp(region) {
    
    if (! (region)) { 
        region = 'helpregion'; 
    }
    
    if (region == 'helpregion') {
        document.getElementById('upperright').style.display = 'inline';
        document.getElementById('whatsthis').style.display = 'none';
    }
    
    document.getElementById(region).firstChild.nodeValue = '';
    document.getElementById(region).style.display = 'none';
    
}



function Spawn(whichPop) {
    if (whichPop == 'privacy') {
	    newWindow = window.open('/legal/us/privacy.html','Privacy','width=500, height=400, scrollbars=yes, resizable=no');
    }
			
	if (whichPop == 'faq') {
		newWindow = window.open('/legal/us/faq.html', 'FAQ','width=500, height=400, scrollbars=yes, resizable=no');
	}
		
	if (whichPop == 'rules') {
	    newWindow = window.open('/legal/us/rules.html', 'Rules','width=500, height=400, scrollbars=yes, resizable=no');
	}

	if (whichPop == 'terms') {
		newWindow = window.open('/legal/us/terms.html', 'Terms of Use','width=500, height=400, scrollbars=yes, resizable=no'); 
	}

}

function moveOver(from, to) {
	
	var i = 0;
	
	while (i < from.options.length) {
	
		if (from.options[i].selected == true) {
			var j = to.options.length;			
			to.options[j] = new Option(from.options[i].text, from.options[i].value, false, false);	
			from.options[i] = null;
		}
		i++;		
	}
}

/* used in "stereo-shell" selectors */
function clearTo(texas) {
    while (texas.length > 0) {
      texas.options[0]=null;
    }
  }


// Populates a named select box with an array of objects containing .text and .val attributes
// defined in the calling html file.
// 
function populateSelect(entryList, selectName) {

	var i = 0;
	
	while (i < entryList.length) {	
		selectName.options[i] = new Option(entryList[i].text, entryList[i].val, false, false);
		i++;
		} 
	}



// NOTES ON DATEPICKER.
//
// popYear, findDayOfWeek, popDay, isLeap and makeDate are  
// in support of the smart datepicker.
//
// To use, call popYear() and popMonth from the body's onLoad event using appropriate
// parameters.
//
// The document should also have option-free <select>s for year, month, and day, named intelligently
// (no assumptions about their names are made).
//
// Add calls to popDay() to the onChange events for both Year and Month selectors.
//
// Finally, because of the way dates are defined, any change to Year or Month forces the Day
// picker to be repopulated. Consequently, it is best to place these controls on the page
// in Year - Month - Day order, to encourage the user to pick left to right. That way, they
// are less likely to pick day first, and then get confused when their selection goes away when
// they pick year, and goes away again when they pick month.
//
// A more intelligent version would only repop Day if there was a need, of course, but who's
// got time for that?
//
// There are a couple extra features and notes:
// - popYear can be made to spit out future-only dates by careful parameter selection.
//   This was unintentional, but useful.
//
// - findDayOfWeek will do just that, but to work you must define a region for it to 
//   write to in the page. It's only called if you pass a 4th parameter to popDay, which
//   causes it to compute and output the day of the week once you've made your three choices.
//
// - isLeap is internal, but don't forget it's there.
//
// - makeDate() takes two different sets of parameters, depending on if you want to make the
//   form show today's date or some arbitrary date. In either case, the last 3 are the controls
//   in question. See below for details.
//
// - futurePopYear() has been added (june 19) because the author hates using popyear to do 
//   future dates. Its functionality ought to be merged with popYear, but hey, who's got the time?

function popYear(target, numOptions, cutoff) {	
	// Fills year selector with years from current back to current - numOptions.
	// target is in the form of "document.formname.selectname".

	if (arguments.length < 3) {
		alert ("popYear: I want 3 options, and I'm gonna be a jerk about it.");
		return 997;
		}
	
	// cutoff controls the most recent year listed. As such, it can't be more than numOptions.
	//
	if (cutoff > numOptions) {
		alert("popYear: Your paremeters make no sense. It needs to be target-name, numOptions, cutoff");
		return 998;
		}
	
	// This is arbitrary, but frankly why on earth would you want a year picker with 
	// more than 100 entries?
	//
	if (numOptions > 100) {
		alert ("popYear: C'mon, be reasonable. You don't really want " + numOptions + " entries, do you? I'm bailing, dude.")
		return 999;
		}
	
	// make sure it's empty
	target.options.length = 0;

	// put in the default option	
	target.options[0] = new Option("Select Year","default",true,true);

	// Now fill 'er up.	
	var today = new Date();
	var endYear = today.getYear();
	
	if (endYear < 1000) endYear+= 1900;
		
	var floor = endYear - numOptions;

	endYear = endYear - cutoff; /* it may not make sense to populate all the way to curr year */

	var i = 1; /* not zero, since we already added the 0th option above */
	
	while (floor <= endYear) {
		target.options[i] = new Option(floor, floor, false, false);
		floor++;
		i++;
		}
	} // end popYear();
	
// because I decided I was an idiot. 
//
function futurePopYear(target, numoptions) {

    var today = new Date();
    var startyear = today.getYear();
    
    if (startyear < 1000) startyear += 1900;
    
    // make sure the target's empty
    target.options.length = 0;
    
    // add a default
    target.options[0] = new Option("Select Year", "default", true, true);
    
    var i = 0;
    
    while (i < numoptions) {
        target.options[i+1] = new Option(startyear+i, startyear+i, false, false);
        i++;   
    }
}	
	
function popMonth(target) {
    // for better hallway vision.
    // takes name of select control for month.
    //
    
    var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October', 'November','December');   
        
    target.options.length = 0;
    
    target.options[0] = new Option("Select Month", "default", true, true);
    
    var i = 0;
    
    while (i < 12) {
        //
        // the array index starts at 0, but the meaningful months start at 1, and
        // the month values should correspond to 1-12, ergo the i+1 in two spots below.
        //
        target.options[i+1] = new Option(months[i], i+1, false, false);
        i++;
        }
    
    }

function findDayOfWeek(monthPicker, dayPicker, yearPicker) {

	if ( (yearPicker.value != "default") && (monthPicker.value != "default")) {

		pickedDate = new Date(yearPicker.value, monthPicker.value-1, dayPicker.value);
		
		var dow = pickedDate.getDay();
					
		var dayName = new Array();
		
		dayName[0]="Sunday";
		dayName[1]="Monday";
		dayName[2]="Tuesday";
		dayName[3]="Wednesday";
		dayName[4]="Thursday";
		dayName[5]="Friday";
		dayName[6]="Saturday";
		
		var dayOutput = document.getElementById("dayofweek");
	    if (dayOutput) {
    		dayOutput.firstChild.nodeValue = dayName[dow];
    		}
	
		}
	}	
	
function popDay(monthPicker, yearPicker, target, doDay) {
	// Fill the day selector based on the month choice.
	// 31: 1/Jan, 3/Mar, 5/May, 7/July, 8/August, 10/Oct, 11/Dec
	// 30: 4/Apr, 6/Jun, 9/Sep, 11/Nov
	// 28/29: Duh.

    //We should only do anything if and only if both day and month have actual values;
    // it's wasted effort to populate the daypicker without having a setting on both, since
    // any change to either means we have to do it again.
    
    
    // Also, doing operations on monthPicker.value when its value is "default" isn't good.
    
    if ((monthPicker.value != "default") && (yearPicker.value != "default")
        && (monthPicker.value != "") && (yearPicker.value != "")) {

        if (arguments.length < 4) doDay = false;
        
        //doDay controls whether or not we try to spit out the day of week in a region ID=dayofweek
    
        // selectedMonth comes is as the right intuitive number b/c there's a
        // "select month" entry at options[0]. Otherwise, the index would be one less than
        // the usual month value.
        
        var monthList = [
            {mo: 1, days: 31},
            {mo: 2, days: 28},
            {mo: 3, days: 31},
            {mo: 4, days: 30},
            {mo: 5, days: 31},
            {mo: 6, days: 30},
            {mo: 7, days: 31},
            {mo: 8, days: 31},
            {mo: 9, days: 30},
            {mo: 10, days: 31},
            {mo: 11, days: 30},
            {mo: 12, days: 31}];
        
        var limit = monthList[(monthPicker.value)-1].days;
        
        if ((monthPicker.value == 2) && (isLeap(yearPicker.value))) {
        
            limit = 29;
    
        }
    
        // if the value that's been chosen is less than the new max
        // there's no reason to clear the select; we just set the limit
        // to the new max.
        if (target.value > limit) {
    
            target.value = limit;
            
        }
        
        if (target.options.length > limit + 1) {
        
            target.options.length = limit + 1;

        } else if (target.options.length < limit + 1) {
            
            var count = target.options.length;
    
            
            if (count == 0) {
                target.options[count] = new Option("Select Date", "default", false, false);
                count++;
            }

            while ( !(count > limit)) {
                target.options[count] = new Option(count, count, false, false);
                count++;
            }
        }
        
        if (doDay) {
        
        /* I'm pretty sure this doesn't actually do anything */
        
            var dayOutput = document.getElementById("dayofweek");
            
            dayOutput.firstChild.nodeValue = "  ";
        
            }
    
    }			
} // end popDay();

function isLeap(year) {

	// target is an actual year value, not an object. for the month picker.

	// called from popDay.
	//
	// if year is evenly divis by 4 and isn't 2100 (which isn't quite right, but as of this writing
	// won't break for 197 years) AND month is feb, repopulate day to include 29.
	//
	// At some point, change this to actually reflect the real leap algorithm, which is
	// years-div-by-4 unless they're a century year, in which case they aren't, unless the
	// century year is also divisible by 400.
	//
	// If no year has been picked, we rely on the default year setting created in popYear();
	
	if (arguments.length < 1) {
		alert("isLeap: Sorry, we gotta have 1 argument or we get VERY GROUCHY.");
		return 2;
		}
		
	if ((year == 2100) ||
		(year == "default") ||
		(year%4)) {
			return false;
			}
		else {
			return true;
			}	
	} // end isLeap();

//yyyy,mm,dd,yearSelect, monthSelect, daySelect
//
function makeDate(one, two, three, four, five, six){
	// expects one of:
	
	// ('today', yearSelector, monthSelecter, daySelector)
	//or
	// yyyy,mm,dd, yearSelector, monthSelecter, daySelector)
	
	
	// WARNING: you need to pick a year that appears in the target yearselector.
	// Otherwise, no year is selected.
	
	/*
	makeDate('today',document.entry.release_y, document.entry.release_m, document.entry.release_d);
	*/
	if ((arguments.length != 4) && 
		(arguments.length != 6)) {
			alert("makeDate: sorry, params are 'today',y_sel,m_sel,d_sel or year,month,day,y_sel,m_sel,d_sel.");
			return 13;
			} 
	
	if ((one == "today") &&
		 (arguments.length == 4)) {
		 
		 	var yearSelect = two;
		 	var monthSelect = three;
		 	var daySelect = four;
		 	 
		 	var today = new Date();
	
			var yyyy = today.getFullYear();
			var mm = today.getMonth(); /* gives us the 0 - 11 figure, though */
			
			mm++; 
			/* 	so the figure is more intuitive, and to align with 
				the meaningful values in the select */
	
			var dd = today.getDate();
			
			
			
		 	}/* end today clause */
		 
		 else if (arguments.length == 6) {
		 	
		 	var yyyy = one;
		 	var mm = two;
		 	var dd = three;
		 	var yearSelect = four;
		 	var monthSelect = five;
		 	var daySelect = six;
		 
		 
		 	} /* end arbitrary day clause */
		 
		 else {
		 
		 	alert("makeDate: Too freaky. Check your arguments. I can't make heads or tails of them.");
		 	return 1;
		 	} /* args not what we expected, so screw it */
	
	var i=0;
		
	while(i<yearSelect.options.length) {
		if (yearSelect.options[i].value == yyyy) {
			yearSelect.options[i].selected = true;
			}
		i++;
		}
	
	i = 0;
	
	while(i<monthSelect.options.length) {
		if (monthSelect.options[i].value == mm) {
			monthSelect.options[i].selected = true;
			}
		i++
		}

	i = 0;
	
	popDay(monthSelect, yearSelect, daySelect, false);

	while(i<daySelect.options.length) {
		if (daySelect.options[i].value == dd) {
			daySelect.options[i].selected = true;
			}
		i++;
		}
	return 0;
	
	
	} /* end makeDate */


function stripLeadingHash(value) {

	/* 	Takes a document form input box value;
		If it starts with #, it strips the # and returns to modified string;
		If not, it returns the value passed in the first place.
		
	*/	
	if (value[0] == "#") {
		value = value.substring(1,value.length);
		}
	return value;
	}


// Remaining code is preloaders.
//
function teamAdminPreLoad() {
	
	clicked = new Image();
		clicked.src = "/buttons/admin/clicked.gif";
	
	admin_home_over = new Image();
		admin_home_over.src = "/buttons/admin/adminhome_over.gif";

	settings_over = new Image();
		settings_over.src = "/buttons/admin/settings_over.gif";
		
	colors_over = new Image();
		colors_over.src = "/buttons/admin/colorsgraphics_over.gif";
	
	reports_over = new Image();
		reports_over.src = "/buttons/admin/reports_over.gif";
		
	admin_log_over = new Image();
		admin_log_over.src = "/buttons/admin/adminlog_over.gif";
		
	user_log_over = new Image();
		user_log_over.src = "/buttons/admin/userlog_over.gif";
	
	activities_over = new Image();
		activities_over.src = "/buttons/admin/activities_over.gif";
	
	membership_over = new Image();
		membership_over.src = "/buttons/admin/membership_over.gif";
		
	webtools_over = new Image();
		webtools_over.src = "/buttons/admin/webtools_over.gif";
		
	visit_team_over = new Image();
		visit_team_over.src = "/buttons/admin/visitteam_over.gif";

	deactivate_over = new Image();
		deactivate_over.src = "/buttons/admin/deactivate_over.gif";
		
	logout_over = new Image();
		logout_over.src ="/buttons/admin/logout_over.gif";
		
    dmaexplorer_over = new Image();
		dmaexplorer_over.src = '/buttons/admin/dmaexplorer_over.gif';


	}
	

function clientAdminPreLoad() {

	clicked = new Image();
		clicked.src = '/buttons/admin/clicked.gif';
		
	adminhome_over = new Image();
		adminhome_over.src = '/buttons/admin/adminhome_over.gif';
		
	managers_over = new Image();
		managers_over.src = '/buttons/admin/managers_over.gif';
		
	members_over = new Image();
		members_over.src = '/buttons/admin/membership_over.gif';
		
	dmaexplorer_over = new Image();
		dmaexplorer_over.src = '/buttons/admin/dmaexplorer_over.gif';
		
	reports_over = new Image();
		reports_over.src = '/buttons/admin/reports_over.gif';
		
	logout_over = new Image();
		logout_over.src = '/buttons/admin/logout_over.gif';
		
	dmaexplorer_over = new Image();
		dmaexplorer_over.src = '/buttons/admin/dmaexplorer_over.gif';

	
}


function ieAdminPreLoad() {

	 clicked = new Image();
		clicked.src = '/buttons/admin/clicked.gif';
	
	 adminhome_over = new Image();
		adminhome_over.src = '/buttons/admin/adminhome_over.gif';
		
	 managers_over = new Image();
		managers_over.src = '/buttons/admin/managers_over.gif';
		
	 members_over = new Image();
		members_over.src = '/buttons/admin/membership_over.gif';
		
	 clientscompanies_over = new Image();
		clientscompanies_over.src = '/buttons/admin/clientscompanies_over.gif';
		
	 artists_over = new Image();
		artists_over.src = '/buttons/admin/artists_over.gif';
		
	 radiodatabase_over = new Image();
		radiodatabase_over.src = '/buttons/admin/radiodatabase_over.gif';
	
	 videochannels_over = new Image();
		videochannels_over.src = '/buttons/admin/videochannels_over.gif';
		
	 uploadpromoplaya_over = new Image();
		uploadpromoplaya_over.src = '/buttons/admin/uploadpromoplaya_over.gif';
		
	 dmaexplorer_over = new Image();
		dmaexplorer_over.src = '/buttons/admin/dmaexplorer_over.gif';
		
	 reports_over = new Image();
		reports_over.src = '/buttons/admin/reports_over.gif';
		
	 logout_over = new Image();
		logout_over.src = '/buttons/admin/logout_over.gif';
	
	}


function teamPreLoad(dir) {

/* 
Dir is an unvalidated parameter that tells this thing what to actually preload, since we use a mess of buttons.
*/

	if (arguments.length < 1) {
		alert("teamPreLoad: no args");
		return 1;
		}
	
	buttonpath = "/buttons/" + dir + "/";
	
	 clicked = new Image();
		clicked.src = buttonpath + "clicked.gif";

	 message_over = new Image();
		message_over.src = buttonpath + "message_over.gif";
		
	 request_over = new Image();
		request_over.src = buttonpath + "request_over.gif";
	
	 vote_over = new Image();
		vote_over.src = buttonpath + "vote_over.gif";
	
	 quiz_over = new Image();
		quiz_over.src = buttonpath + "quiz_over.gif";
	
	 recruit_over = new Image();
		recruit_over.src = buttonpath + "recruit_over.gif";
	
	 playa_over = new Image();
		playa_over.src = buttonpath + "playa_over.gif";
	
	 rewards_over = new Image();
		rewards_over.src = buttonpath + "rewards_over.gif";
	
	 webtools_over = new Image();
		webtools_over.src = buttonpath + "webtools_over.gif";
	
	 contact_over = new Image();
		contact_over.src = buttonpath + "contact_over.gif";
	
	 activity_over = new Image();
		activity_over.src = buttonpath + "activity_over.gif";
	
	 website_over = new Image();
		website_over.src = buttonpath + "website_over.gif";
		
	store_over = new Image();
		store_over.src = buttonpath + "store_over.gif";
		
	// in the team context, we will also need these for the upper left.
	// They don't vary. There are 4 buttons, 3 of which vary depending on
	// logged-in or not. Privacy Policy persists.
	
	privacypolicy_over = new Image();
		privacypolicy_over.src = "/buttons/teamupperleft/privacypolicy_over.gif";
		
	logout_over= new Image();
		logout_over.src = "/buttons/teamupperleft/logout_over.gif";
		
	myaccount_over = new Image();
		myaccount_over.src = "/buttons/teamupperleft/myaccount_over.gif";
		
	login_over = new Image();
		login_over.src = "/buttons/teamupperleft/login_over.gif";
		
	join_over = new Image();
		join_over.src = "/buttons/teamupperleft/join_over.gif";
		
	forgotpassword_over = new Image();
		forgotpassword_over.src = "/buttons/teamupperleft/forgotpassword_over.gif";
		
	faqs_over = new Image();
		faqs_over.src = "/buttons/teamupperleft/faqs_over.gif";

	terms_over = new Image();
		terms_over.src = "/buttons/teamupperleft/termsofuse_over.gif";
	
		}


function userAdminPreLoad() {
	
	clicked = new Image();
		clicked.src = "/buttons/useradmin/clicked.gif";
		
	myisquads_over = new Image();
		myisquads_over.src = "/buttons/useradmin/myisquads_over.gif";
		
	myinfo_over = new Image();
		myinfo_over.src = "/buttons/useradmin/myinfo_over.gif";
		
	options_over = new Image();
		options_over.src = "/buttons/useradmin/options_over.gif";

	join_over = new Image();
		join_over.src = "/buttons/useradmin/join_over.gif";
		
	privacypolicy_over = new Image();
		privacypolicy_over.src ="/buttons/useradmin/privacypolicy_over.gif";
		
	faqs_over = new Image();
		faqs_over.src = "/buttons/useradmin/faqs_over.gif";
		
	logout_over = new Image();
		logout_over.src = "/buttons/useradmin/logout_over.gif";


	}


function preLoadSamples() {

	threed_over = new Image();
		threed_over.src = "/buttons/3d/website_over.gif";
		
	threed_clicked = new Image();
		threed_clicked.src = "/buttons/3d/clicked.gif";
		
	alien_over = new Image();
		alien_over.src = "/buttons/Alien/website_over.gif";
		
	alien_clicked = new Image();
		alien_clicked.src = "/buttons/Alien/clicked.gif";
		
	postit_over = new Image();
		postit_over.src = "/buttons/Post_It/website_over.gif";
		
	postit_clicked = new Image();
		postit_clicked.src = "/buttons/Post_It/clicked.gif";
		
	radioactive_over = new Image();
		radioactive_over.src = "/buttons/Radioactive/website_over.gif";
		
	radioactive_clicked = new Image();
		radioactive_clicked.src = "/buttons/Radioactive/clicked.gif";
		
	}
