// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=1900;
var maxYear=2100;
var nameIndex = 0;
var typeIndex = 1;
var requiredIndex = 2;
var msgIndex = 3;
var jstypeIndex = 5;
var minIndex = 5;
var maxIndex = 6;
var compareToIndex = 7;
var allowblank = 8;
var validate = new Array();
var maxHours = 24;
var requiredTxt = 'Missing Required Field:'
var invalidTxt = 'Invalid Value:'
var secondsSinceLoad = 0;

var DoOnLoad = false;

function getCell(id){
	return document.all ? document.all(id) : document.getElementById ? document.getElementById(id) : document.layers ? document['NS_' + id].document.layers[0] : null
}

function isCurrency(strString) {
  	
  	var strValidChars = "0123456789.";
   	var strChar;
   	var blnResult = true;

	if (strString.length == 0) return false;

   	//  test strString consists of valid characters listed above
   	for (i = 0; i < strString.length && blnResult == true; i++) {
   		strChar = strString.charAt(i);
   		if (strValidChars.indexOf(strChar) == -1){
   			blnResult = false;
   		}
   	}
   	return blnResult;
}

function isNotNumeric(s){
  if(!/^-*[0-9\.]+$/.test(s))
   {
   		alert("Invalid Number!");
   		return false
   }
   else
   {
   		return true;
   }
}

/**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */
function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function


/**
 * Displays an error message if a "DROP DATABASE" statement is submitted
 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
 * sumitting it if required.
 * This function is called by the 'checkSqlQuery()' js function.
 *
 * @param   object   the form
 * @param   object   the sql query textarea
 *
 * @return  boolean  whether to run the query or not
 *
 * @see     checkSqlQuery()
 */
function confirmQuery(theForm1, sqlQuery1)
{
    // Confirmation is not required in the configuration file
    if (confirmMsg == '') {
        return true;
    }

    // The replace function (js1.2) isn't supported
    else if (typeof(sqlQuery1.value.replace) == 'undefined') {
        return true;
    }

    // js1.2+ -> validation with regular expressions
    else {
        // "DROP DATABASE" statement isn't allowed
        if (noDropDbMsg != '') {
            var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
            if (drop_re.test(sqlQuery1.value)) {
                alert(noDropDbMsg);
                theForm1.reset();
                sqlQuery1.focus();
                return false;
            } // end if
        } // end if

        // Confirms a "DROP/DELETE/ALTER" statement
        //
        // TODO: find a way (if possible) to use the parser-analyser
        // for this kind of verification
        // For now, I just added a ^ to check for the statement at
        // beginning of expression
        
        //var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
        //var do_confirm_re_1 = new RegExp('ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
        //var do_confirm_re_2 = new RegExp('DELETE\\s+FROM\\s', 'i');
        var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
        var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
        var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
        if (do_confirm_re_0.test(sqlQuery1.value)
            || do_confirm_re_1.test(sqlQuery1.value)
            || do_confirm_re_2.test(sqlQuery1.value)) {
            var message      = (sqlQuery1.value.length > 100)
                             ? sqlQuery1.value.substr(0, 100) + '\n    ...'
                             : sqlQuery1.value;
            var is_confirmed = confirm(confirmMsg + ' :\n' + message);
            // drop/delete/alter statement is confirmed -> update the
            // "is_js_confirmed" form field so the confirm test won't be
            // run on the server side and allows to submit the form
            if (is_confirmed) {
                theForm1.elements['is_js_confirmed'].value = 1;
                return true;
            }
            // "DROP/DELETE/ALTER" statement is rejected -> do not submit
            // the form
            else {
                window.focus();
                sqlQuery1.focus();
                return false;
            } // end if (handle confirm box result)
        } // end if (display confirm box)
    } // end confirmation stuff

    return true;
} // end of the 'confirmQuery()' function


/**
 * Displays an error message if the user submitted the sql query form with no
 * sql query, else checks for "DROP/DELETE/ALTER" statements
 *
 * @param   object   the form
 *
 * @return  boolean  always false
 *
 * @see     confirmQuery()
 */
