var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false;
var visibleError = false;
var firstID = false;

if (document.getElementById) {
  DHTML = true;
  DOM = true;
} else {
  if (document.all) {
    DHTML = true;
    MSIE4 = true;
  } else {
    if (document.layers) {
      DHTML = true;
      NS4 = true;
    }
  }
}
if (window.opera) {
  OP = true;
}

function GetValue(id)
{
         var s; 
         s = getElement('id',id,0);
         if( s ) return s.value;
         return false;
//        return getAttribute ("id",id,0,"value");
}
function TrimValue(id)
{
         var e = getElement("id",id,0);
         var s = TrimString(e.value);
         e.value = s;
          
}

function getElement (Mode, Identifier, ElementNumber) {
  var Element, ElementList;
  if (DOM) {
    if (Mode.toLowerCase() == "id") {
      Element = document.getElementById(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      ElementList = document.getElementsByName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.getElementsByTagName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (MSIE4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document.all(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.all.tags(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document[Identifier];
      if (!Element) {
        Element = document.anchors[Identifier];
      }
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "layerindex") {
      Element = document.layers[Identifier];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}

function getAttributeByElement( Element,AttributeName ) 
{
   if (!Element){
    return false;
   }
   if (DOM || MSIE4) 
   {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
   }
   if (NS4) 
   {
      Attribute = Element[AttributeName]
      if (!Attribute) 
      {
       Attribute = false;
      }
      return Attribute;
    }
    return false;
}

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    Attribute = Element[AttributeName]
    if (!Attribute) {
       Attribute = false;
    }
    return Attribute;
  }
  return false;
}

function getContent (Mode, Identifier, ElementNumber) {
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    } else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) {
    Content = Element.innerText;
    return Content;
  }
  return false;
}

function setContent (Mode, Identifier, ElementNumber, Text) {
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) {
    Element.innerText = Text;
    return true;
  }
  if (NS4) {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
}

function isInteger(object)
{
         if (object_value.length == 0)
         {
		return true;
	 }

	var decimal_format = ".";
	var check_char;


	check_char = object.indexOf(decimal_format)

 	if (check_char < 1) 
        {
	    return isNumeric(object);
	} 
        else 
        {
	    return false;
	}
}

function isAlphaChar(ch)
{
       if( ch == 'Ö' || ch == 'ö') return true;
       if( ch == 'Ä' || ch == 'ä') return true;
       if( ch == 'Ü' || ch == 'ü') return true;
       if( ch == 'ß' ) return true;
       return (ch == '_' || ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ( ch.charCodeAt(0) >= 0x05d0 && ch.charCodeAt(0) <= 0x05ea);
}

function isNumeric(object)
{
	
	if(object.length == 0) 
      {
	   return false;
	}
	
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	
	
	check_char = start_format.indexOf(object.charAt(0))
	if( check_char == 1) 
      {
    	    decimal = true;
	} 
      else 
      if(check_char < 1) 
      {
     	   return false;
	}
	        
	
	for (var i = 1; i < object.length; i++)
	{
		check_char = number_format.indexOf(object.charAt(i))
		if (check_char < 0) 
            {
		    return false;
		} 
            else 
            if(check_char == 1) 
            {
			if (decimal)
                  {	
				return false;
			} 
                  else 
                  {
				decimal = true;
			}
		} 
            else 
            if (check_char == 0)	
            {
			if (decimal || digits) 
                  {
				trailing_blank = true;
			}
			
		} 
            else 
            if (trailing_blank) 
            {
			return false;
		} 
            else 
            {
			digits = true;
		}
	}	
	return true
}


function isNumberChar(ch)
{
 	 return (ch >= '0' && ch <= '9');
}



function isAlphaNumeric(object)
{
	var i;
	var intLength, ch;
	intLength = object.length;
	
	for(i = 0; i < intLength; i++) 
	{
		ch = object.charAt(i);
		if(!(isAlphaChar(ch) || isNumberChar(ch))) 
            {
          	     return false;
		}
	}
	return true;
}

function isAlpha(object_value)
{
	var i;
	var intLength, ch;
	intLength = object_value.length;
	
	for(i = 0; i < intLength; i++) 
	{
	    ch = object_value.charAt(i);
	    if(!isAlphaChar(ch)) 
          {
		  return false;
	    }
	}
	return true;
}



function isPhone(object_value, min_value)
{
	var i, ch, intCount;
	
	var strChars = "_- 0123456789.~*+, ";
	var len = object_value.length;
	if( len == 0) 
      {
	    return false;
	}
	
	if( len < min_value) 
      {
	    return false;
	}
	
	intCount = 0;
	for(i = 0; i < len; i++) 
      {
		ch = object_value.charAt(i);
		
		if( (strChars.indexOf(ch) == -1) ) 
            {    
     		     return false;
		} 
            if( ch != ' ')
                intCount++;
	}
	if( (intCount > 0 && intCount >= min_value ) )
           return true;   
      return false;
}


function isPrice(object_value, min_value)
{
	var i, ch, intCount;
	
	var strChars = "-0123456789.+, ";
	var len = object_value.length;
	if( len == 0) 
      {
	    return false;
	}
	
	if( len < min_value) 
      {
	    return false;
	}
	
	intCount = 0;
	for(i = 0; i < len; i++) 
      {
		ch = object_value.charAt(i);
		
		if( (strChars.indexOf(ch) == -1) ) 
            {    
     		     return false;
		} 
            if( ch != ' ')
                intCount++;
	}
	if( (intCount > 0 && intCount >= min_value ) )
           return true;   
      return false;
}

function isEmail(object_value, min_value)
{
	var i, ch, intAtCount, intDotPos, intLastDotPos;
	
	var strEmailChars = "_-@.~!#$%&*+\"'"

	var len = object_value.length;

	if( len == 0) 
      {
	    return false;
	}
	
	if( len < min_value) 
      {
	    return false;
	}
	
	intAtCount = 0;
	intDotPos = 0;
	for(i = 0; i < len; i++) 
      {
		ch = object_value.charAt(i);
		
		if(!(	isAlphaChar(ch) || 
			isNumberChar(ch) ||
			strEmailChars.indexOf(ch) != -1) ) 
                {
			return false;
		} 
                else
                {
			if(ch == '@') 
                        {
			   intAtCount++;
			   if(intAtCount > 1) 
                           {
			      return false;
			   }
			} 
                        else 
                        if( ch == '.') 
                        {
			    if (i - 1 == intLastDotPos) 
                            {
			       	return false;
			    }
			    intDotPos = i;
			    intLastDotPos = i;
			}
		}
	}
	return (intDotPos > 0 && intAtCount > 0 && intDotPos < (len - 1));
}


function isURL(object_value)
{
	var i, ch, intDotCount;
	
	var strURLChars = "~!@#$%*_+-:/.?&="
	
	var len = object_value.length;
	
	if (object_value.length == 0) {
		return true;
	}
	
	if (object_value.length < 10) {
		return false;
	}
	
	if	((object_value.indexOf("http://") == -1) &&
			(object_value.indexOf("https://") == -1) &&
			(object_value.indexOf("ftp://") == -1)) {
		return false;
	}
	
	intDotCount = 0;
	for(i = 0; i < len; i++) {
		ch = object_value.charAt(i);
		
		if(!(	isAlphaChar(ch) || 
				isNumberChar(ch) ||
				strURLChars.indexOf(ch) != -1) 
			) {
				return false;
		} else if(ch == '.') {
			intDotCount++;
		} 
	}
	
	return (intDotCount > 0);
	
}

function isValidExtension(object_value, extensions)
{
	

	var i, ch, intDotCount;
	var test_extension = "";
	var obj_extension = "";
	var len = object_value.length;

	if ((object_value == "") || (extensions == ""))
		return true;
		 
	for( i = len; i > 0; i--) 
        {
	     ch = object_value.charAt(i);
	     if (ch == '.') 
             {
		 intDotCount = i;
		 break;
	     }
	}	
	
	for (i = (intDotCount + 1); i < len; i++) 
        {
		obj_extension = obj_extension + object_value.charAt(i);
	}

	if (obj_extension.length == 0)
		return false;


	extensions = extensions.toLowerCase();
	obj_extension = obj_extension.toLowerCase();

	len = extensions.length;
	test_extension = "";

	for (i = 0; i <= len; i++) 
        {

		ch = extensions.charAt(i);

		if ((ch == ',') || (ch == ' ') || (i == len)) 
                {
			if (test_extension.length == 0)
				continue;			
			if (test_extension == obj_extension)
				return true;
			test_extension = "";
		}
		else 
                {
			test_extension = test_extension + ch;
		}
	}
	return false;
}

function TrimString(s)
{
     return ValidatorTrim(s);
}

function ValidatorTrim(str) 
{
    var m = str.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function ValidateStrLength(control,minLength)
{
         var value = ValidatorTrim(control);
         if( value.length >= minLength )
             return true;
         return false;
}
function ValidateString(control)
{
         var value = ValidatorTrim(control);
         if( value == "")
             return false;         
         return isAlphaNumeric(control); 
}

function ValidateNumeric(control)
{                
         var value = ValidatorTrim(control);
         if( value == "")
             return false; 
         return isNumeric(value); 
}

function ValidateEMail(control)
{
         var value = ValidatorTrim(control);
         if( value == "")
             return false; 
         return isEmail(value); 
}

function getExtension(id) 
{
         var ext = getElement('id',id,0).value;
         if( ext.length == 0 )
             return false;
         ext = ext.substring(ext.length-3,ext.length);
         ext = ext.toLowerCase();
         return ext;
}

function showElem(idtoShow,show)
{
         var elem;
         elem = getElement("id",idtoShow,0);
         if( elem ) 
         { 
             if( show )
                 elem.style.display = 'block';
             else
                 elem.style.display = 'none';
         }
}

function colorElem(idtoShow)
{
         var elem;
         elem = getElement("id",idtoShow,0);
         if( elem ) 
         { 
             elem.style.display = 'block';
         }
}

function setInnerValue(idTo,val)
{     
         setContent("id",idTo,0,val);
}

function setBackgroundColor(idto,color)
{
         elem = getElement("id",idto,0);
         if( elem ) 
         { 
             elem.style.backgroundColor  = color;
         }
}
function setBorderColor(idto,color)
{
         elem = getElement("id",idto,0);
         if( elem ) 
         { 
             elem.style.borderColor  = color;
         }
}

function getInnerValue(idTo)
{     
         return getContent("id",idTo,0);
}

function showhide(idshow,idhide)
{
       var elemHide,elemShow;
       elemShow = getElement("id",idshow,0);
       elemHide = getElement("id",idhide,0);

       if( elemHide ) elemHide.style.display = 'none';
       if( elemShow ) elemShow.style.display = 'block';
}
function copyValue(to,from)
{
       var elemFrom,elemTo;
       elemFrom = getElement("id",from,0);
       elemTo   = getElement("id",to,0);
       elemTo.value = elemFrom.value;       
}


