
/*
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><SCRIPT LANGUAGE=JavaScript>
*/

//**********************************************************************************
//       Check wether only the characters specified are there in the string
// Accepts the string and the character to be checked (it is a string)
//                                        A     -> for all alphabets (no case specification)
//                                        N     -> for all numbers
//                                        a - z     -> for all the lower case chars
//                                        other just specify it
//**********************************************************************************
function func_check_enter(ent,obj_form,val_func){
	if(ent.keyCode==13){
	    if (val_func != "" ){
		    if (eval(val_func)){
		 		obj_form.submit();	
			}
		}
		else{
		 		obj_form.submit();	
		}
	}
}
function checkAllowedChars(strToCheck, allowedChars)
{
     var acLen     = allowedChars.length;
     var stcLen     = strToCheck.length;
     strToCheck     = strToCheck.toLowerCase();
     var i;
     var j;
     var rightCount = 0;
     for(i = 0; i < acLen; i++)
     {
          switch(allowedChars.charAt(i))
          {
          case 'A':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z';
               }
               break;
          case 'N':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9';
               }
               break;
          default:
               for(j = -1; -1 != (j = strToCheck.indexOf(allowedChars.charAt(i), j+1)); rightCount++);
               break;
          }
     }
     if(rightCount == stcLen)
     {
          return true;
     }
     return false;
}

