﻿// JScript File

function trimString(str) {
    if(str != null) {
        var newStr = str.replace(/^\s*/, '').replace(/\s*$/, ''); 
        if(newStr != '') {
            return newStr;
        }
    }

    return null;
}
	
function redirect(targetURL) {
    window.location.href = targetURL;
}

function BaseValidator(controlName, errorMessage) {
	this.controlName = controlName;
	this.errorMessage = errorMessage;
	
	this.init = function(controlName, errorMessage) {
		this.controlName = controlName;
		this.errorMessage = errorMessage;
	}
	
	this.trim = function(str) {
		if(str != null) {
			var newStr = str.replace(/^\s*/, '').replace(/\s*$/, ''); 
			if(newStr != '') {
				return newStr;
			}
		}
		
		return null;
	}
	
	this.displayErrorMessage = function() {
		alert(this.errorMessage);
	}
}

function UserNameValidator(controlName, nullMessage, invalidMessage) {
	this.init(controlName, nullMessage);
	this.nullMessage = nullMessage;
	this.invalidMessage = invalidMessage;
	
	this.isValid = function() 
	{

		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled)
		{
			return true;
		}
		var userName = this.trim(control[0].value);
		if(userName != null) 
		{
		    var pattern = '^\\w+$';
		    var regex = new RegExp(pattern);
		    if(regex.test(userName)) 
		    {
		        return true;
		    } 
		    else 
		    {
		        this.errorMessage = this.invalidMessage;
		    }
		} 
		else 
		{
		    this.errorMessage = this.nullMessage;
		}
    
		control[0].focus();
		return false;
    }
}
UserNameValidator.prototype = new BaseValidator();
UserNameValidator.prototype.constructor = UserNameValidator;
UserNameValidator.superclass = BaseValidator.prototype;

function TextValidator(controlName, errorMessage) {
	this.init(controlName, errorMessage);
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
		
		if(this.trim(control[0].value) != null) {
			return true;
		}

		control[0].focus();
		return false;
	}
}
TextValidator.prototype = new BaseValidator();
TextValidator.prototype.constructor = TextValidator;
TextValidator.superclass = BaseValidator.prototype;

function EmailValidator(controlName, invalidMessage) {
	this.init(controlName, invalidMessage);
	this.invalidMessage = invalidMessage
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
		
		if(control[0].value != null)
		{
		    var controlValue = this.trim(control[0].value);
			if(controlValue != null) 
			{
				// /^\s*[A-Za-z0-9._]+@[a-zA-Z0-9-]+\.[A-Za-z]{2,}\.?([A-Za-z]{2,4})?\s*$/
				if(/^\s*[A-Za-z0-9]+([._-](_*[a-zA-Z0-9]+))*@[A-Za-z0-9]+([._-](_*[a-zA-Z0-9]+))*\.[A-Za-z]{2,4}\s*$/.test(controlValue)) 
				{
			       	if(controlValue.substring(controlValue.length, controlValue.length - 1) == '.')
			        {
			            this.errorMessage = this.invalidMessage;
			        }
			        else
			        {
			            return true;
			        }
				} 
			    else 
			    {
			            this.errorMessage = this.invalidMessage;
			    }
			}
			else
			{
			    return true;
			}
		}
		else 
		{
		    return true;
		}

		control[0].focus();
		return false;
	}
}
EmailValidator.prototype = new BaseValidator();
EmailValidator.prototype.constructor = EmailValidator;
EmailValidator.superclass = BaseValidator.prototype;