function checkSqlQuery(theForm)
{
    var sqlQuery = theForm.elements['sql_query'];
    var isEmpty  = 1;

    // The replace function (js1.2) isn't supported -> basic tests
    if (typeof(sqlQuery.value.replace) == 'undefined') {
        isEmpty      = (sqlQuery.value == '') ? 1 : 0;
        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
        }
    }
    // js1.2+ -> validation with regular expressions
    else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (sqlQuery.value.replace(space_re, '') == '') ? 1 : 0;
        // Checks for "DROP/DELETE/ALTER" statements
        if (!isEmpty && !confirmQuery(theForm, sqlQuery)) {
            return false;
        }
        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_file'].value.replace(space_re, '') == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_localfile'].value.replace(space_re, '') == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
            isEmpty  = (theForm.elements['id_bookmark'].selectedIndex == 0);
        }
        if (isEmpty) {
            theForm.reset();
        }
    }

    if (isEmpty) {
        sqlQuery.select();
        alert(errorMsg0);
        sqlQuery.focus();
        return false;
    }

    return true;
} // end of the 'checkSqlQuery()' function


/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
        theForm.reset();
        theField.select();
        alert(errorMsg0);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' function


/**
 * Ensures a value submitted in a form is numeric and is in a range
 *
 * @param   object   the form
 * @param   string   the name of the form field to check
 * @param   integer  the minimum authorized value
 * @param   integer  the maximum authorized value
 *
 * @return  boolean  whether a valid number has been submitted or not
 */
function checkFormElementInRange(theForm, theFieldName, min, max)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

    if (typeof(min) == 'undefined') {
        min = 0;
    }
    if (typeof(max) == 'undefined') {
        max = Number.MAX_VALUE;
    }

    // It's not a number
    if (isNaN(val)) {
        theField.select();
        alert(errorMsg1);
        theField.focus();
        return false;
    }
    // It's a number but it is not between min and max
    else if (val < min || val > max) {
        theField.select();
        alert(val + errorMsg2);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function


/**
 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
 * checkboxes is consistant
 *
 * @param   object   the form
 * @param   string   a code for the action that causes this function to be run
 *
 * @return  boolean  always true
 */
function checkTransmitDump(theForm, theAction)
{
    var formElts = theForm.elements;

    // 'zipped' option has been checked
    if (theAction == 'zip' && formElts['zip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
            theForm.elements['gzip'].checked = false;
        }
        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
            theForm.elements['bzip'].checked = false;
        }
    }
    // 'gzipped' option has been checked
    else if (theAction == 'gzip' && formElts['gzip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
            theForm.elements['bzip'].checked = false;
        }
    }
    // 'bzipped' option has been checked
    else if (theAction == 'bzip' && formElts['bzip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
            theForm.elements['gzip'].checked = false;
        }
    }
    // 'transmit' option has been unchecked
    else if (theAction == 'transmit' && !formElts['asfile'].checked) {
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
            theForm.elements['gzip'].checked = false;
        }
        if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
            theForm.elements['bzip'].checked = false;
        }
    }

    return true;
} // end of the 'checkTransmitDump()' function


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        domDetect    = false;
    } // end 3

    var c = null;
    // 5.1 ... with DOM compatible browsers except Opera
    for (c = 0; c < rowCellsCnt; c++) {
        if (domDetect) {
            currentColor = theCells[c].getAttribute('bgcolor');
        } else {
            currentColor = theCells[c].style.backgroundColor;
        }

        // 4. Defines the new color
        // 4.1 Current color is the default one
        if (currentColor == ''
            || currentColor.toLowerCase() == theDefaultColor1.toLowerCase() 
            || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
            if (theAction == 'over' && thePointerColor != '') {
                newColor              = thePointerColor;
            } else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.2 Current color is the pointer one
        else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
                 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
            if (theAction == 'out') {
                if (c % 2) {
                    newColor              = theDefaultColor1;
                } else {
                    newColor              = theDefaultColor2;
                }
            }
            else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.3 Current color is the marker one
        else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
            if (theAction == 'click') {
                newColor              = (thePointerColor != '')
                                      ? thePointerColor
                                      : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
                marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                      ? true
                                      : null;
            }
        } // end 4

        // 5. Sets the new color...
        if (newColor) {
            if (domDetect) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
            // 5.2 ... with other browsers
            else {
                theCells[c].style.backgroundColor = newColor;
            }
        } // end 5
    } // end for

     return true;
 } // end of the 'setVerticalPointer()' function

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
          ? document.forms[the_form].elements['selected_tbl[]']
          : document.forms[the_form].elements['selected_fld[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function


/**
  * Checks/unchecks all options of a <select> element
  *
  * @param   string   the form name
  * @param   string   the element name
  * @param   boolean  whether to check or to uncheck the element
  *
  * @return  boolean  always true
  */
function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for

    return true;
} // end of the 'setSelectOptions()' function

/**
  * Allows moving around inputs/select by Ctrl+arrows
  *
  * @param   object   event data   
  */