//**********************************************************************************
//       Check wether the characters specified are not there in the string
// Accepts the string and the character to be checked (it is a string)
//                                        A     -> for all alphabets (no case specification)
//                                        N     -> for all numbers
//                                        a - z     -> for all the lower case chars
//                                        other just specify it
//**********************************************************************************
function checkNotAllowedChars(strToCheck, unAllowedChars)
{
     var acLen     = unAllowedChars.length;
     var stcLen     = strToCheck.length;
     strToCheck     = strToCheck.toLowerCase();
     var i;
     var j;
     var rightCount = 0;
     for(i = 0; i < acLen; i++)
     {
          switch(unAllowedChars.charAt(i))
          {
          case 'A':
               for(j = 0; j< stcLen; j++)
               {
                    if(strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z')
                    {
                         return false;
                    }
               }
               break;

          case 'N':
               for(j = 0; j< stcLen; j++)
               {
                    if(strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9')
                    {
                         return false;
                    }
               }
               break;

          default:
               if(strToCheck.indexOf(unAllowedChars.charAt(i)) != -1)
               {
                    return false;
               }
               break;
          }
     }
     return true;
}

function trimSpace(frmElement)
{
     var stringToTrim = eval(frmElement).value;
     var len = stringToTrim.length;
     var front;
     var back;
     for(front = 0; front < len && (stringToTrim.charAt(front) == ' ' || stringToTrim.charAt(front) == '\n' || stringToTrim.charAt(front) == '\r' || stringToTrim.charAt(front) == '\t'); front++);
     for(back = len; back > 0 && back > front && (stringToTrim.charAt(back - 1) == ' ' || stringToTrim.charAt(back - 1) == '\n' || stringToTrim.charAt(back - 1) == '\r' || stringToTrim.charAt(back - 1) == '\t'); back--);

     frmElement.value = stringToTrim.substring(front, back);
}

function noChkBoxSelected(frmElement)
{
     var i;
     if(frmElement[1])
     {
          var len = frmElement.length;
          for(i = 0; i < len; i++)
               if(frmElement[i].checked)
                    break;

          if(i < len)
               return false;
          else
               return true;
     }
     else
          return !(frmElement.checked);
}

function findSelectedButton(btns)
{
     if(!btns[1])
          return btns.checked? 0: -1;

     for(i = 0; i < btns.length; i++)
     {
          if(btns[i].checked)
               return i;
     }

     return -1;
}

function setButton(btns, idx, val)
{
     idx = parseInt(idx, 10);
     if(!isNaN(idx))
          if(!btns[1])
               btns.checked = val;
          else
               btns[idx].checked = val;
}

function checkRedundantValues(frmElement)
{
     if(frmElement[1])
     {
          var cpy = new Array();
          for(i = 0; i < (frmElement.length - 1); i++)
               if(frmElement[i].value != '')
                    for(j = i+1; j < frmElement.length; j++)
                         if(frmElement[i].value == frmElement[j].value)
                              cpy[cpy.length] = i;
          if(cpy.length)
               return cpy;
     }
     return null;
}

//**********************************************************************************//
//                      Counts the Number of Occurance of a character                    //
// Accepts the string and the character                                                            //
//**********************************************************************************//
function countOccurance(str, charecter)
{
     var j;
     var count;
     for(j = -1, count = 0; -1 != (j = str.indexOf(charecter, j+1)); count++);
     return count;
}

function checkEmail(email, mandatory)
{
     if(mandatory && !(email.length))
          return false;

     if(!(email.length))
          return true;

     if(!(checkAllowedChars(email, 'AN@-_.<>')
          && countOccurance(email, '@') == 1
          && email.indexOf('@') != 0
          && email.lastIndexOf('@') != (email.length - 1)
          && countOccurance(email, '<') <= 1
          && countOccurance(email, '>') <= 1
          && ((email.lastIndexOf('>') == (email.length - 1) && email.indexOf('<') != -1)
               || (email.indexOf('>') == -1 && email.indexOf('<') == -1))
          && countOccurance(email, '.') >= 1
          && email.indexOf('..') == -1
          && email.indexOf('.') != 0
          && email.lastIndexOf('.') != (email.length - 1)))
     {
          return false;
     }

     afterAt = email.substring(email.indexOf('@')+1);
     if(!(afterAt.indexOf('.') != 0 && afterAt.lastIndexOf('.') != (afterAt.length - 1)))
          return false;

     beforeAt = email.substring(0, email.indexOf('@'));
     if(!(beforeAt.indexOf('_') != 0
      && beforeAt.indexOf('-') != 0
      && beforeAt.indexOf('.') != 0
      && beforeAt.lastIndexOf('.') != (beforeAt.length - 1)))
     {
          return false;
     }
     return true;
}

/*
 * checkDateString(dateString, dateFormat, seperator)
 *
 * dateString     (string)     The string that is to validated.
 * dateFormat     (string)     The format in which the date is expected to be present in dateString. {dmy for ddmmyyyy, ymd for yyyymmdd}
 * seperator     (string)     The seperator that seperates the day, month & year from each other. Its possible values are - and /
 *
 * Returns Value:
 *  true if the date that you give is correct. Else it returns false.
 */

function checkDateString(dateString, dateFormat, seperator)
{
     var dmy = new Array();
     var day, month, year;

     dateFormat.toLowerCase();
     if(!checkAllowedChars(dateFormat, 'dmy'))
     {
          alert('checkDateString: Function usage error.\n\nInvalid date format.');
          return false;
     }

     if(seperator.length != 1 || (!checkAllowedChars(seperator, '/-')))
     {
          alert('checkDateString: Function usage error.\n\nInvalid seperator.');
          return false;
     }


     if(!checkAllowedChars(dateString, 'N' + seperator))
          return false;

     dmy = dateString.split(seperator);
     if(dmy.length == 3)
     {
          i = 0;
          while(dateFormat.length > 0)
          {
               fmtLen = countOccurance(dateFormat, dateFormat.charAt(0));

               switch(dateFormat.charAt(0))
               {
               case 'd':
                    day = dmy[i];
                    break

               case 'm':
                    month = dmy[i];
                    break

               case 'y':
                    year = dmy[i];
                    break
               }
               dateFormat = dateFormat.substring(fmtLen);
               i++;
          }

          if(!(day.length > 0 && month.length > 0 && year.length > 0))
               return false;

          return _checkDate(day, month, year);
     }
     return false;
}
/*
 * checkDate(day, month, year)
 *
 * As you expect day, month and year are the strings that contains the corresponding values.
 *
 * Returns Value:
 *  true if the date that you give is correct. Else it returns false.
 */

function checkDate(day, month, year)
{
     if(!checkAllowedChars(day + month + year, 'N'))
          return false;

     if((day.length <= 0) || (month.length <= 0) || (year.length <= 0))
          return false;

     return _checkDate(day, month, year);
}

function _checkDate(day, month, year)
{
     year *= 1;
     if(year <= 0)
          return false;

     month *= 1;
     if(!((month > 0) && (month < 13)))
          return false;

     var daysInMonth = new Array();
     daysInMonth[ 0] = 31;                         //Jan
     daysInMonth[ 1] = isLeap(year) == true? 29: 28;     //Feb
     daysInMonth[ 2] = 31;                         //Mar
     daysInMonth[ 3] = 30;                         //Apr
     daysInMonth[ 4] = 31;                         //May
     daysInMonth[ 5] = 30;                         //Jun
     daysInMonth[ 6] = 31;                         //Jul
     daysInMonth[ 7] = 31;                         //Aug
     daysInMonth[ 8] = 30;                         //Sep
     daysInMonth[ 9] = 31;                         //Oct
     daysInMonth[10] = 30;                         //Nov
     daysInMonth[11] = 31;                         //Dec

     day *= 1;
     if(!((day > 0) && (day <= daysInMonth[month - 1])))
          return false;

     return true;
}

function isLeap(year)
{
     if((year % 4) == 0)
     {
          if((year % 100) == 0)
          {
               if((year % 400) == 0)
                    return true;
               else
                    return false;
          }
          return true;
     }
     return false;
}


/*
 * checkDropDown(dropDown, alertMsg, moveNext)
 *
 * dropDown          (object)     The reference to the dropdown object.
 * alertMsg          (string)     The message to be alerted on finding error. If it is null('') then the message will not be displayed in case of an error.
 * moveNext          (boolean)     Says whether to move to the next option on error.
 *
 * Returns Value:
 *  true if there was no error. Else it returns false.
 *
 * Remark
 *  The options that are not to be allowed to select by the user should be given the value null ('').
 */

function checkDropDown(dropDown, alertMsg, moveNext)
{
     if(dropDown.options[dropDown.selectedIndex].value == '')
     {
          if(alertMsg != '')
               alert(alertMsg);

          if(moveNext)
               cddMoveForward(dropDown)

          return false;
     }
     return true;
}

function cddMoveBack(dropDown)
{
     var i;
     for(i = dropDown.selectedIndex - 1; i >= 0 && dropDown.options[i].value == ''; i--);
     if(i < 0)
          dropDown.options[dropDown.selectedIndex].selected = false;
     else
          dropDown.options[i].selected = true;
}

function cddMoveForward(dropDown)
{
     var i;
     for(i = dropDown.selectedIndex + 1; i < dropDown.options.length && dropDown.options[i].value == ''; i++);
     if(i >= dropDown.options.length)
          cddMoveBack(dropDown);
     else
          dropDown.options[i].selected = true;
}


/*
 * formFocus(frm)
 *
 * frm          (object)     The reference to the form object to be focused.
 *
 * Remark
 *  Passes the focus to the first element in the given form.
 */

function formFocus(frm)
{
     var fieldLen;
     if(frm != null && frm.elements)
     {
          fieldLen = frm.elements.length;
          var eleType;
          for(i = 0; i < fieldLen; i++)
          {
               eleType = frm.elements[i].type;
               if(eleType == 'select-multiple' || eleType == 'select-one' || eleType == 'text' || eleType == 'textarea' || eleType == 'checkbox' || eleType == 'radio')
               {
                    frm.elements[i].focus();
                    break;
               }
          }
     }
}

// Function to check whether an element is null or contain initial spaces.
function spaceCheck(formname, fieldname) {
        anyspacing = true;
        itemlength = eval("document." + formname + "." + fieldname + ".value.length");
        itemvalue = eval("document." + formname + "." + fieldname + ".value");
        for(i = 0; i < itemlength; i++) {
                if(itemvalue.charAt(i) != ' ') {
                        anyspacing = false;
                        break;
                }
        }
       eval("document." + formname + "." + fieldname + ".focus()");
        return anyspacing;
}

//---------------------------------------------------------------------------------------------------
//     to check space
//     parameters  (formname,fieldname)
//-----------------------------------------------------------------------------------------------------

function chkspace(formname,fieldname,msgname) {
     field = eval("document." + formname +"."+ fieldname);
        if (field.value.indexOf(' ') >= 0) {
             alert(msgname + " cannot contain space");
             field.focus();
             return false;
        }
        else {
             return true;
        }
}

function isEmpty(formname, fieldname) {
        itemvalue = eval('document.' + formname + '.' + fieldname + '.value');
        if(itemvalue.length <= 0) {
                return true;
        }
        icount = 0;
        for(i=0;i<itemvalue.length;++i) {
                if(itemvalue.charAt(i) != ' ') {
                        ++icount;
                }
        }
        if(icount > 0) {
                return false;
        }
        else {
                return true;
        }
}

function openWindow(type, page) {
     windowFeatures = "";
     if (type == 'news') {
          window_width = 500;
          window_height = 350;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=1"
     }
     if (type == 'showimage') {
          window_width = 400;
          window_height = 400;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=1"
     }
      if (type == 'joincom') {
          window_width = 320;
          window_height = 250;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=0"
     }
       if (type == 'eire') {
          window_width = 330;
          window_height = 170;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=0"
      }
      if (type == 'ett') {
          window_width = 330;
          window_height = 170;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=0"
      }

          if (type == 'global') {
          window_width = 350;
          window_height = 200;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=0"
     }
     
        if (type == 'global1') {
          window_width = 350;
          window_height = 400;
          window_top = (screen.availHeight-window_height)/2
          window_left = (screen.availWidth-window_width)/2
          windowFeatures += "width=" + window_width + ",height=" + window_height + ",top="
          windowFeatures += window_top
          windowFeatures += ",left="
          windowFeatures += window_left
          windowFeatures += ",scrollbars=1"
     }
     window.open(page,type,windowFeatures)
}


/*Please don't delete this line </SCRIPT></HEAD><BODY STYLE="background-color:black;color:gray">
<FORM name=form1 onSubmit="alert(checkDateString(document.form1.dateInput.value, document.form1.dateFormat.value, document.form1.seperator.options[document.form1.seperator.selectedIndex].value)); return false"><TABLE><TR><TD ALIGN=RIGHT>Date:</TD><TD ALIGN=LEFT><INPUT STYLE="background-color:black;color:gray;border:1 solid" TYPE=TEXT name=dateInput></TD></TR><TR><TD ALIGN=RIGHT>Date Format:</TD><TD ALIGN=LEFT><INPUT STYLE="background-color:black;color:gray;border:1 solid" TYPE=TEXT name=dateFormat></TD></TR><TR><TD ALIGN=RIGHT>Seperator:</TD><TD ALIGN=LEFT><SELECT STYLE="background-color:black;color:gray;border:1 solid" NAME=seperator SIZE=1><OPTION VALUE='/'>/</OPTION><OPTION VALUE='-'>-</OPTION></SELECT></TD></TR><TR><TD ALIGN=CENTER COLSPAN=2><INPUT STYLE="background-color:black;color:gray;border:1 solid" TYPE=submit onMouseOver="this.style.backgroundColor='#555555';this.style.color='#bbbbbb'" onMouseOut="this.style.backgroundColor='black';this.style.color='gray'"></TD></TR></TABLE></FORM>
</BODY></HTML>*/


//isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.() 
function func_is_telephone_number(param_text) 
{ 
	var b_is_telephone_number=true; 
	if(func_trim(param_text)!="") 
	{ 
		var str_text=new String(func_trim(param_text));
		var i_length=func_len(str_text);
		var i_loop; 
		for (i_loop=0;i_loop<i_length;i_loop++) 
		{ 
			if (!((str_text.charCodeAt(i_loop) >= 48 && str_text.charCodeAt(i_loop) <= 57) || (str_text.charAt(i_loop) == "-")|| (str_text.charAt(i_loop) == "(")|| (str_text.charAt(i_loop) == ")") || (str_text.charAt(i_loop) == "+") || (str_text.charCodeAt(i_loop) ==32) || (str_text.charAt(i_loop) == "."))) 
			{ 
				b_is_telephone_number=false; 
			} 
		} 
	} 
	return b_is_telephone_number; 
}

function func_is_fax_number(param_text) 
{ 
	var b_is_fax_number=true; 
	if(func_trim(param_text)!="") 
	{ 
		var str_text=new String(func_trim(param_text));
		var i_length=func_len(str_text);
		var i_loop; 
		for (i_loop=0; i_loop<i_length; i_loop++) 
		{ 
			if (!((str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57) || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="(") || (str_text.charAt(i_loop)==")") || (str_text.charAt(i_loop)=="+") || (str_text.charCodeAt(i_loop)==32) || (str_text.charAt(i_loop)=="."))) 
			{ 
				b_is_fax_number=false; 
			} 
		} 
	} 
	return b_is_fax_number; 
}
5/4/04
//returns true if numeric
function func_isnumeric(par_text)
{
 	if(!isNaN(par_text))
	{
		return true;
	}
	else
	{
		return false;
	}
}
//returns true if alphabetic
function func_isalphabetic(par_text)
{
 	var text=new String(par_text);
	var ilen;
	var bflag=true;
	for(ilen=0;ilen<=text.length;ilen++)
	{
		if(text.charCodeAt(ilen) < 65 || text.charCodeAt(ilen) > 90 && text.charCodeAt(ilen) < 97 || text.charCodeAt(ilen) > 122)
		{
			bflag=false;
		}
	}
	return bflag;
}
//returns true if alphanumeric
function func_isalphanumeric(par_text)
{
 	var str = new String(par_text);
	for (var i=0;i<str.length;i++)
	{
		if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
		{
			return false; 
		}
	 }
	return true;	 
} 
// returns true if length is gearter than given value.
function func_isMaxLength(par_text,par_length)
{
	var strlen;
	var text=new String(par_text);
	strlen = func_len(text);
	if (strlen > par_length)
	{
		return true;
	}
	else
	{
		return false;
	}
}
// returns true if length is less than given value.
 function func_isMinLength(par_text,par_length)
{
	var strlen;
	var text=new String(par_text);
	strlen = func_len(text);
	if (strlen < par_length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//returns true if null
function func_isNull(par_text)
{
	
	if((func_trim(par_text) == "") || (par_text == null))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//returns true if it is valid date.
function func_isDate(date,month,year)
{ 
	var bflag=true;
	if (isNaN(year) || isNaN(month) || isNaN(date))
	{
		bflag=false;
	}
	if(bflag)
	{
		var dtnew = new Date(year,month-1,date);
		if ((parseInt(dtnew.getFullYear()) == year) && (parseInt(dtnew.getMonth()) == (month-1)) && (parseInt(dtnew.getDate()) == date))
		{
			bflag=true;
		}
		else
		{
			bflag=false;
		}
	}
	return bflag;
}

// returns true if valid Email.
function func_isEmail(emailval)
{
	var tempStr,icount;
	var blnmail,blnperiod; 
	var lastoccofperiod,maxthree;
	var ampicount=0;
	var amppos;
	var servername = 1;
	var dots;
	icount=emailval.length;
	blnperiod = 1;
	maxthree = 1;
	specialchar = 0
	lastoccofperiod = 0;
	if (icount==0)
	{
		return true;
	}
	for(i=0;i<icount;i++)
	{
		tempStr = emailval.charAt(i);
		if ((tempStr >='a')&&(tempStr <='z'))
		{
			specialchar=specialchar+1;
		}
		else
		{
			if ((tempStr >='A')&&(tempStr <='Z'))
			{
				specialchar=specialchar+1;
			}
			else
			{
				if ((tempStr >= 0)&&(tempStr<=9))
				{
					specialchar=specialchar+1;
				}
				else
				{
					if ((tempStr=='_')||(tempStr=='-')||(tempStr=='.')||(tempStr=='@'))
					{
						specialchar=specialchar+1;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}
	dots = emailval.indexOf('..');
	if (dots != -1)
	{
		return false;
	}
	espace = emailval.indexOf(' ');
	if (espace != -1)
	{
		return false;
	}
	lastoccofperiod = emailval.lastIndexOf('.');
	if (lastoccofperiod <= 0)
	{
		blnperiod = 0;
	}
	if (((icount - lastoccofperiod) > 5)||((icount - lastoccofperiod) < 3))
	{
		maxthree = 0;
	}
	 for(i=0;i<=icount;i++)
	{
		tempStr = emailval.charAt(i)
		if (tempStr=='@')
		ampicount=ampicount + 1;
	}
	amppos = emailval.indexOf('@');
	if (emailval.charAt(amppos+1) == '.')
	servername = 0;
	if(icount - emailval.charAt(amppos)< 5) 
	servername = 0;
	if ((ampicount==1)&&(blnperiod==1)&&(maxthree==1)&&(servername==1))
	{
		blnmail=1;
	}
	else
	{
		 blnmail=0;
	}
	 //return blnmail;
	if (blnmail==0)
	{
		//alert('Please enter a valid email address');
		return false;
	}
	else
	{
		return true;
	}
 }

function func_isValidURL(strText)
{
	var bcorrect=true;
	if(bcorrect && func_isNull(strText))
	{
		return true;
	}
	if(bcorrect && strText.indexOf("/")!=-1)
	{
		strText=strText.substring(0,strText.indexOf("/"));
	}
	
	var len = strText.length;
	
	//validate the characters allowed
	if(bcorrect)
	{	
		var i = 0;
		for (i=0; i<len; i++)
		{
			if (!((strText.charCodeAt(i) >= 65 && strText.charCodeAt(i) <= 90)
			  || (strText.charCodeAt(i) >= 97 && strText.charCodeAt(i) <= 122)
			  || (strText.charCodeAt(i) >= 48 && strText.charCodeAt(i) <= 57)
			  || (strText.charAt(i) == "-")
			  || (strText.charAt(i) == "_")
			  || (strText.charAt(i) == ".")))
			{
				bcorrect=false;
			}
		}
	}
	
	if(bcorrect && strText.indexOf("..")!=-1)
		bcorrect=false;
	if(bcorrect && strText.indexOf("-")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf("_")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf(".")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf(".")==-1)
		bcorrect=false;
	
	//validate last index of '.' and number of chars next to that
	if(bcorrect)
	{
		var iLastPos=strText.lastIndexOf('.');
		var iMinChar=len - iLastPos;
		if(iMinChar<3 || iMinChar>5)
			bcorrect=false;
	}
	
	//validate extension
	if(bcorrect)
	{
		var strExtension=strText.substring(strText.lastIndexOf('.')+1);
		if(!func_isalphanumeric(strExtension))
			bcorrect=false;
	}
	return bcorrect;
}

//Checks whether file type is ends with specified extension or not
function isFile(strValue,strFileType)
{
	var bCorrect=false;
	strImage=new String(strValue);
	var bHtml=false;
	var bAll=false;
	var bImage=false;
	if(strValue.length==0)
	{
		return true;
	}
	if(strFileType.toLowerCase()=="htm" || strFileType.toLowerCase()=="html")
	{
		bHtml=true;
	}
	if(strFileType.toLowerCase()=="all")
	{
		bAll=true;
	}
	if(strFileType.toLowerCase()=="img")
	{
		bImage=true;
	}
	if(strImage.indexOf(".")!=-1)
	{
		iIndex=strImage.indexOf(".");
		if(bAll==true)
		{
			strFile=strImage.substring(iIndex+1);
			if(strFile.length>=2 && strFile.length<250)
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else	if(bImage==true)
		{
			if((strImage.substring(iIndex+1)).toLowerCase()=="gif" || (strImage.substring(iIndex+1)).toLowerCase()=="jpg" || (strImage.substring(iIndex+1)).toLowerCase()=="jpeg" || (strImage.substring(iIndex+1)).toLowerCase()=="bmp")
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else	if(bHtml==true)
		{
			if((strImage.substring(iIndex+1)).toLowerCase()=="htm" || (strImage.substring(iIndex+1)).toLowerCase()=="html")
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else
		{
			if((strImage.substring(iIndex+1)).toLowerCase()==strFileType.toLowerCase())
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
	}
	else
	{
		bCorrect=false;
		return bCorrect;
	}
}








// customised functions
// returns the length of string
function func_len(par_text)
{
	var strText=new String(par_text);
	return strText.length;
}

//returns the trimmed string
function func_trim(par_text)
{
	var stext = new String(par_text);
	var sresult = "";
	//Remove leading spaces
	for (var i=0; i<stext.length; i++)
	{
		if (stext.charAt(i) != " ")
		{
			sresult = stext.substr(i, (stext.length - i));
			break;
		}
	}
	stext = sresult;
	//Remove trailing spaces
	for (var j=(stext.length - 1); j>=0; j--)
	{
		if (stext.charAt(j) != " ")
		{
			sresult = stext.substr(0, (j + 1));
			break;
		}
	}
	return sresult;
}

// selecting & focusing on the element that holds incorrect value
function func_selectFocus(element)
{
	element.select();
	element.focus();
	return true;
}

// HTML Validations
function validate_check_box(obj_form,str_prefix)
{
 	var b_return = true;
	for(i=0;i<obj_form.elements.length;i++)
	{
	 	obj_element = obj_form.elements[i];
		if(obj_element.type == "checkbox" && obj_element.name.indexOf(str_prefix)!=-1)
		{
		 	if(obj_element.checked == true)
			{
			  b_return = false;
			  return b_return;	
			}
		}	
	 }
	 return(b_return);
}

function validate_dropdownlist(obj_listelement)
{
 		 var b_return = true;
		 if(obj_listelement.options[obj_listelement.selectedIndex].value != "")
		 {
		  	  b_return = false;
		 	  return b_return;
		 }		
		 return b_return;
}

function validate_textbox(str_Name,obj_element,b_numeric,b_alphabetic,b_alphanumeric,b_zerolength,i_max_char,i_min_char,str_email,str_url,str_file,str_filetype)
{
 		var b_return = true;
		var str_value=obj_element.value;
		if (b_return && numeric) 
		{
		   alert("Numeric");
		func_selectFocus(obj_element);
		   
		}
		
		return b_return;
}

//returns true if a radio button is checked
function func_IsRadioChecked(objForm,strName)
{
	var bcorrect;
	bcorrect=false;
	for(i=0; i<objForm.elements.length; i++)
	{
		var name=objForm.elements[i].name;
		var type=objForm.elements[i].type;
		if((type=="radio") && (name.indexOf(strName)!=-1))
		{
			var val=objForm.elements[i].checked;
			if(val==true)
			{
				bcorrect=true;
				break;
			}
		}
	}	
	return bcorrect;
}

//returns true if atleast one check box is selected
function func_IsCheckboxSelected(objForm,strName)
{
	var bcorrect=false;
	for(var i=0; i<objForm.elements.length; i++)
	{
		var name=objForm.elements[i].name;
		var type=objForm.elements[i].type;
		if((type=="checkbox") && (name.indexOf(strName)!=-1))
		{
			var val=objForm.elements[i].checked;
			if(val==true)
			{
				bcorrect = true;
				break;
			}
		}
	}
	return bcorrect;
}

function func_add_tolistbox(obj_form,obj_text_element,obj_option_element)
{
 	str_value = obj_text_element.value;
	if(str_value == "")
	{
	 	alert("Please enter value");
	}
	else
	{
		obj_option_element.options[obj_option_element.length] = new Option(str_value,str_value);			
	}
}
function isEmptyfield(s)
{   
	return ((s == null) || (s.length == 0) || (s.substr(0,1) == " "))
}


