
function alphaNumericStrOnly(str){
	return str.replace(/[^a-zA-Z 0-9]+/g,'');
}

function pause(millis)
{

date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < millis);
} 

function Timestamp() {
    var dt = new Date();
	var strText = new String(dt.getHours() + "" + dt.getMinutes() + "" +  dt.getSeconds() + "" + dt.getMilliseconds())
	return strText;
}


function RemoveRow(table, row) {

	if(document.getElementById(table) != null){
		oTable = document.getElementById(table);
	}else if(window.opener.document.getElementById(table) != null){
		oTable = window.opener.document.getElementById(table);
	}else
		return false


	//find row
	found = 0;

	for(i=0; i < oTable.rows.length; i++){

		if(oTable.rows[i].id == row){
			oRow = oTable.deleteRow(i)
			break
		}		
	}
	
}


function rpad(number,length, padchar) {
    var str = '' + number;
    while (str.length < length)
        str = str + padchar ;
    return str;
}

function lpad(number,length, padchar) {
    var str = '' + number;
    while (str.length < length)
        str =  padchar + str;
    return str;
}

function isNumber(contents) {
    if (((contents / contents) != 1) && (contents != 0)) {return false}
	else return true
}



function check_sequence(form){
	form = document.getElementById(form)
	
	for(i=0; i < form.length; i++){

		if(form.elements[i].name == 'display_order[]'){

			current = form.elements[i].options[form.elements[i].options.selectedIndex].text

			for(j=0; j < form.length; j++){
				
				if(form.elements[j].name == 'display_order[]' ){
					if(j != i){
						//alert(form.elements[j].options[form.elements[j].options.selectedIndex].text)
						if(form.elements[j].options[form.elements[j].options.selectedIndex].text == current){
							alert("Duplicate found for position "+current+" in sequence order. Please check.")
							return false
						}
					}
				}

			} //END FOR

		} //END IF

	} //END FOR	
}



function isValidFilename(string) {

	var invalids = '?&/\*:;|<>"\'=';

    for (var i=0; i< string.length; i++) {
       if (invalids.indexOf(string.charAt(i)) != -1)
          return false;
    }
    return true;
}




function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}




function toggle_box(form, box)
{

	str = "if (document."+form+"."+box+".checked == true) document."+form+"."+box+".checked = false; else document."+form+"."+box+".checked = true"
	eval(str);

}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

//3-state Highlight menu effect script: By Dynamicdrive.com
//For full source, Terms of service, and 100s DTHML scripts
//Visit http://www.dynamicdrive.com

function over_effect(e,state){
if (document.all)
source4=event.srcElement
else if (document.getElementById)
source4=e.target
if (source4.className=="menulines")
source4.style.borderStyle=state
else{
while(source4.tagName!="TABLE"){
source4=document.getElementById? source4.parentNode : source4.parentElement
if (source4.className=="menulines")
source4.style.borderStyle=state
}
}
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function uppercase(value) {
  return value.toUpperCase(value);
}

function lowercase(value) {
  return value.toLowerCase(value);
}



function getExtension(value) {
  return value.substring(value.lastIndexOf('.') + 1,value.length);
}


function datePosition(sd, sm, sy, ed, em, ey, flag) {
    

	var startday = sd;
    var startmonth = sm;
    var startyear = sy;
    var endday = ed;
    var endmonth = em;
    var endyear = ey;


    var startdate = new Date(startyear-0,startmonth-1,startday-0);
    var enddate = new Date(endyear-0,endmonth-1,endday-0);

    starttime = Date.UTC(y2k(startdate.getYear()),startdate.getMonth(),startdate.getDate(),0,0,0);
 
	//if flag is 0, check with current date
	if(flag == 0){
		currentdate = new Date();
		endtime = Date.UTC(y2k(currentdate.getYear()),currentdate.getMonth(),currentdate.getDate(),0,0,0);
	
	}else{
		endtime = Date.UTC(y2k(enddate.getYear()),enddate.getMonth(),enddate.getDate(),0,0,0);
	}
    

	if (starttime < endtime) {
		return -1;
	}else if(starttime == endtime) {			
		return 0;
	}else{
		return 1;
	}

}

function y2k(number)
{
  return (number < 1000) ? number + 1900 : number;
}


function isValidDate (day,month,year)
{
  // checks if date passed is valid
 
    var today = new Date();
    year = ((!year) ? y2k(today.getFullYear()):year);
	month = ((!month) ? today.getMonth():month-1);
  

    if (!day) return false


    var test = new Date(year,month,day);
    if ( (y2k(test.getFullYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false

}


function cleanFolderName(name){

	name = replaceCarriageReturn(name, '&','and');
	name = replaceCarriageReturn(name, '+','plus');
	name = replaceCarriageReturn(name, '\'','');
	name = replaceCarriageReturn(name, '"','');
	name = replaceCarriageReturn(name, '/','');
	name = replaceCarriageReturn(name, '\\','');
	name = replaceCarriageReturn(name, '%','');
	name = replaceCarriageReturn(name, '$','');
	name = replaceCarriageReturn(name, '#','');
	return name;

}

function replaceCarriageReturn(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceCarriageReturn(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function trim(strText) { 

    strText = replaceCarriageReturn(replaceCarriageReturn(strText,'\r',''),'\n','');

	// this will get rid of leading spaces 
    while ((strText.substring(0,1) == ' ')||(strText.substring(0,2) == '\r')) 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while ((strText.substring(strText.length-1,strText.length) == ' ')||(strText.substring(strText.length-2,strText.length) == '\r'))
        strText = strText.substring(0, strText.length-1);

   return strText;
} 


function is_empty(form, field)
{
  form.field.value = trim(form.field.value);
  if ( (temp_str == null) || (temp_str == " ") || (temp_str == '\t') || (temp_str == "") )
	return true;
  else
	return false;
}