function onKeyDownArrowsHandler(e) {
    e = e||window.event;
    var o = (e.srcElement||e.target);
    if (!o) return;
    if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
    if (!e.ctrlKey) return;
    if (!o.id) return;

    var pos = o.id.split("_");
    if (pos[0] != "field" || typeof pos[2] == "undefined") return;

    var x = pos[2], y=pos[1];
    
    // skip non existent fields
    for (i=0; i<10; i++)
    {
        switch(e.keyCode) {
            case 38: y--; break; // up
            case 40: y++; break; // down
            case 37: x--; break; // left
            case 39: x++; break; // right
            default: return;
        }

        var id = "field_" + y + "_" + x;
        var nO = document.getElementById(id);
        if (nO) break;
    }
    
    if (!nO) return;
    nO.focus();
    if (nO.tagName != 'SELECT') {
        nO.select();
    }
    e.returnValue = false;
}

/**
  * Inserts multiple fields.
  *
  */
function insertValueQuery() {
    var myQuery = document.sqlform.sql_query;
    var myListBox = document.sqlform.dummy;

    if(myListBox.options.length > 0) {
        var chaineAj = "";
        var NbSelect = 0;
        for(var i=0; i<myListBox.options.length; i++) {
            if (myListBox.options[i].selected){
                NbSelect++;
                if (NbSelect > 1)
                    chaineAj += ", ";
                chaineAj += myListBox.options[i].value;
            }
        } 

        //IE support
        if (document.selection) {
            myQuery.focus();
            sel = document.selection.createRange();
            sel.text = chaineAj;
            document.sqlform.insert.focus();
        }
        //MOZILLA/NETSCAPE support
        else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
            var startPos = document.sqlform.sql_query.selectionStart;
            var endPos = document.sqlform.sql_query.selectionEnd;
            var chaineSql = document.sqlform.sql_query.value;
        
            myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
        } else {
            myQuery.value += chaineAj;
        }
    }
}

//sListView = new sugarListView();
// -- end sugarListView class

function popWin(Page,Title,scrbar,w,h) {
	
	LPos = (screen.width - w)/2;
	TPos = (screen.height - h)/2;
	
	winRef = window.open(Page,Title,"height="+h+",width="+w+",scrollbars="+scrbar+",resizable=no,maximize=no,left="+LPos+", top="+TPos);
	winRef.focus();
}

function MM_callJS(jsStr) { //v2.0
	return eval(jsStr)
}
	
function chk_rad(t, n, msg) {
	for (var i=0; i<n; i++) {
		if (t[i].checked!="0") return true;
	}
	alert(msg);
	return false;
}
   
function chk_text(t, msg) {
	if (t.value != '') return true;
	alert(msg);
	t.focus();
	return false;
}
	
function chk_select(t, msg) {
	if (t.selectedIndex != 0) return true;
   	alert(msg);
	t.focus();
	return false;
}
	
function chk_text_email(t, msg) {
	if (t.value != '') {
	    var at = t.value.indexOf('@', 0);
        if (at > 1 && t.value.lastIndexOf('.') > at) {
    	    return true;
    	}
    }
    alert(msg);
    t.focus();
    t.select();
	return false;
}
   
function chk_textPassword(t, s, msg) {
	if(s.value == t.value) return true;
	alert(msg);
	s.focus();
	return false;
}
	
function chk_number(t, msg){
	var valid = "0123456789";
	var tt = t.value;
	for (var i=0; i < tt.length; i++) {
		temp = "" + tt.substring(i, i+1);
		if (valid.indexOf(temp) == "-1"){
			alert(msg);
			t.focus();
			return false;	
		}
	}	
	return true;
}

function chk_currency(t, msg){
		var valid = "0123456789.";
		var tt = t.value;
		for (var i=0; i < tt.length; i++) {
			temp = "" + tt.substring(i, i+1);
			if (valid.indexOf(temp) == "-1"){
				alert(msg);
				t.focus();
				return false;	
			}
		}	
		return true;
	}
	
function chk_NumofChar(t, msg, num){
	if(t.value.length > num) return true;
	alert(msg);
	t.focus();
	return false;
}

function chk_length(t, n, msg){
	if (t.value.length == n) return true;
	alert(msg);
	t.focus();
}
	
function OnKeyPressForTest(){
	// to allow 0-9 numeric digit in the input field
	if( event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;
}
	
function alertmsg(tclick, url){
	var a = confirm("Are you sure you want to "+tclick+" this ticket?", "Yes", "No")
	if (a == true) {
		window.location.href = url;
	}
}
	
function alertmsg2(msg, url){
	var a = confirm(msg, "Oui", "Non")
	if (a == true) {
		window.location.href = url;
	}
}
	
function validate_image(file) {
	
	if (file=="") return true;
	extArray = new Array(".gif", ".jpg", ".png", ".bmp",".jpeg");
	allowSubmit = false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { 
			allowSubmit = true; 
			break; 
		}
	}
	if (allowSubmit) return true; //form.submit();
	//else
	//alert('Invalid Photo Format.');
	return false;
}
	