function WebSiteValidator(controlName, invalidMessage) {
	this.init(controlName, invalidMessage);
	this.invalidMessage = invalidMessage
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
		
		if(control[0].value != null)
		{
		
		    var controlValue = this.trim(control[0].value);
            if(controlValue != null) 
            {
                if(/^(((h|H?)(t|T?)(t|T?)(p|P?)(s|S?))\:\/\/)?(www\.[a-zA-Z0-9]+\.[A-Za-z]{2,3}\.?([A-Za-z]{2})?)*$/.test(controlValue)) 
                {
                   if(controlValue.substring(controlValue.length, controlValue.length - 1) == '.')
                   {
                       this.errorMessage = this.invalidMessage;
                   }
                   else
                   {
                       return true;
                   }
                }
                else
                {
                 this.errorMessage = this.invalidMessage;
                }
                   
            }
			else
			{
			    return true;
			}
		}
		else 
		{
		    return true;
		}

		control[0].focus();
		return false;
	}
}
WebSiteValidator.prototype = new BaseValidator();
WebSiteValidator.prototype.constructor = WebSiteValidator;
WebSiteValidator.superclass = BaseValidator.prototype;

function DateValidator(controlName, invalidMessage) {
	this.init(controlName, invalidMessage);
	this.invalidMessage = invalidMessage
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
		
		if(control[0].value != null)
		{
		    var controlValue = this.trim(control[0].value);
			if(controlValue != null) 
			{
			    var date;
			    if (controlValue.indexOf('-') != -1)
			    {
			         date = controlValue.split('-');
			    }  
                if (controlValue.indexOf('/') != -1)
			    {
			         date = controlValue.split('/');
			    }  
                if(date == null)
                {
                    this.errorMessage = this.invalidMessage;
                }   
                else if (date.length != 3)
                {
                    this.errorMessage = this.invalidMessage;
                }
               else
               {  
                    var dateVal = date[0] + "/" + date[1]+ "/" + date[2];
                    var dt = new Date(dateVal);

                    if(dateVal.length < 10)
                    {
                        this.errorMessage = this.invalidMessage;
                    }
                    else if(dt.getDate() != date[1])
                    {
                        this.errorMessage = this.invalidMessage;
                    }
                    else if(dt.getMonth() != date[0]-1)
                    {
                    //this is for the purpose JavaScript starts the month from 0
                        this.errorMessage = this.invalidMessage;
                    }
                    else if(dt.getFullYear() != date[2])
                    {
                        this.errorMessage = this.invalidMessage;
                    }
                   else
                   {  
                    return true;			
                   } 
                } 
            }
			else
			{
			    return true;
			}
		}
		else 
		{
		    return true;
		}

		control[0].focus();
		return false;
	}
}
DateValidator.prototype = new BaseValidator();
DateValidator.prototype.constructor = DateValidator;
DateValidator.superclass = BaseValidator.prototype;

function CurrentDateValidator(expiryDate, invalidMessage)
{
    this.isValid = function()
    {
        var currentTime = new Date();
        var month = currentTime.getMonth() + 1;
        var day = currentTime.getDate();
        var year = currentTime.getFullYear();

        var currentDate = month + "/" + day + "/" + year;
        
        var toDate = document.getElementsByName(expiryDate);
        var toDateVal = toDate[0].value;
        
        toDateVal = toDateVal.replace('-','/').replace('-','/');
        
        if (Date.parse(currentDate) > Date.parse(toDateVal)) 
        {
            this.errorMessage = invalidMessage;
            toDate[0].focus();
        }
        else
        {
            return true;
        }
	}
}

CurrentDateValidator.prototype = new BaseValidator();
CurrentDateValidator.prototype.constructor = CurrentDateValidator;
CurrentDateValidator.superclass = BaseValidator.prototype;

