/******************************************************
	Date Created: 10-Oct-2008
	Created By: Pravin kucha
	Purpose of this (page/form/module): This page is used for the javascript funtion.
	Last Modified: 
	Modified By: Pravin kucha
******************************************************/
/* Read Only Function*/
var baseurl='http://www.bradmin.dwt';
function make_readonly()
{
	alert("Please Use Browse Button");
	return false;
}//End of Function

/* Checks for blank text boxes*/
function checkBlank(ctl,msgName)
{
	if(Trim(ctl.value)=="")	
    {
		alert(''+msgName+'' + "cannot be blank");
		ctl.focus();
		return (false);
    }
}//End of Function

/* Checks for unselected select boxes*/
function checkSelect(ctl,msgName)
{
	if(ctl.selectedIndex<=0)	
    {
		alert('Please select '+msgName);
		ctl.focus();
		return (false);
    }
	else
    {
    	return (true);
    }
}//End of Function

/* Checks for the entered email id is in a proper format*/
function ValidateEmail(ctl)
{
	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) 
	{
		error = 1;
		alert("Email address is not formatted properly.");
		ctl.focus();
		return (false);
	}
}
function checkEmail(ctl)
{
	var id=ctl;
	var str=id.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else
	{
		alert("Email address is not formatted properly.");
		ctl.focus();
		testresults=false
	}
	return (testresults)
}//End of Function

/* Checks for password entered is same or not*/
function confirmPassword(ctl1,ctl2)
{
	if(ctl1.value != ctl2.value)
	{
   		alert("Password and confirm password must be same");
   		ctl1.focus();
   		return(false);
   }
}//End of Function

/* Function to validate the radio button*/
function radio_validate(formObj) 
{
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) 
	{
		currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) 
		{
            isOK=true;
			break;
        }
    }
    
	if (!isOK) 
		alert("You need to select a option !");
    return isOK;
}//End of Function
function checkURL(ctl,msgName) 
{
	var value = ctl.value;
	var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
	if(!urlregex.test(value))
	{
		alert(''+msgName+'' + "cannot be valid ");
		ctl.focus();
		return (false);
	}
	return(true);
}

/* Function to remove the leading and trailing spaces*/
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//End of Function

/* Funtion for Numbers Only and Disables all other key*/
function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
		//unicode!=8;
	if (unicode!=9)
	{ //if the key isn't the backspace key (which we should allow)
		if ((unicode<48||unicode>57) && unicode != 46 && unicode != 8) //if not a number
		return false //disable key press
	}
}//End of Function

/* Function moves the cursor from one text box to another after 3 characters*/
function valuedata(data,movedata)
{ 
	if(data.length == 3)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function
 
/* Function moves the cursor from one text box to another after 2 characters*/
function valuedata1(data,movedata)
{
	if(data.length == 2)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function

/* Funtion for Characters Only and Disables all other key*/
function alphaCharacters(event)
{
	/********
	FOR IE
	*********/
	if(document.all)
	{
		if(event.keyCode>=65 && event.keyCode<=90)
		{
			return true;
		}
		else if(event.keyCode>=97 && event.keyCode<=122)
		{
			return true;
		}
		else if(event.keyCode==32)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/************************************
	OTHER BROWSER LIKE FIREFOX,NETSCAPE
	*************************************/
	if ((!document.all )&& (document.getElementById)) 
	{
		if(event.which>=65 && event.which<=90)
		{
			return true;
		}
		else if(event.which>=97 && event.which<=122)
		{
			return true;
		}
		else if(event.which==32)
		{
			return true;
		}
		else if(event.which==0 || event.which==8)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}//End of Function

function checkUncheckAll(theElement)
{
		
     var theForm = theElement.form, z = 0;

	 for(z=0; z<theForm.length;z++)
	 {
		 	
     	 if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
	  	 {
	  		theForm[z].checked = theElement.checked;
	  	 }
     }
}

//function for check file extension.

function checkValidFileName(cntID)
   {
        var value =  document.getElementById(cntID).value; 
	if(value!="")
	{
         value=value.toLowerCase();
         if((value.lastIndexOf(".jpg") == -1 ) && (value.lastIndexOf(".gif") == -1 ))
          {
				
     		alert("Select .JPG or .GIF file");
	        return false; 
           }
	}
	else
	{
		return true;
	}
     
     }

// JScript File Listbox handling.
function moveItem(inFromBox, inToBox)
{
   var selectedValue = "";
   var selectedName = "";
   for(i = 0; i < inFromBox.length; i ++ )
   {
      
      if(inFromBox[i].selected == true  )
      {
         var TOLength = inToBox.length
         inToBox[inToBox.length] = new Option(inFromBox[i].text, inFromBox[i].value);
      }
   }
   for(i = inFromBox.options.length - 1; i >= 0; i -- )
   {
      if(inFromBox.options[i].selected)
      inFromBox.remove(i);
   }

}
function moveall(inFromBox, inToBox)
{
   j = inToBox.length  ;
   for(i = 0; i < inFromBox.length; i ++ )
   {
      inToBox[j] = new Option(inFromBox[i].text, inFromBox[i].value);
      inToBox.options[j].style.backgroundColor = inFromBox.options[i].style.backgroundColor;
      j = j + 1;
   }
   inFromBox.length = 0 ;
}
function selectALL(ID)
{
	
   var inFromBox = document.getElementById(ID);
   for(i = 0; i < inFromBox.length; i ++ )
   inFromBox[i].selected = true
}
function selectAlldrp(ID)
{
alert("hi");
   inFromBox = document.getElementById(ID)
   for(i = 0; i < inFromBox.length; i ++ )
   inFromBox[i].selected = true;
}
function moveUpList(listField) {
listField = document.getElementById(listField);
   if ( listField.length == -1) {  // If the list is empty
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == 0 ) {
            } else {
               // Get the text/value of the one directly above the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected-1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected-1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected-1].text = moveText2;
               listField[selected-1].value = moveValue2;
               listField.selectedIndex = selected-1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

function moveDownList(listField) {
listField = document.getElementById(listField);
   if ( listField.length == -1) {  // If the list is empty
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == listField.length-1 ) {
            } else {
               // Get the text/value of the one directly below the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected+1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected+1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected+1].text = moveText2;
               listField[selected+1].value = moveValue2;
               listField.selectedIndex = selected+1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

