var firstclick = true;
var checkednum = 0;
var checks = new Array()

function setCookie(name, value, expires, path, domain, secure)
{ var curCookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
  document.cookie=curCookie;
}

function setorder() {
  var cool=new Array()
  cool[0] = document.coolsetform.coolname.value;
	if (document.coolsetform.checkedlist.length > 0) {
		cool[1] = document.coolsetform.checkedlist.options[0].value
	}
	if (document.coolsetform.checkedlist.length > 1) {
		cool[2] = document.coolsetform.checkedlist.options[1].value
	}
	if (document.coolsetform.checkedlist.length >2) {		
		cool[3] = document.coolsetform.checkedlist.options[2].value	
	}
	if (document.coolsetform.checkedlist.length >3) {		
		cool[4] = document.coolsetform.checkedlist.options[3].value	
	}
	if (document.coolsetform.checkedlist.length >4) {		
		cool[5] = document.coolsetform.checkedlist.options[4].value	
	}
  var test=cool.join();
  var the_end = new Date("July 17, 2010");
  setCookie("cool",test,the_end);
}

function subtractfromchecked(name) {
	if (name == document.coolsetform.checkedlist.options[0].value) 
		document.coolsetform.checkedlist.options[0] = null
	else if (name == document.coolsetform.checkedlist.options[1].value)
		document.coolsetform.checkedlist.options[1] = null
	else if (name == document.coolsetform.checkedlist.options[2].value)
		document.coolsetform.checkedlist.options[2] = null
	else if (name == document.coolsetform.checkedlist.options[3].value)
		document.coolsetform.checkedlist.options[3] = null	
	else if (name == document.coolsetform.checkedlist.options[4].value)
		document.coolsetform.checkedlist.options[4] = null	
}

function addtochecked(checkboxname, checkedtitle, checkednum) {
//alert (document.coolsetform.checkedlist.length)

	if (document.coolsetform.checkedlist.length == 1) {
		if (document.coolsetform.checkedlist.options[0].value=="one") {
			document.coolsetform.checkedlist.options[0] = null
		}
	}	
	if (document.coolsetform.checkedlist.length <5) {
		var oOption = new Option(checkedtitle, checkboxname);
		var ind = 0;
		if (document.coolsetform.checkedlist.length > 0) {
			ind = document.coolsetform.checkedlist.length;
		}
		eval("document.coolsetform.checkedlist[ind] = oOption");
	}
	else if (checkednum == 1) {
		document.coolsetform.checkedlist.options[0].value = checkboxname;	
		document.coolsetform.checkedlist.options[0].text = checkedtitle;		
	}
	else if (checkednum == 2) {
		document.coolsetform.checkedlist.options[1].value = checkboxname;
		document.coolsetform.checkedlist.options[1].text = checkedtitle;
	}
	else if (checkednum == 3) {
		document.coolsetform.checkedlist.options[2].value = checkboxname;
		document.coolsetform.checkedlist.options[2].text = checkedtitle;
	}
	else if (checkednum == 4) {
		document.coolsetform.checkedlist.options[3].value = checkboxname;
		document.coolsetform.checkedlist.options[3].text = checkedtitle;
	}
	else if (checkednum == 5) {
		document.coolsetform.checkedlist.options[4].value = checkboxname;
		document.coolsetform.checkedlist.options[4].text = checkedtitle;
	}
//Test	
document.coolsetform.checkedlist.options[0].selected = true; 
}

function moveup() {
	if (document.coolsetform.checkedlist.selectedIndex>0) {
		var i = document.coolsetform.checkedlist.selectedIndex;
		name= document.coolsetform.checkedlist.options[i-1].value 
		chtext = document.coolsetform.checkedlist.options[i-1].text
		document.coolsetform.checkedlist.options[i-1].value  = document.coolsetform.checkedlist.options[i].value
		document.coolsetform.checkedlist.options[i-1].text = document.coolsetform.checkedlist.options[i].text
		document.coolsetform.checkedlist.options[i].value = name
		document.coolsetform.checkedlist.options[i].text = chtext
		document.coolsetform.checkedlist.selectedIndex = i-1
	}
}

function movedown() {
  if (document.coolsetform.checkedlist.selectedIndex>=0) {
	if (document.coolsetform.checkedlist.length>document.coolsetform.checkedlist.selectedIndex+1) {
		var i = document.coolsetform.checkedlist.selectedIndex;
		name= document.coolsetform.checkedlist.options[i].value 
		chtext = document.coolsetform.checkedlist.options[i].text
		document.coolsetform.checkedlist.options[i].value  = document.coolsetform.checkedlist.options[i+1].value
		document.coolsetform.checkedlist.options[i].text = document.coolsetform.checkedlist.options[i+1].text
		document.coolsetform.checkedlist.options[i+1].value = name
		document.coolsetform.checkedlist.options[i+1].text = chtext
		document.coolsetform.checkedlist.selectedIndex = i+1
	}
  }
}

function Options(checkboxname) {
	if (firstclick == true) {
		firstclick = false;
		var i = document.coolsetform.CheckedCustomItems.value;
		i = i-1
		checkednum = i+1;
	}
	if (checkboxname.checked) {
		if (checkednum < 5) {
			checkednum=checkednum+1;
			name = checkboxname.name.toUpperCase();			//Uppercase 
	//alert (name)
			if (name == COOLstr1) {
				chtitle = COOLstring1;
			}
			else if (name == COOLstr2) {
				chtitle = COOLstring2;
			}
			else if (name == COOLstr3) {
				chtitle = COOLstring3;
			}
			else if (name == COOLstr4) {
				chtitle = COOLstring4;
			}
			else if (name == COOLstr5) {
				chtitle = COOLstring5;
			}
			else if (name == COOLstr6) {
				chtitle = COOLstring6;
			}
			else if (name == COOLstr7) {
				chtitle = COOLstring7;
			}
			else if (name == COOLstr8) {
				chtitle = COOLstring8;
			}
			
			addtochecked(name, chtitle,  checkednum);
			
		} else {
			alert("You may select only 5 options");
			checkboxname.checked=!checkboxname.checked;
		}
	} else {
		checkednum=checkednum-1;
		name = checkboxname.name.toUpperCase();		// Convert to UCase.
		chtitle =  checkboxname.title;
		subtractfromchecked(name);
	}
}

function findbox(name) {
	if (name == COOLstr1) {
		checks[1] = true;
	}
	else if (name == COOLstr2) {
		checks[2] = true;
	}
	else if (name == COOLstr3) {
		checks[3] = true;
	}
	else if (name == COOLstr4) {
		checks[4] = true;
	}
	else if (name == COOLstr5) {
		checks[5] = true;
	}
	else if (name == COOLstr6) {
		checks[6] = true;
	}
	else if (name == COOLstr7) {
		checks[7] = true;
	}
	else if (name == COOLstr8) {
		checks[8] = true;
	}
return checks;
}