function FromToDateRequiredValidator(strFromDate, strToDate, invalidMessage1, invalidMessage2)
{
    this.isValid = function()
    {
        var fromDate = document.getElementsByName(strFromDate);
        var fromDateVal = fromDate[0].value;
        
        fromDateVal = fromDateVal.replace('-','/').replace('-','/');
        
        var toDate = document.getElementsByName(strToDate);
        var toDateVal = toDate[0].value;
        
        toDateVal = toDateVal.replace('-','/').replace('-','/');
        
        if(fromDateVal != '' || toDateVal != '')
        {
            if(fromDateVal == '')
            {
                this.errorMessage = invalidMessage1;
                fromDate[0].focus();
                return false;                    
            }
            else if(toDateVal == '')
            {
                this.errorMessage = invalidMessage2;
                toDate[0].focus();
                return false;                
            }            
        }
        return true;
    }
}
FromToDateRequiredValidator.prototype = new BaseValidator();
FromToDateRequiredValidator.prototype.constructor = FromToDateRequiredValidator;
FromToDateRequiredValidator.superclass = BaseValidator.prototype;

function FromToDateValidator(strFromDate, strToDate, invalidMessage)
{
    this.isValid = function()
    {
        var fromDate = document.getElementsByName(strFromDate);
        var fromDateVal = fromDate[0].value;
        
        fromDateVal = fromDateVal.replace('-','/').replace('-','/');
        
        var toDate = document.getElementsByName(strToDate);
        var toDateVal = toDate[0].value;
        
        toDateVal = toDateVal.replace('-','/').replace('-','/');
        
        if (Date.parse(fromDateVal) > Date.parse(toDateVal)) 
        {
            this.errorMessage = invalidMessage;
            toDate[0].focus();
            return false;
        }
        else
        {
            return true;
        }
	}
}

FromToDateValidator.prototype = new BaseValidator();
FromToDateValidator.prototype.constructor = FromToDateValidator;
FromToDateValidator.superclass = BaseValidator.prototype;

function TimeValidator(controlName, invalidMessage)
{
    this.isValid = function()
    {
		var timePat = /^((0[1-9]|1[0-2])(:)([0-5][0-9])(\s(AM|am|PM|pm)))$/;
        var control = document.getElementsByName(controlName);
        var controlVal = control[0].value;
        var matchArray = controlVal.match(timePat);
        
        if (matchArray == null)
        {
            this.errorMessage = invalidMessage;
            control[0].focus();
        }
        else
        {
            return true;
        }
    }
}

TimeValidator.prototype = new BaseValidator();
TimeValidator.prototype.constructor = TimeValidator;
TimeValidator.superclass = BaseValidator.prototype;

function CompareControlsHasValue(firstControlName, secondControlName, thirdControlName, thirdValue, invalidMessage)
{   
    this.isValid = function()
    {
        var firstControl = document.getElementsByName(firstControlName);
        var secondControl = document.getElementsByName(secondControlName);
        var thirdControl = document.getElementsByName(thirdControlName);
    
        var firstControlVal = firstControl[0].value;
        var secondControlVal = secondControl[0].value;
        var thirdControlVal = thirdControl[0].value;
        
        if((firstControlVal != '' || secondControlVal != '') && thirdControlVal == thirdValue)
        {   
            if(firstControlVal != '')
            {
                firstControl[0].focus();
            }
            else if(secondControlVal != '')
            {
                secondControl[0].focus();
            }
            
            this.errorMessage = invalidMessage;
        }
        else
        {
            return true;
        }
    }
}
CompareControlsHasValue.prototype = new BaseValidator();
CompareControlsHasValue.prototype.constructor = CompareControlsHasValue;
CompareControlsHasValue.superclass = BaseValidator.prototype;


function CheckboxValidator(controlName, errorMessage) {
    this.init(controlName, errorMessage);
    
    this.isValid = function() {
        var checkbox = document.getElementsByName(this.controlName);
        for(var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].checked && (!checkbox[i].disabled)) {
                return true;
             }
        }
        
        return false;
    }
}
CheckboxValidator.prototype = new BaseValidator();
CheckboxValidator.prototype.constructor = CheckboxValidator;
CheckboxValidator.superclass = BaseValidator.prototype;


