
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);



function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function radio_button_checker()
{

var radio_choice = false;

for (counter = 0; counter < radio_form.radio_button.length; counter++)
{
if (radio_form.radio_button[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("Please select a letter.")
return (false);
}
return (true);
}



function submitForm(frm)
{
    frm.submit() ;
}


function move(Sel,bDir) {
  
  var idx = Sel.selectedIndex
  if (idx==-1) 
    alert("You must first select the item to reorder.")
  else {
    var nxidx = idx+( bDir? -1 : 1)
    if (nxidx<0) nxidx=Sel.length-1
    if (nxidx>=Sel.length) nxidx=0
    var oldVal = Sel[idx].value
    var oldText = Sel[idx].text
    Sel[idx].value = Sel[nxidx].value
    Sel[idx].text = Sel[nxidx].text
    Sel[nxidx].value = oldVal
    Sel[nxidx].text = oldText
    Sel.selectedIndex = nxidx
  }
}




function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      selectedCount++;
    }
  }
  deleteOption(theSelFrom);
  
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}


function isNewOption(theSel, theValue)
{
 var selLength = theSel.length;		
 for(i=selLength-1; i>=0; i--)
 {
	if ( theSel.options[i].value ==  theValue ) return false;
 } 
 return true;
}


function addOption(theSel, theText, theValue)
{
	// if it is a new one in case non zero values
	if( isNewOption(theSel, theValue) ||  theValue == "0"  )
	{
		var newOpt = new Option(theText, theValue);
		var selLength = theSel.length;
		theSel.options[selLength] = newOpt;
		theSel.size = theSel.length;
		return true;
	}
	else
	{
		alert("Duplicate entry..!");
		return false;
	};	
	return false;
}


function deleteOption(theSel)
{ 
  
  var selLength = theSel.length;
  
  var i;
  
  if(selLength>0)
  {
	
	for(i=selLength-1; i>=0; i--)
	{
	    if(theSel.options[i].selected)
	    {
			theSel.options[i] = null;
			theSel.size = theSel.length;
		
		}
	}
  }
}

function emptyField(textObj)
{
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; ++i)  {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;
	}
	return true;
}




function TrackCount(fieldObj,countFieldName,maxChars)
{
	var countField = eval("fieldObj.form."+countFieldName);
	var diff = maxChars - fieldObj.value.length;
	// Need to check & enforce limit here also in case user pastes data
	if (diff < 0)
	{
		fieldObj.value = fieldObj.value.substring(0,maxChars);
		diff = maxChars - fieldObj.value.length;
	}
	countField.value = diff;
}

function LimitText(fieldObj,maxChars)
{
	var result = true;
	if (fieldObj.value.length >= maxChars)
	result = false;
	if (window.event)
	window.event.returnValue = result;
	return result;
}
					
function pic_change(pic_source,img_place)
{
	var s=pic_source.options.selectedIndex;
	if (pic_source.options[s].value=='n/a')
	{
		img_place.src = '';
		img_place.src = '../../images/pixel.gif';
	}
	else
	{
		img_place.src = '';
		img_place.src = '../../packages/images/' + pic_source.options[s].value;
	}
}
	
				
function getYear(d)
{ 
	return (d < 1000) ? d + 2000 : d;
}

function isDate (day, month, year)
{
	// month argument must be in the range 1 - 12
	month = month - 1;  // javascript month range : 0- 11
	var tempDate = new Date(year,month,day);
	year = getYear(year);
	//alert (year);
	//alert(day+month+year);
	//alert(tempDate);
	if ( (getYear(tempDate.getYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
	{	
		return true;
	}	
	else
	{
		return false
	}
}


function LessThanMin(textObj, min)
{
	var count=0;
	if (textObj.value.length < min) return true;
	for (var i=0; i<textObj.value.length; ++i)
	{
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') count++;
	}
	if (count<min) return true;
	return false;
}

function notEqual(textObj,textObj1)
{
	if (textObj.value != textObj1.value) return true;
	return false;
}


function validateform(frm)
{
if( checkEmptyText   ('AdminUserName', 'Enter UserName..!' ) ) return false;
if( checkEmptyText   ('AdminPassword', 'Enter Password..!' ) ) return false;
return true;
}

function change(combo,s)
 {
   var jobstr=combo.options[combo.selectedIndex].value;
	if (jobstr=='modify') document.getElementById(s).style.display = '';
	if (jobstr=='delete') document.getElementById(s).style.display = 'none';
}


function checkEmptyText(textName,ErrMsg)
{
	textObj =  document.getElementById(textName);
	if (emptyField(textObj))
	{
		alert(ErrMsg);
		textObj.focus();
		return true;						
	}
	return false;
}

function checkNumericText(textName,ErrMsg)
{	
    textObj =  document.getElementById(textName);
 	if (isNaN(textObj.value))
	{
		alert(ErrMsg);
		textObj.focus();
		return true;
	}
	return false;
}


function checkEqual(textName1,textName2,ErrMsg)
{	
    textObj1 =  document.getElementById(textName1);
    textObj2 =  document.getElementById(textName2);
 	if (textObj1.value == textObj2.value )
	{
		alert(ErrMsg);
		textObj2.focus();
		return true;
	}
	return false;
}



function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

function checkEmail(textName,ErrMsg)
{	
    textObj =  document.getElementById(textName);
 	if (!isValidEmail(textObj.value))
	{
		alert(ErrMsg);
		textObj.focus();
		return true;
	}
	return false;
}