function validate_pdf(file) {
		
	if (file=="") return true;
	extArray = new Array(".pdf");
	allowSubmit = false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { 
			allowSubmit = true; 
			break; 
		}
	}
	if (allowSubmit) return true; //form.submit();
	//else
	//alert('Invalid PDF Format.');
	return false;
}

function validate_csv(file) {
		
	if (file=="") return true;
	extArray = new Array(".csv");
	allowSubmit = false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { 
			allowSubmit = true; 
			break; 
		}
	}
	if (allowSubmit) return true; //form.submit();
	//else
	//alert('Invalid CSV Format.');
	return false;
}
	
function sendLimit(fileName, page) {
    //If the selected file name isn't blank, send it to reader.
   	if (fileName.value != "") {
 		//alert(fileName.value);
		location.href=page+'&limit='+fileName.value;
   	}
}
	
function Get_Cookie(name){
	var start=document.cookie.indexOf(name+'=');
	var len=start+name.length+1;
	if((!start)&&(name!=document.cookie.substring(0,name.length))) return null;
	if(start==-1) return null;
	var end=document.cookie.indexOf(';',len);
	if(end==-1)end=document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}
	
function Set_Cookie(name,value,expires,path,domain,secure){
	var today=new Date();
	today.setTime(today.getTime());
	if(expires){
		expires=expires*1000*60*60*24;
	}
	var expires_date=new Date(today.getTime()+(expires));
	document.cookie=name+"="+escape(value)+((expires)?";expires="+expires_date.toGMTString():"")+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+((secure)?";secure":"");
}
	
function Delete_Cookie(name,path,domain){
	if(Get_Cookie(name)) document.cookie=name+'='+((path)?';path='+path:'')+((domain)?';domain='+domain:'')+';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function get_sub_cookies(cookie){
	var cookies=new Array();
	var end='';
	if(cookie&&cookie!=''){
		end=cookie.indexOf('#')
		while(end>-1){
			var cur=cookie.substring(0,end);
			cookie=cookie.substring(end+1,cookie.length);
			var name=cur.substring(0,cur.indexOf('='));
			var value=cur.substring(cur.indexOf('=')+1,cur.length);
			cookies[name]=value;
			end=cookie.indexOf('#')
		}
	}
	return cookies;
}

function subs_to_cookie(cookies){
	var cookie='';
	for(var i in cookies){
		cookie+=i+'='+cookies[i]+'#';
	}
	return cookie;
}

var request_id=0;
var current_child_field='';
var current_subpanel_url='';
var child_field_loaded=new Object();
var request_map=new Object();
	
function get_module_name(){
	//if(typeof(window.document.forms['DetailView'])=='undefined'){
	//	return'';
	//}else{
	//	if(typeof(window.document.forms['DetailView'].elements['subpanel_parent_module'])!='undefined'&&window.document.forms['DetailView'].elements['subpanel_parent_module'].value!=''){
	//		return window.document.forms['DetailView'].elements['subpanel_parent_module'].value;
	//	}
		return window.document.forms['DetailView'].elements['module'].value;
	//}
}
	
