/**** all jquery-funtions ****/
$(document).ready(function() {
  $('a.prdlookup').cluetip({sticky: true, closePosition: 'title', arrows: true});
  
  $('a.clientlookup').cluetip({width: '400px', sticky: true, closePosition: 'title', arrows: true});
  
  $('#houdini').cluetip({
    splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
                     // ...and split the contents into separate divs where there is a "|"
    showTitle: false // hide the clueTip's heading
  });
  //round to correct money display in textfields
  $('.money').text(function(index,value){
	  return($().number_format(value,{
		  numberOfDecimals:2,
          decimalSeparator: '.',
          thousandSeparator: '',
          symbol: ''}));
  });
  //round to correct money display in input fields
  $('.money_input').val(function(index,value){
	  return($().number_format(value,{
		  numberOfDecimals:2,
          decimalSeparator: '.',
          thousandSeparator: '',
          symbol: ''}));
  });
//round to correct % display in textfields
  $('.percentage').text(function(index,value){
	  return($().number_format(value,{
		  numberOfDecimals:2,
          decimalSeparator: '.',
          thousandSeparator: '',
          symbol: ''}));
  });
  //round to correct % display in input fields
  $('.percentage_input').val(function(index,value){
	  return($().number_format(value,{
		  numberOfDecimals:2,
          decimalSeparator: '.',
          thousandSeparator: '',
          symbol: ''}));
  });
});

$(function() {
		$('#datepicker,#datepicker2,#datepicker3').datepicker({
			changeMonth: true,
			changeYear: true,
			yearRange:'1900:2100'
		});
		
		$("#dialog-message-error").dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
		$("#dialog-message-info").dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
		$("#dialog-message-confirm").dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
});

/**** AJAX framework ***************/
/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ // Check to see if this object has not
										// already been added to page before
										// proceeding
if (file.indexOf(".js")!=-1){ // If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ // If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " // Remember this object as being already added to page
}
}
}

/********************* script framework ******************************/
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
	  //alert(IsNumber);
   return IsNumber;
}
/*******************************************************************************/

function get_formdate(){
    p_caller = arguments[0];
	if (arguments[1] == null)
		p_yearoffset = 0;
    else p_yearoffset = arguments[1];
    jetzt = new Date();
    Tag = jetzt.getDate();
    Monat = jetzt.getMonth()+1;
    if (Monat.length == 1) Monat= '0' + Monat;
    Jahr = jetzt.getFullYear();
	Jahr= Jahr+p_yearoffset;
    Heute = Jahr + '-' + Monat + '-' + Tag;
    eval("document."+p_caller+".value = Heute;");
}
/********************* needed for setting form values ************/
/** caused by compatibility-problems with MACs                  **/
function callBack(theForm, theElement, theValue) {
  document.forms[theForm].elements[theElement].value = theValue;
}
/******************* check geman date *******************************/
function gueltigesDatum (datum)
{
    //(Schritt 1) Fehlerbehandlung
 if (!datum) return false;
 datum=datum.toString();

    //(Schritt 2) Aufspaltung des Datums
 datum=datum.split(".");
 if (datum.length!=3) return false;

    //(Schritt 3) Entfernung der fuehrenden Nullen und Anpassung des Monats
 if (datum[0].length==1) return false;
 if (datum[1].length==1) return false;
 
 datum[0]=parseInt(datum[0],10);
 datum[1]=parseInt(datum[1],10)-1;
    //(Schritt 4) Behandlung Jahr nur zweistellig
 if (datum[2].length==2) return false; //datum[2]="20"+datum[2];

    //(Schritt 5) Erzeugung eines neuen Dateobjektes
 var kontrolldatum=new Date(datum[2],datum[1],datum[0]);

    //(Schritt 6) Vergleich, ob das eingegebene Datum gleich dem JS-Datum ist
 if (kontrolldatum.getDate()==datum[0] && kontrolldatum.getMonth()==datum[1] && kontrolldatum.getFullYear()==datum[2])
     return true; else return false;

}

/** 'borrowed' from mysqladmin framework **/

/**
 * 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 setPointer(theRow, theRowNum, theAction, theDefaultColor, 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 {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3
	if (currentColor == null) {
		currentColor='';
	}	
	
//alert("_"+currentColor+"_");
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.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') {
            newColor              = theDefaultColor;
        }
        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
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {

        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5
    return true;
} // end of the 'setPointer()' function
 

