/**********************************************************************************
The function "linkTo" is used to open components in new windows.

The arguments are:
- component: This is the ID# of the component to be opened in 
			the new window. REQUIRED
- width: The width of the window to be opened. REQUIRED. (The default width is 640px)
- height: The height of the window to be opened. REQUIRED. (The default width is 480px)
- opt: The properties of the window to be opened. NOTE: This string must be comma-separated 
		without spaces.(The default properties are "menubar,status,resizable,scrollbars")
- loc: The location that the current window will redirect to. If this is left blank, 
		the current content will reload itself.
		
An alert dialog box with the warning "warn" will appear if any of the required 
arguments or the optional "loc" argument is not a numerical value.

Example:
<A HREF="javascript: linkTo('55555','640','480','scrollbars,resizable');">link</a>
***********************************************************************************/

function randomname()
{
  var windowname = Math.round((Math.random()*1000000));
  var windowname2 = Math.round((Math.random()*10000));
  var x = windowname +"V";
  var name1 = "ingvfcPoP" + windowname2;
  var value1 = windowname+"V";
  var cookiename = name1 + "=" + value1;
  document.cookie= cookiename;
  return x;
}



function linkTo(component,width,height,opt,loc) {
	var warn = "This resource is incorrectly linked. Please contact the site administrator."
	var maximum = "false";
	if(!width  || width==null || width=="") width="640";
	if(!height || height==null || height=="") height="480";
	if(!opt) opt="menubar,status,resizable,scrollbars";
	
	if(isNaN(component)) {
		if(component.indexOf("://") != -1||component.indexOf("/forms") != -1) {
			if(component.indexOf("/forms") != -1) {
				component="http://www.ingvfc.com"+component;
			}
			var targ = "winSite";
		} else {
			alert(warn);
			return false; 
		} 
	} else {
		var targ = "win"+ component;
		component = "/ComponentProxy?c="+component;
	}

	if(isNaN(width)) {
		if(width != "max") {
			alert(warn);
			return false; 
		} else {
			width = screen.availWidth;
			maximum = true;
		}
	}

	if(isNaN(height)) {
		if(height != "max") {
			alert(warn);
			return false; 
		} else {
			height = screen.availHeight;
			maximum = true;
		}
	}
	
	var features = "width="+width+",height="+height+ ","+opt;
	var popup;

	if(!loc) {
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
	} else if(isNaN(loc)) {
		if(loc=="nav") {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
			window.history.back();
		} else {	
			alert(warn);
			return false;
		}
	} else {
		loc = "/ComponentProxy?c="+loc;
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
		window.location = loc;
	}
}

/*********************************************************************************************
The function "selectLink" is used to open components in new windows from the 
"onChange" event handler of a dropdown <SELECT> list.

The arguments are:
- component: This is the ID# of the component to be opened in the new window. 
			 This should always be set to "this.options[this.selectedIndex].value"
			 A value of "null" will prevent a window from being opened and not 
			 generate an alert. REQUIRED
- width: The width of the window to be opened. REQUIRED. (The default width is 640px)
- height: The height of the window to be opened. REQUIRED. (The default width is 480px)
- opt: The properties of the window to be opened. NOTE: This string must be comma-separated 
		without spaces.(The default properties are "menubar,status,resizable,scrollbars")
- loc: The location that the current window will redirect to. If this is left blank, 
		the current content will reload itself.
		
An alert dialog box with the warning "warn" will appear if any of the required 
arguments or the optional "loc" argument is not a numerical value.

Example:
<form>
<select onchange="selectLink(this.options[this.selectedIndex].value,'600','400','resizable');">
<option>--Please Select--</option>
<option VALUE="null">Selecting me will do nothing</option>
<option VALUE="55555">Go to Component</option>
</form>
**********************************************************************************************/
function selectLink(component,width,height,opt,loc) {
	var warn = "This resource is incorrectly linked. Please contact the site administrator."
	var maximum = "false";
	if(isNaN(component)) {
		if(component.indexOf("://") != -1||component.indexOf("/forms") != -1) {
			if(component.indexOf("/forms") != -1) {
				component="http://www.ingvfc.com"+component;
			}
			var targ = "winSite"
		} else if (component == "null") { 
			return false;
		} else {
			alert(warn);
			return false; 
		}
	} else {
		var targ = "win"+ component;
		component = "/ComponentProxy?c="+component;
	}

	if(!width  || width==null || width=="") width="640";
	if(!height || height==null || height=="") height="480";
	if(!opt) opt="menubar,status,resizable,scrollbars";
	
	if(isNaN(width)) {
		if(width != "max") {
			alert(warn);
			return false; 
		} else {
			width = screen.availWidth;
			maximum = true;
		}
	}

	if(isNaN(height)) {
		if(height != "max") {
			alert(warn);
			return false; 
		} else {
			height = screen.availHeight;
			maximum = true;
		}
	}  
	
	var features = "width="+width+",height="+height+ ","+opt;
	var popup;

	if(!loc) {
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
	} else if(isNaN(loc)) {
		alert(warn);
		return false;
	} else {
		loc = "/ComponentProxy?c="+loc;
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
		window.location = loc;
	}
}