function subp_nav(m,i,a,t){
	if(t.href.search(/#/)<0){
		return;
	}
	if(a=='d'){
		a='DetailView';
	}else{
		a='EditView';
	}
	url='';//"index.php?module="+m+"&action="+a+"&record="+i+"&parent_module="+get_module_name()+"&parent_id="+get_record_id()+"&return_module="+get_module_name()+"&return_id="+get_record_id()+"&return_action=DetailView";
	t.href="#";
}

function sub_p_rem(sp,lf,li,rp){
	return_url="index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
	//remove_url="index.php?module="+get_module_name()+"&action=DeleteRelationship"+"&record="+get_record_id()+"&linked_field="+lf
	//+"&linked_id="+li
	//+"&return_url="+escape(escape(return_url))
	//+"&refresh_page="+rp;
	remove_url='';
	showSubPanel(sp,remove_url,true);
}

function sp_rem_conf(){
	//return confirm(SUGAR.language.get('app_strings','NTC_REMOVE_CONFIRMATION'))
}

function get_record_id(){
	return window.document.forms['DetailView'].elements['record'].value;
}

function get_layout_def_key(){
	if(typeof(window.document.forms['DetailView'].elements['layout_def_key'])=='undefined')return'';
	return window.document.forms['DetailView'].elements['layout_def_key'].value;
}

function save_finished(args) {
	var child_field=request_map[args.request_id];
	delete(child_field_loaded[child_field]);
	showSubPanel(child_field);
}

function set_return_and_save_background(popup_reply_data){
	var form_name=popup_reply_data.form_name;
	var name_to_value_array=popup_reply_data.name_to_value_array;
	var passthru_data=popup_reply_data.passthru_data;
	var query_array=new Array();
	if(name_to_value_array!='undefined'){
		for(var the_key in name_to_value_array){
			if(the_key=='toJSON'){
			} else {
				query_array.push(the_key+"="+name_to_value_array[the_key]);
			}
		}
	}
	var selection_list=popup_reply_data.selection_list;
	if(selection_list!='undefined'){
		for(var the_key in selection_list){
			query_array.push('subpanel_id[]='+selection_list[the_key])
		}
	}
	var module=get_module_name();
	var id=get_record_id();
	query_array.push('value=DetailView');
	query_array.push('module='+module);
	query_array.push('http_method=get');
	//query_array.push('return_module='+module);
	//query_array.push('return_id='+id);
	query_array.push('record='+id);
	//query_array.push('isDuplicate=false');
	query_array.push('action=edit');
	query_array.push('inline=1');
	var refresh_page=escape(passthru_data['refresh_page']);
	for(prop in passthru_data){
		if(prop=='link_field_name'){
			query_array.push('subpanel_field_name='+escape(passthru_data[prop]));
		}else{
			if(prop=='module_name'){
				query_array.push('subpanel_module_name='+escape(passthru_data[prop]));
			}else{
				query_array.push(prop+'='+escape(passthru_data[prop]));
			}
		}
	}
	var query_string=query_array.join('&');
	request_map[request_id]=passthru_data['child_field'];
	var returnstuff=http_fetch_sync('index.php',query_string);
	request_id++;
	got_data(returnstuff,true);
	if(refresh_page==1){
		document.location.reload(true);
	}
}

function got_data(args,inline){
	var list_subpanel=document.getElementById('list_subpanel_'+request_map[args.request_id].toLowerCase());
	var module=get_module_name();
	if(list_subpanel!=null){
		var subpanel=document.getElementById('subpanel_'+request_map[args.request_id].toLowerCase());
		var child_field=request_map[args.request_id].toLowerCase();
		if(inline){
			child_field_loaded[child_field]=2;
			//list_subpanel.innerHTML='';
			//list_subpanel.innerHTML=args.responseText;
		}else{
			child_field_loaded[child_field]=1;
			subpanel.innerHTML='';
			subpanel.innerHTML=args.responseText;
			var inlineTable=subpanel.getElementsByTagName('table');
			inlineTable=inlineTable[1];
			inlineTable=subpanel.removeChild(inlineTable);
			var listDiv=document.createElement('div');
			listDiv.id='list_subpanel_'+request_map[args.request_id].toLowerCase();
			subpanel.appendChild(listDiv);
			listDiv.appendChild(inlineTable);
		}
		subpanel.style.display='';
		set_div_cookie(subpanel.cookie_name,'',module);
		if(current_child_field!=''&&child_field!=current_child_field){}
		current_child_field=child_field;
	}
}

function showSubPanel(child_field,url,force_load){
	var inline=1;
	var module=get_module_name();
	if(typeof(force_load)=='undefined'){
		force_load=false;
	}
	if(force_load||typeof(child_field_loaded[child_field])=='undefined'){
		request_map[request_id]=child_field;
		if(typeof(url)=='undefined'||url==null){
			
			var id=get_record_id();
			var layout_def_key=get_layout_def_key();
			url='';//'index.php?sugar_body_only=1&module='+module+'&subpanel='+child_field+'&action=SubPanelViewer&inline='+inline+'&record='+id+'&layout_def_key='+layout_def_key;
		}
		if(url.indexOf('http://')!=0&&url.indexOf('https://')!=0){
			url=''+url;
		}
		current_subpanel_url=url;
		var returnstuff=http_fetch_sync(url+'&inline='+inline+'&ajaxSubpanel=true');
		request_id++;
		got_data(returnstuff,inline);
	} else {
		var subpanel=document.getElementById('subpanel_'+child_field);
		subpanel.style.display='';
		set_div_cookie(subpanel.cookie_name,'',module);
		if(current_child_field!=''&&child_field!=current_child_field){
			hideSubPanel(current_child_field);
		}
		current_child_field=child_field;
	}
	if(typeof(url)!='undefined'&&url.indexOf('refresh_page=1')>0){
		document.location.reload();
	}
	
}

function markSubPanelLoaded(child_field){
	child_field_loaded[child_field]=2;
}


function hideSubPanel(child_field){
	var module=get_module_name();
	var subpanel=document.getElementById('subpanel_'+child_field);
	subpanel.style.display='none';
	set_div_cookie(subpanel.cookie_name,'none',module);
}

//var sub_cookie_name=get_module_name()+'_divs';
var sub_cookie_name='_divs';
var temp=Get_Cookie(sub_cookie_name);
var div_cookies=new Array();
if(temp&&typeof(temp)!='undefined'){
	div_cookies=get_sub_cookies(temp);
}

function set_div_cookie(name,display, module){
	div_cookies[name]=display;
	Set_Cookie(module+sub_cookie_name,subs_to_cookie(div_cookies),3000,false,false,false);
}

function local_open_popup(name,width,height,arg1,arg2,arg3,params){
	return open_popup(name,width,height,arg1,arg2,arg3,params);
}


// #########################################################################################################################
// --  Phone Mask and Validation OLD
var dFilterStep

function dFilterStrip (dFilterTemp, dFilterMask)
{
    dFilterMask = replace(dFilterMask,'#','');
    for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++)
		{
		    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
		}
		return dFilterTemp;
}