//Checks whether the form input element is a valid Phone Number (USA)
//paramValue-Value of the Form Item
function PhoneValidator(controlName, nullMessage, invalidMessage)
{
	this.init(controlName, nullMessage);
	this.nullMessage = nullMessage;
	this.invalidMessage = invalidMessage
	
	this.isValid = function() 
	{
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) 
		{
			return true;
		}
		
		if(control[0].value != null) 
		{
		    var controlValue = this.trim(control[0].value);
			if(controlValue != null) 
			{
                this.errorMessage = this.invalidMessage;

                var expIsPhoneFormat1 = /^\(\d{3}\)\d{3}\-\d{4}$/;
                var expIsPhoneFormat2 = /^\d{3}\-\d{3}\-\d{4}$/;
                var expIsPhoneFormat3 = /^\(\d{3}\) \d{3}\-\d{4}$/;

                if( (expIsPhoneFormat1.test(controlValue) || expIsPhoneFormat2.test(controlValue) || expIsPhoneFormat3.test(controlValue)))
                 {
	                return true;
		         }
		         
                this.errorMessage = this.invalidMessage;
             }
             else
             {
                return true;
             }
        }
        else
        {
            return true;
        }
                        
        control[0].focus();
	    return false;
    }
}

PhoneValidator.prototype = new BaseValidator();
PhoneValidator.prototype.constructor = PhoneValidator;
PhoneValidator.superclass = BaseValidator.prototype;


function DropDownsValidator(firstControlName, secondControlName, firstDrpEmptyMsg, secondDrpEmptyMsg)
{
	this.isValid = function() 
	{
        var firstControl = document.getElementsByName(firstControlName);
        var secondControl = document.getElementsByName(secondControlName);

        var firstControlVal = parseInt(getValue(firstControl[0].value));
        var secondControlVal = parseInt(getValue(secondControl[0].value));

            if (firstControlVal != -1 || secondControlVal != -1)
        {
            if (firstControlVal == -1)
            {
                this.errorMessage = firstDrpEmptyMsg;
                firstControl[0].focus();
                return false;
            }
            
            if (secondControlVal == -1)
            {
                this.errorMessage = secondDrpEmptyMsg;
                secondControl[0].focus();
                return false;
            }
        }
        return true;
    }
}

DropDownsValidator.prototype = new BaseValidator();
DropDownsValidator.prototype.constructor = DropDownsValidator;
DropDownsValidator.superclass = BaseValidator.prototype;

function CompareControlValidator(firstControlName, secondControlName, errorMsg)
{
 	this.isValid = function() 
	{
        var firstControl = document.getElementsByName(firstControlName);
        var secondControl = document.getElementsByName(secondControlName);
        
        var firstControlVal = parseInt(getValue(firstControl[0].value));
        var secondControlVal = parseInt(getValue(secondControl[0].value));
        
        if(firstControlVal < secondControlVal)
        {
            this.errorMessage = errorMsg;
            secondControl[0].focus();
            return false;
        }
        return true;
    }
}

CompareControlValidator.prototype = new BaseValidator();
CompareControlValidator.prototype.constructor = CompareControlValidator;
CompareControlValidator.superclass = BaseValidator.prototype;

function CompareValueValidator(firstValue, secondValue, controlName, invalidErrorMessage)
{
    this.isValid = function() 
    {        
        if(firstValue > secondValue)
        {   
            var control = document.getElementsByName(controlName);
            this.errorMessage = invalidErrorMessage;
            control[0].focus();
            return false;
        }
        else
        {
            return true;
        }
    }
}
CompareValueValidator.prototype = new BaseValidator();
CompareValueValidator.prototype.constructor = CompareValueValidator;
CompareValueValidator.superclass = BaseValidator.prototype;