function selectLinkCB(component,width,height,opt,loc) {
	var warn = "This resource is incorrectly linked. Please contact the site administrator."
	var maximum = "false";
	if(isNaN(component)) {
		if(component.indexOf("://") != -1||component.indexOf("/forms") != -1) {
			if(component.indexOf("/forms") != -1) {
				component="http://www.ingvfc.com"+component;
			}
			var targ = "winSite"
		} else if (component == "null") { 
			return false;
		} else {
			alert(warn);
			return false; 
		}
	} else {
		var targ = "win"+ component;
		component = "/ComponentProxy?c="+component;
	}

	if(!width  || width==null || width=="") width="640";
	if(!height || height==null || height=="") height="480";
	if(!opt) opt="menubar,status,resizable,scrollbars";
	
	if(isNaN(width)) {
		if(width != "max") {
			alert(warn);
			return false; 
		} else {
			width = screen.availWidth;
			maximum = true;
		}
	}

	if(isNaN(height)) {
		if(height != "max") {
			alert(warn);
			return false; 
		} else {
			height = screen.availHeight;
			maximum = true;
		}
	}  
	
	var features = "width="+width+",height="+height+ ","+opt;
	var popup;

	if(!loc) {
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
	} else if(isNaN(loc)) {
		alert(warn);
		return false;
	} else {
		loc = "/ComponentProxy?c="+loc;
		if(maximum != "false" && targ=="winSite"){
			var targWin = eval(window.open('',targ,features));
			popUp = void(targWin);
			targWin.moveTo(0,0);
			targWin.location = component;
		} else {
			var targWin = eval(window.open(component,targ,features));
			popUp = void(targWin);
		}
		window.location = loc;
	}
}








/**********************************************************************************
The function "loadData" is used to open Zacks Securities Research options in a 
targeted window from the "onChange" event handler of a dropdown <SELECT> list.
The variables in this function are specifically mapped to form objects in Component
46022 (Zack's Securities Research Top Navigation).

The argument is:
- form: Set to "this" in Component #46022. Corresponds specifically to the form
		"form1" in Component #46022.
		
An alert dialog box will appear if the form is submitted with no option selected 
from the dropdown list OR with no ticker symbol entered into the text input.
***********************************************************************************/
function loadData(form) {
	var ticker = form.tick.value;
	var index=form.select.selectedIndex;
	var which = form.select.options[index].value;
	form.t.value = "";
	form.d.value = "";
	if(ticker!=""){
		if(which!="null") {
			if(which.indexOf("r[]") != -1) {
				form.t.value = form.tick.value;
				form.d.value = "INGnew";
			} else {
				form.t.value = "ing_new";
				form.d.value = "2,1";
			}
			form.action = which;
			return true;
		} else {
			alert("Please select an option from the list.");
			return false;
			form.company.value = ticker;
		}
	} else {
		alert("Please enter a ticker symbol to continue.");
		return false;		
	}
}

/**********************************************************************************
The functions "addFile" and "fill" are used to create an array of arrays (addFile) 
and dynamically populate a <SELECT> list (fill) from the multidimensional array. 
Both functions rely on the global variable "cat" to represent the multidimensional 
array that "addFile" will populate. The "addFile" function MUST be called from 
within the individual components to populate the "cat" array. Each call to "addFile"
creates an array entry that corresponds to an option in the <SELECT> list populated
with the "fill" function. 
Example: addFile("january_02","Jan. 30: Defense Factor II","46146");
NOTE: This example assumes that the form is using the standard "selectLink" function
to link to a component from an onChange event handler.

addFile's arguments are:
- whichCat: This value is used as a key to determine which items in the "cat" array
			to populate the targeted <SELECT> list options.
- title: The option text to be displayed in the targeted <SELECT> list for an individual
			option listing.
- src: The option value assigned to the individual option in the targeted <SELECT> list.
		This should be the component ID of a resource to be linked to. A value of "null"
		will prevent the onChange event from working.

fill's arguments are:
- form: The name of the form which contains the <SELECT> list to be populated.
- list: The name of the <SELECT> list to be populated with items from the "cat" array.
- which: The key that corresponds to the "whichCat" value of specific items in the "cat"
	array. This determines which array objects will be used to populate the <SELECT>
	list.
***********************************************************************************/
var cat = new Array();
	
function addFile(whichCat, title, src) {
	n = cat.length;
	cat[n] = new Array
	cat[n][0] = whichCat;
	cat[n][1] = title;
	cat[n][2] = src;
}
	
function fill(form, list, which) {
	var coll = 0;
	for(i=0; i<cat.length; i++) {
		if (cat[i][0] == which.toLowerCase()){
			coll++;
			eval("document."+form+"."+list+".options.length = "+coll);
			var curr = coll-1
			var targ = eval("document."+form+"."+list+".options["+curr+"]");
			targ.text = cat[i][1];
			targ.value = cat[i][2];
		}
	}
}























/**************************************************************************************
The function showMsg is used to dynamically write text to the page (msg) for a specified
period of time (until).
 
The arguments are:
- msg: A string value
- until: A JS Date value that must appear in the format "DD Month YYYY" to be correctly 
		parsed as a GMT Date string.
		
Both arguments must be quoted in the function call. Care should be taken when using 
quotation marks in the "msg" string.
***************************************************************************************/
function showMsg(msg,until) {
	NowDate = new Date();
	retDate = new Date(until);
	retDate.setYear = NowDate.getFullYear;
	day = (1000*60*60*24);
	computeDay= (retDate.getTime() - NowDate.getTime()) / day;
	CDRET = Math.round (computeDay);
	if(CDRET >= 0){
		document.write(msg);
	} 
}