function dFilterMax (dFilterMask)
{
 		dFilterTemp = dFilterMask;
    for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++)
		{
		 		if (dFilterMask.charAt(dFilterStep)!='#')
				{
		        dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
				}
		}
		return dFilterTemp.length;
}

function dFilter (key, textbox, dFilterMask)
{
		dFilterNum = dFilterStrip(textbox.value, dFilterMask);
		
		if (key==9)
		{
		    return true;
		}
		else if (key==8&&dFilterNum.length!=0)
		{
		 	 	dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
		}
 	  else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) )
		{
        dFilterNum=dFilterNum+String.fromCharCode(key);
		}

		var dFilterFinal='';
    for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++)
		{
        if (dFilterMask.charAt(dFilterStep)=='#')
				{
					  if (dFilterNum.length!=0)
					  {
				        dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
					      dFilterNum = dFilterNum.substring(1,dFilterNum.length);
					  }
				    else
				    {
				        dFilterFinal = dFilterFinal + "";
				    }
				}
		 		else if (dFilterMask.charAt(dFilterStep)!='#')
				{
				    dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); 			
				}
//		    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
		}


		textbox.value = dFilterFinal;
    return false;
}

function replace(fullString,text,by) {
// Replaces text with by in string
    var strLength = fullString.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return fullString;

    var i = fullString.indexOf(text);
    if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
    if (i == -1) return fullString;

    var newstr = fullString.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

    return newstr;
}