function RadioValidator(controlName, errorMessage) {
    this.init(controlName, errorMessage);
    
    this.isValid = function() {
        var checkbox = document.getElementsByName(this.controlName);
        for(var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].checked && (!checkbox[i].disabled)) {
                return true;
             }
        }
        
        return false;
    }
    
    this.getValue = function() {
        var checkbox = document.getElementsByName(this.controlName);
        for(var i = 0; i < checkbox.length; i++) {
            if(checkbox[i].checked && (!checkbox[i].disabled)) {
                return checkbox[i].value;
             }
        }
        
        return '';
    }
}
RadioValidator.prototype = new BaseValidator();
RadioValidator.prototype.constructor = RadioValidator;
RadioValidator.superclass = BaseValidator.prototype;



function PasswordValidator(password1, password2, nullMessage, mismatchedMessage) {
	//this.init(null, nullMessage);
	this.nullMessage = nullMessage;
	this.mismatchedMessage = mismatchedMessage;
	this.password1 = password1;
	this.password2 = password2;
	
	this.isValid = function() 
	{
	    var p1Control = document.getElementsByName(this.password1)[0];
	    var p2Control = document.getElementsByName(this.password2)[0];
	    
		var p1 = this.trim(p1Control.value);

		if(p1 == null) 
		{
		    this.errorMessage = this.nullMessage;
		    p1Control.focus();
		}
		else
		{
		    var p2 = this.trim(p2Control.value);
		    if(p2 != null && p1 == p2)
		    {
			    return true;
		    }
		    else 
		    {
		        this.errorMessage = this.mismatchedMessage;
		        p2Control.focus();
		    }
		}
		
		return false;
	}
}
PasswordValidator.prototype = new BaseValidator();
PasswordValidator.prototype.constructor = PasswordValidator;
PasswordValidator.superclass = BaseValidator.prototype;





function getFCKeditor(controlName) {
    try {
        return FCKeditorAPI.GetInstance(controlName);
    } catch(err) {
        return null;
    }
}

function FCKEditorValidator(controlName, errorMessage) {
	this.init(controlName, errorMessage);
	
	this.isValid = function() {
        //var FCKeditor = FCKeditorAPI.GetInstance(this.controlName);
        var FCKeditor = getFCKeditor(this.controlName);
        if(FCKeditor != null) {
            if(this.trim(FCKeditor.GetXHTML()) != null) {
                return true;
            }
        } else {
            var control = document.getElementsByName(this.controlName);
		    if(control[0].disabled) {
			    return true;
		    }
    		
		    if(this.trim(control[0].value) != null) {
			    return true;
		    }

		    control[0].focus();
        }


		return false;
	}
}
FCKEditorValidator.prototype = new BaseValidator();
FCKEditorValidator.prototype.constructor = FCKEditorValidator;
FCKEditorValidator.superclass = BaseValidator.prototype;

function MinMaxValidator(controlName, errorMessage, minValue, maxValue)  {
	this.init(controlName, errorMessage);
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
                
		if(this.trim(control[0].value) != null) {
		    if(isFloat(this.trim(control[0].value)) && this.trim(control[0].value) >= minValue && this.trim(control[0].value) <= maxValue)
	        {
                return true;
	        }
		}
		else
		{
		    return true;
		}
		
        control[0].focus();
		return false;
	}
}
MinMaxValidator.prototype = new BaseValidator();
MinMaxValidator.prototype.constructor = MinMaxValidator;
MinMaxValidator.superclass = BaseValidator.prototype;

function MaxValidator(controlName, errorMessage, controlValue, maxValue)  {
	this.init(controlName, errorMessage);
	
	this.isValid = function() {
        var control = document.getElementsByName(this.controlName);
            
        if(controlValue <= maxValue)
        {
            return true;
        }
		
        control[0].focus();
		return false;
	}
}
MaxValidator.prototype = new BaseValidator();
MaxValidator.prototype.constructor = MaxValidator;
MaxValidator.superclass = BaseValidator.prototype;

