sortitems = 1;  // Automatically sort items within lists? (1 or 0)

//*************************************************************
//description:		move information from listbox1 to listbox2
//*************************************************************
function move(fbox,tbox) 
{
	for(var i=0; i<fbox.options.length; i++) 
	{
		if(fbox.options[i].selected && fbox.options[i].value != "") 
		{
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		}
	}
	BumpUp(fbox);
	if (sortitems) SortD(tbox);
}

//*************************************************************
//description:		
//*************************************************************
function BumpUp(box)  
{
	for(var i=0; i<box.options.length; i++) 
	{
		if(box.options[i].value == "")  
		{
			for(var j=i; j<box.options.length-1; j++)  
			{
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
		var ln = i;
		break;
		}
	}
	
	if(ln < box.options.length)  
	{
		box.options.length -= 1;
		BumpUp(box);
	}
}

//*************************************************************
//description:		
//*************************************************************
function SortD(box)  
{
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++)  
	{temp_opts[i] = box.options[i];}
	
	for(var x=0; x<temp_opts.length-1; x++)  
	{
		for(var y=(x+1); y<temp_opts.length; y++)  
		{
			if(temp_opts[x].text > temp_opts[y].text)  
			{
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
				temp = temp_opts[x].value;
				temp_opts[x].value = temp_opts[y].value;
				temp_opts[y].value = temp;
			}
		}
	}
	
	for(var i=0; i<box.options.length; i++)  
	{
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
	}
}
		
//*************************************************************
//description:		
//*************************************************************
function selectAll(cboName)
{	
	for(var i=0;i < cboName.options.length; i++)
	{cboName.options[i].selected=true;}
}

//*************************************************************
//description:		
//*************************************************************
function finishExam()
{Form1.Finish.value=1;}

//*************************************************************
//description:		
//*************************************************************
function confirmDeleteQuestion(strURL)
{
	strMessage = "Click 'OK' to Delete the Question or click 'Cancel' to escape."
	if (confirm(strMessage))
	{location.href= strURL} 
}

//*************************************************************
//description:		
//*************************************************************
function Back(UserID)
{location.href="menu.asp?UserID=" + UserID;}

//*************************************************************
//description: TextField Validation
//*************************************************************
function isBlank(value, ErrorMessage)
{
	if (value.length > 0)
	{return "";}
	else
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
}

//*************************************************************
//description: check between min - max length with alphanumeric only
//*************************************************************
function AlphaNumeric(value, minLength, maxLength, ErrorMessageLngth, ErrorMessageAlphaNumeric)
{
	var AlphaNumericPat = /[^a-zA-Z0-9]/;
	var matchArray = value.match(AlphaNumericPat); // is the format ok?
	
	if ((value.length < minLength) || (value.length > maxLength))
	{return ErrorMessageLngth = "*" + ErrorMessageLngth + "\n";} //not 6-10 char
	else
	{
		if (matchArray != null) //alphanumeric char
		{return ErrorMessageAlphaNumeric = "*" + ErrorMessageAlphaNumeric + "\n";}
		else
		{return "";}
	}
}

//*************************************************************
//description: ComboBox Validation
//*************************************************************
function isBlankCbo(value, ErrorMessage)
{
	if (value.length<=0)
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	else
	{return "";}
}

//*************************************************************
//description: DropDownList Validation
//*************************************************************
function isBlankDdl(value, index, ErrorMessage)
{
	if (value.selectedIndex == index)
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	else
	{return "";}
}

//*************************************************************
//description: Radio button Validation
//muliple list of radio buttons for the exams app
//*************************************************************
function isRadioChecked(radio, ErrorMessage)
{
	var checked = false;
	var j;
	for (j=0; j<radio.length; j++)
	{
		if (radio[j].checked == true)
		{
			checked = true;
			break;
		}
	}
	if (!checked)
	{
		if (ErrorMessage != "")
		{return ErrorMessage = ErrorMessage + ", ";}
		else
		{return ErrorMessage = ErrorMessage;}
	}
	else
	{return "";}
}