// #########################################################################################################################
// --  START Phone Mask and Validation Current
	
	var zChar = new Array('-');
	var maxphonelength = 8;
	var phonevalue1;
	var phonevalue2;
	var cursorposition;

	function ParseForNumber1(object){
		phonevalue1 = ParseChar(object.value, zChar);
	}

	function ParseForNumber2(object){
		phonevalue2 = ParseChar(object.value, zChar);
	}

	function backspacerUP(object,e) {
		if(e){
			e = e
		} else {
			e = window.event
		}
		if(e.which){
			var keycode = e.which
		} else {
			var keycode = e.keyCode
		}

		ParseForNumber1(object)
		if(keycode >= 48){
			ValidatePhone(object)
		}
	}

	function backspacerDOWN(object,e) {
		if(e){
			e = e
		} else {
			e = window.event
		}
		if(e.which){
			var keycode = e.which
		} else {
			var keycode = e.keyCode
		}
		ParseForNumber2(object)
	}

	function GetCursorPosition(){
		var t1 = phonevalue1;
		var t2 = phonevalue2;
		var bool = false
		for (i=0; i<t1.length; i++){
			if (t1.substring(i,1) != t2.substring(i,1)) {
				if(!bool) {
					cursorposition=i
					bool=true
				}
			}
		}
	}

	function ValidatePhone(object){
		var p = phonevalue1
		p = p.replace(/[^\d]*/gi,"")
		if (p.length < 3) {
			object.value=p
		} else if(p.length==3){
			pp=p;
			d4=p.indexOf('-')
			if(d4==-1){
				pp=pp+"-";
			}
			object.value = pp;
		} else if(p.length>3 && p.length < 7){
			l30=p.length;
			p30=p.substring(0,3);

			p31=p.substring(3,l30);
			pp=p30+p31;

			object.value = pp;

		} else if(p.length >= 7){
			l30=p.length;
			p30=p.substring(0,3);
			p30=p30+"-"

			p31=p.substring(3,l30);
			pp=p30+p31;

			object.value = pp.substring(0, maxphonelength);
		}

		GetCursorPosition()

		if(cursorposition >= 0){
			if (cursorposition == 0) {
				cursorposition = 2
			} else if (cursorposition <= 2) {
				cursorposition = cursorposition + 1
			} else if (cursorposition <= 5) {
				cursorposition = cursorposition + 2
			} else if (cursorposition == 6) {
				cursorposition = cursorposition + 2
			} else if (cursorposition == 7) {
				cursorposition = cursorposition + 4
				e1=object.value.indexOf(')')
				e2=object.value.indexOf('-')
				if (e1>-1 && e2>-1){
					if (e2-e1 == 4) {
						cursorposition = cursorposition - 1
					}
				}
			} else if (cursorposition < 11) {
				cursorposition = cursorposition + 3
			} else if (cursorposition == 11) {
				cursorposition = cursorposition + 1
			} else if (cursorposition >= 12) {
				cursorposition = cursorposition
			}

			var txtRange = object.createTextRange();
			txtRange.moveStart( "character", cursorposition);
			txtRange.moveEnd( "character", cursorposition - object.value.length);
			txtRange.select();
		}
	}

	function ParseChar(sStr, sChar){
		if (sChar.length == null){
			zChar = new Array(sChar);
		} else zChar = sChar;
		
		for (i=0; i<zChar.length; i++){
			sNewStr = "";
			var iStart = 0;
			var iEnd = sStr.indexOf(sChar[i]);
			while (iEnd != -1){
				sNewStr += sStr.substring(iStart, iEnd);
				iStart = iEnd + 1;
				iEnd = sStr.indexOf(sChar[i], iStart);
			}
			sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
			sStr = sNewStr;
		}

		return sNewStr;
	}
	
// --  END Phone Mask and Validation Current
// #########################################################################################################################

// -- Only Numbers on Keypress #############################################################################################

	function numbersonly(myfield, e, dec) {
		var key;
		var keychar;

		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;
		else
		   return true;
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) || 
		    (key==9) || (key==13) || (key==27) )
		   return true;
		
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
		   return true;
		
		// decimal point jump
		else if (dec && (keychar == "."))
		   {
		   myfield.form.elements[dec].focus();
		   return false;
		   }
		else
		   return false;
	}


// -- END Numbers Only On Keypress #########################################################################################

function remove_from_subpanels(msg, url, containerid){
	var a = confirm(msg, "Yes", "No")
	if (a == true) {
		ajaxpage(url, containerid);
	}
}

function accept_status_subpanels(msg, url, containerid){
	var a = confirm(msg, "Yes", "No")
	if (a == true) {
		ajaxpage(url, containerid);
	}
}

function DateAdd(startDate, numDays, numMonths, numYears){
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11){
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;
	
}

function suycDateDiff( start, end, interval, rounding ) {
	
	    var iOut = 0;
	
	    var startMsg = "Check the Start Date and End Date\n"
	        startMsg += "must be a valid date format.\n\n"
	        startMsg += "Please try again." ;
	
	    var intervalMsg = "Sorry the dateAdd function only accepts\n"
	        intervalMsg += "d, h, m OR s intervals.\n\n"
	        intervalMsg += "Please try again." ;
	
	    var bufferA = Date.parse( start ) ;
	    var bufferB = Date.parse( end ) ;
	
	    if ( isNaN (bufferA) || isNaN (bufferB) ) {
	        alert( startMsg ) ;
	        return null ;
	    }
	
	    if ( interval.charAt == 'undefined' ) {
	        alert( intervalMsg ) ;
	        return null ;
	    }
	
	    var number = bufferB-bufferA ;
	
	    switch (interval.charAt(0))
	    {
	        case 'd': case 'D':
	            iOut = parseInt(number / 86400000) ;
	            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
	            break ;
	        case 'h': case 'H':
	            iOut = parseInt(number / 3600000 ) ;
	            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
	            break ;
	        case 'm': case 'M':
	            iOut = parseInt(number / 60000 ) ;
	            if(rounding) iOut += parseInt((number % 60000)/30001) ;
	            break ;
	        case 's': case 'S':
	            iOut = parseInt(number / 1000 ) ;
	            if(rounding) iOut += parseInt((number % 1000)/501) ;
	            break ;
	        default:
	        alert(intervalMsg) ;
	        return null ;
	    }
	
	    return iOut ;
	}