function MinValidator(controlName, errorMessage, controlValue, minValue)  
{
	this.init(controlName, errorMessage);
	
	this.isValid = function() 
	{
        var control = document.getElementsByName(this.controlName);
        
        if(controlValue >= 0)
        {        
            if(controlValue < minValue)
            {
                control[0].focus();
		        return false;                        
            }    
        }		
        return true;
	}
}
MinValidator.prototype = new BaseValidator();
MinValidator.prototype.constructor = MinValidator;
MinValidator.superclass = BaseValidator.prototype;

function TypeValidator(controlName, errorMessage, dataType)  {
	this.init(controlName, errorMessage);
	
	this.isValid = function() {
		var control = document.getElementsByName(this.controlName);
		if(control[0].disabled) {
			return true;
		}
                
		if(this.trim(control[0].value) != null) {
		
		    if(dataType == "Numeric")
		    {
		        if(isNumeric(this.trim(control[0].value)))
		        {
		            return true;
		        }
		    }
		    else if(dataType == "Float")
		    {
		        if(isFloat(this.trim(control[0].value)))
		        {
                    return true;
		        }
		    }
            else if(dataType == "Char")
		    {
		        if(isChar(this.trim(control[0].value)))
                {
		            return true;
		        }

		    }
		    else if(dataType == "AlphaNumeric")
		    {
		        if(isValidAlphaNumeric(this.trim(control[0].value)))
                {
		            return true;
		        }
		    }
		}
		else
		{
		    return true;
		}
		
        control[0].focus();
		return false;
	}
}
TypeValidator.prototype = new BaseValidator();
TypeValidator.prototype.constructor = TypeValidator;
TypeValidator.superclass = BaseValidator.prototype;

function DropDownsThreeValidator(firstControlName, secondControlName, thirdControlName, firstDrpEmptyMsg, secondDrpEmptyMsg, thirdDrpEmptyMsg)
{
	this.isValid = function() 
	{
        var firstControl = document.getElementsByName(firstControlName);
        var secondControl = document.getElementsByName(secondControlName);
        var thirdControl = document.getElementsByName(thirdControlName);

        var firstControlVal = parseInt(getValue(firstControl[0].value));
        var secondControlVal = parseInt(getValue(secondControl[0].value));
        var thirdControlVal = parseInt(getValue(thirdControl[0].value));
        
            if (firstControlVal != -1 || secondControlVal != -1 || thirdControlVal != -1)
        {
            if (firstControlVal == -1)
            {
                this.errorMessage = firstDrpEmptyMsg;
                firstControl[0].focus();
                return false;
            }
            
            if (secondControlVal == -1)
            {
                this.errorMessage = secondDrpEmptyMsg;
                secondControl[0].focus();
                return false;
            }
            
            if (thirdControlVal == -1)
            {
                this.errorMessage = thirdDrpEmptyMsg;
                thirdControl[0].focus();
                return false;
            }
        }
        return true;
    }
}

DropDownsThreeValidator.prototype = new BaseValidator();
DropDownsThreeValidator.prototype.constructor = DropDownsThreeValidator;
DropDownsThreeValidator.superclass = BaseValidator.prototype;

function IsAnyRecordEntered(controlsName)  {
	var hasValue = false;	
	
	var strControlName = controlsName.split(',');
	
    for (counter = 0; counter < strControlName.length; counter++)
    {
	    var control = document.getElementsByName(this.trim(strControlName[counter]));
		
	    if(! control[0].disabled) 
	    {
		    if(! isEmpty(control[0].value)) 
		    {
               hasValue = true;  
               break;                   
		    }
	    }
    }
    
    return hasValue;
}


function IsAnyRadioChecked(controlsName)  
{
	var hasValue = false;	
	var strControlName = controlsName.split(',');
	
    for (counter = 0; counter < strControlName.length; counter++)
    {
	    var radio = document.getElementsByName(this.trim(strControlName[counter]));
        
        for (count = 0; count < radio.length; count++)
        {
            if (radio[count].checked)            
		    {
		        hasValue = true;
		        break; 
		    }
		}
    }
    
    return hasValue;
}
function isEmpty(paramValue)
{
	var expIsEmpty=/[^ ^\r^\n ]/;
	return  ! expIsEmpty.test(paramValue);
}