//*************************************************************
//description: Radio button Validation
//*************************************************************
function isRadioCheck(radio, ErrorMessage)
{
	var checked = false;
	var j;
	for (j=0; j<radio.length; j++)
	{
		if (radio[j].checked == true)
		{
			checked = true;
			break;
		}
	}
	if (!checked)
	{
		if (ErrorMessage != "")
		{return ErrorMessage = "*" + ErrorMessage + "\n";}
		else
		{return ErrorMessage = ErrorMessage;}
	}
	else
	{return "";}
}

//*************************************************************
//description: check box validation
//*************************************************************
function isCheckBoxCheck(checkbox)
{
	if (checkbox.checked)
	{return true;}
	else
	{return false;}
	
}

//*************************************************************
//description:	validate email address
//*************************************************************
function isEmail(value, ErrorMessage)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))
	{return "";}
	else
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
}

//*************************************************************
//description:	validate zip code
//*************************************************************
function isZipCode(value, ErrorMessage)
{
	var valid = "0123456789-";
	var hyphencount = 0;

	if (value.length!=5 && value.length!=10) 
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	for (var i=0; i < value.length; i++) 
	{
		temp = "" + value.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") 
		{return ErrorMessage = "*" + ErrorMessage + "\n";}
		if ((hyphencount > 1) || ((value.length==10) && ""+value.charAt(5)!="-")) 
		{return ErrorMessage = "*" + ErrorMessage + "\n";}
	}
	return "";
}

//*************************************************************
//description:	validate phone number
//*************************************************************
function isPhoneNumber(value, ErrorMessage)
{ 
	var rep = /(^\s*)|(\s*$)/g;
	var first = value.substring(0,3).replace(rep, "");
	var second = value.substring(4,7).replace(rep, "");
	var third = value.substring(8,12).replace(rep, "");
	
	if (value.length != 12 || first.length != 3 || second.length != 3 || third.length != 4)
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	if (isNaN(first) || isNaN(second) || isNaN(third))
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	if ((value.substring(3,4) != "-") || (value.substring(7,8) != "-"))
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	
	return "";
}

//*************************************************************
//description:	Date Validation
//*************************************************************
function isDate(value, ErrorMessage) 
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = value.match(datePat); // is the format ok?
	var month;
	var day;
	var year;
	
    if (matchArray == null) 
    {return ErrorMessage = "*" + ErrorMessage + "\n";}

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if (month < 1 || month > 12) //check month
    {return ErrorMessage = "*" + ErrorMessage + "\n";}

    if (day < 1 || day > 31) //check days
    {return ErrorMessage = "*" + ErrorMessage + "\n";}

    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
    {return ErrorMessage = "*" + ErrorMessage + "\n";}

    if (month == 2) 
    { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) 
        {return ErrorMessage = "*" + ErrorMessage + "\n";}
    }
    return ""; // date is valid
}

//*************************************************************
//description:	validate number with specific length
//*************************************************************
function isNumber(value, intLength, ErrorMessage)
{
	if (isNaN(value))
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	if (value.length != intLength)
	{return ErrorMessage = "*" + ErrorMessage + "\n";}
	return "";
}

//*************************************************************
//description:	submit form to specified url
//*************************************************************
function SubmitUrl(url)
{
	document.Form1.action = url;
	document.Form1.submit();
}
//*************************************************************
//description:	open new window without address bar
//*************************************************************
function openClient(strURL)
{
	var i= window.open(strURL,"_blank", "height=480,width=640,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=1,z-lock=0","myWinApplication1");
	var x= (window.screen.width / 2)-320;	
	var y= (window.screen.Height / 2)- 240;	
	i.moveTo(x,y);
}
//*************************************************************
//description:	open new browser window
//*************************************************************
function openWindow(strURL)
{
	var i= window.open(strURL,"_blank", "height=480,width=640,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,z-lock=0","myWinApplication1");
	var x= (window.screen.width / 2)-320;	
	var y= (window.screen.Height / 2)- 240;	
	i.moveTo(x,y);
}