function DateDiff(f1, f2, msg){
	var dtCh = "-"

	var dtStr = f1.value;
	var edStr = f2.value;
	
	if(dtStr == '' || edStr == ''){alert("please fill in some dates");return}
	//if(dtStr == ''){alert("please fill in a start date");return}
	//if(edStr == ''){alert("please fill in an end date");return}
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	start_date = strMonth + dtCh + strDay + dtCh + strYear;
		
	pos1=edStr.indexOf(dtCh);
	pos2=edStr.indexOf(dtCh,pos1+1);
	strDay=edStr.substring(0,pos1);
	strMonth=edStr.substring(pos1+1,pos2);
	strYear=edStr.substring(pos2+1);
	end_date = strMonth + dtCh + strDay + dtCh + strYear;
	
	var ierr = 1 ;
	var roundDays = true ;
	
	if(start_date != '') {
	    if(!isNaN(Date.parse( start_date ))) {
	        var s = new Date(Date.parse(start_date)) ;
		    ierr = 0 ;
	    }
	}
	
	if(end_date != '' && ierr != 1) {
		if(!isNaN(Date.parse( end_date ))) {
		    var e = new Date(Date.parse(end_date)) ;
	        var temp = suycDateDiff( s, e, 'd', roundDays ) ;
	        temp++
	     }else{
	        ierr = 1;
	     }
	}else{
		ierr = 1;
	}
	
	if (temp <0) {alert(msg);return};
		return true;
}


function isNumberKey(evt) {
   	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
	    return false;
      return true;
}

function isCurrencyKey(evt) {
   	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
	    return false;
      return true;
}

function setChLength(str, ln){
	var tt = "";
	if (str.length < ln) {
		var t = "";
		for (var i=1; i<ln; i++){
			t += "0";
		}

		tt =  t+str;
	} else {
		tt = str;
	}

	return tt;
}

function centerDiv(divobj){
	alert(divobj);
	standardbody = (document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	var ie=document.all && !window.opera;
	var dom=document.getElementById;
	var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset;
	var scroll_left=(ie)? standardbody.scrollLeft : window.pageXOffset;
	var docwidth=(ie)? standardbody.clientWidth : window.innerWidth-20+window.pageXOffset;
	var docheight=(ie)? standardbody.clientHeight: window.innerHeight;
	var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight; //Full scroll height of document
	var objwidth=divobj.offsetWidth; //width of div element
	var objheight=divobj.offsetHeight; //height of div element
	var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px"; //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
	divobj.style.left=docwidth/2-objwidth/2+"px"; //Center div element horizontally
	divobj.style.top=Math.floor(parseInt(topposition))+"px";
	divobj.style.visibility="visible";
}

function deleteAtom(postfile, id, fld, r, usr) {
	a = confirm("Are you sure you want to delete this file?", "Yes", "No")
	
	if (a == true) {
		$.post(postfile, { id: id, record: r, userid: usr, fldname: fld }, function(data) {
			if(data.status==true){ 
				document.getElementById('divAtom_'+id).innerHTML = '';
				if (document.getElementById(fld) != undefined)
					document.getElementById(fld).value = 0;
			} else {
				alert(data.message);
			}
		}, 'json');
		return false;
	}
}

function stopRKey(evt) { 
	var evt = (evt) ? evt : ((event) ? event : null); 
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
	if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}

/* Browser check */
IS_DOM = (document.getElementById) ? true : false;
IS_IE = (document.all) ? true : false;
IS_IE50 = (navigator.userAgent.indexOf("IE 5.0") != -1);
IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);

// Image Swapping
function changeImages() 
{
  if (document.getElementById) {
    for (var i = 0; i < changeImages.arguments.length; i += 2) { 
  		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i + 1] + ".src"); 
	}
  }
}

// Get an ID 
function getThis(sId)
{
	var oObject;
	oObject = false;
	
	if (IS_DOM) {
		if (document.getElementById(sId)) {
			oObject = document.getElementById(sId);
		}
	}
	
	return oObject;
}

function toTop(id){
	document.getElementById(id).scrollTop=0
}

defaultStep=1
step=defaultStep
function scrollDivDown(id){
	document.getElementById(id).scrollTop+=step
	timerDown=setTimeout("scrollDivDown('"+id+"')",10)
}

function scrollDivUp(id){
	document.getElementById(id).scrollTop-=step
	timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

function toBottom(id){
	document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function toPoint(id){
	document.getElementById(id).scrollTop=100
}

timerDown="" 
timerUp="" 

function stopMe(){
	clearTimeout(timerDown) 
	clearTimeout(timerUp)
}

document.onmousemove=function(){stopMe()} 