function isNumeric(paramValue)
{
  	var expIsNumeric=/[^0-9]/;
  	return ! expIsNumeric.test(paramValue);
}

function isFloat(paramValue)
{
	var expIsFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
	return expIsFloat.test(paramValue);
}

function isChar(paramValue)
{
  	var expIsChar=/[^a-zA-Z ]/;
  	return ! expIsChar.test(paramValue);
}

function isValidAlphaNumeric(paramValue)
{
  	var expisValidAlphaNumeric = /[^a-zA-Z0-9]/;
  	return ! expisValidAlphaNumeric.test(paramValue);
}


function FormValidator() {
	this.validatorArray = new Array();
	
	this.addValidator = function(validator) {
		this.validatorArray.push(validator);
	}
	
	this.validate = function() {
		for(var i = 0; i < this.validatorArray.length; i++) {
			var obj = this.validatorArray[i];
			if(! obj.isValid()) {
				obj.displayErrorMessage();
				return false;
			}
		}
		return true;
	}
}

function initBrowserDetect() {
    var BrowserDetect = {
	    init: function () {
		    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		    this.version = this.searchVersion(navigator.userAgent)
			    || this.searchVersion(navigator.appVersion)
			    || "an unknown version";
		    this.OS = this.searchString(this.dataOS) || "an unknown OS";
	    },
	    searchString: function (data) {
		    for (var i=0;i<data.length;i++)	{
			    var dataString = data[i].string;
			    var dataProp = data[i].prop;
			    this.versionSearchString = data[i].versionSearch || data[i].identity;
			    if (dataString) {
				    if (dataString.indexOf(data[i].subString) != -1)
					    return data[i].identity;
			    }
			    else if (dataProp)
				    return data[i].identity;
		    }
	    },
	    searchVersion: function (dataString) {
		    var index = dataString.indexOf(this.versionSearchString);
		    if (index == -1) return;
		    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	    },
	    dataBrowser: [
		    {
			    string: navigator.vendor,
			    subString: "Apple",
			    identity: "Safari"
		    },
		    {
			    prop: window.opera,
			    identity: "Opera"
		    },
		    {
			    string: navigator.vendor,
			    subString: "iCab",
			    identity: "iCab"
		    },
		    {
			    string: navigator.vendor,
			    subString: "KDE",
			    identity: "Konqueror"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "Firefox",
			    identity: "Firefox"
		    },
		    {	// for newer Netscapes (6+)
			    string: navigator.userAgent,
			    subString: "Netscape",
			    identity: "Netscape"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "MSIE",
			    identity: "Explorer",
			    versionSearch: "MSIE"
		    },
		    {
			    string: navigator.userAgent,
			    subString: "Gecko",
			    identity: "Mozilla",
			    versionSearch: "rv"
		    },
		    { 	// for older Netscapes (4-)
			    string: navigator.userAgent,
			    subString: "Mozilla",
			    identity: "Netscape",
			    versionSearch: "Mozilla"
		    }
	    ],
	    dataOS : [
		    {
			    string: navigator.platform,
			    subString: "Win",
			    identity: "Windows"
		    },
		    {
			    string: navigator.platform,
			    subString: "Mac",
			    identity: "Mac"
		    },
		    {
			    string: navigator.platform,
			    subString: "Linux",
			    identity: "Linux"
		    }
	    ]

    };
    BrowserDetect.init();
    
    return BrowserDetect;
}

function getValue(str)
{
		if(str != null) 
		{
			var newStr = str.replace(/^\s*/, '').replace(/\s*$/, ''); 
			if(newStr != '') 
			{
				return newStr;
            }
		}
		return -1;
}
