function isEmpty (s) {
	if ( s == "" || s == null ) {
		return true;
	}
	return false;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

// CheckIsDollar - Checks to see if the entered value is a number representing a monitry value.
function CheckIsDollar(e){
  var msg1 = "Please enter a currency value, dollar sign is not required.";
  var msg2 = "Not a valid number please re-enter";
  var newStr = "";
  var s = e.value;
  if ( s.charAt(0) == "$" ){
    for ( var i = 1; i < (s.length); i++){
      var c = s.charAt(i);
      newStr += c;
    }
  }
  else{
    newStr = s;
  }
  e.value = newStr;
  if( !IsNumber(newStr) ){
    alert(msg2);
    e.focus();
 	e.select();
    return false;
  }
  return true;
}

// IsNumber - Checks to see if the value passed is a number, that is not containing non-numeric
// characters.
function isNumber(s)
{
	var i;
	if(s.length==0) return false;
	for (i = 0; i < s.length; i++){   
	 	// Check to see if current character is number
	 	var c = s.charAt(i);
	 	if (((c < "0") || (c > "9"))) return true;
	}
	// All characters are numbers
	return false;
}

function IsValidDate(p)
{
  var sErrMsg = "Please Enter a Valid Date."
  with (p){
   // Declaring variables
    if (!isEmpty(value)){
      var MonthArr = new Array(12);
      var v_date = value;
      v_split = v_date.indexOf("/");
      v_split2 = v_date.indexOf("/", v_split + 1);
      var v_day = v_date.substring(0, v_date.indexOf("/"));
      var del1 = v_date.substring(v_split, v_split + 1);
      var v_month = v_date.substring(v_split + 1, v_split2);
      var del2 = v_date.substring(v_split2, v_split2 + 1);
      var v_year= v_date.substring(v_split2 + 1, v_date.length);

      // creating array of months 1 - 12
      // Also compensating for leap years
      MonthArr["1"] = 31
      MonthArr["01"] = 31
      if (((v_year % 4 == 0) && (v_year % 100 != 0)) || (v_year % 400 == 0)) {
         MonthArr["2"] = 29
         MonthArr["02"] = 29
      } else {
         MonthArr["2"] = 28
         MonthArr["02"] = 28
      }
      MonthArr["3"] = 31
      MonthArr["03"] = 31
      MonthArr["4"] = 30
      MonthArr["04"] = 30
      MonthArr["5"] = 31
      MonthArr["05"] = 31
      MonthArr["6"] = 30
      MonthArr["06"] = 30
      MonthArr["7"] = 31
      MonthArr["07"] = 31
      MonthArr["8"] = 31
      MonthArr["08"] = 31
      MonthArr["9"] = 30
      MonthArr["09"] = 30
      MonthArr["10"] = 31
      MonthArr["11"] = 30
      MonthArr["12"] = 31

      if (eval(value != '')) {
         if (v_day < 1 || v_day > MonthArr[v_month] || isNaN(v_day)) {
            alert(sErrMsg);
            focus();
            return false;
         } else {
         if (MonthArr[v_month] == null) {
            alert(sErrMsg);
            focus();
           return false;
         } else {
            if (isNaN(v_year) || v_year == "" || v_year.length != 4){
            alert(sErrMsg);
            focus();
            return false;
            }
         }
      }
   }
 }
}
   return true;
}

function formatNumber(expr, decplaces){
// this function formats the number to two decimal places
  var tempstr;
  tempstr =  "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  while (tempstr.length <= decplaces){
    tempstr = "0" + tempstr
  }
    var decpoint = tempstr.length - decplaces;
    return tempstr.substring(0, decpoint) + '.' + tempstr.substring(decpoint, tempstr.length);
}

// this function formats the number to two decimal places and adds dollar sign
function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.00');
}

// this function allows only numbers + decimal point
function isNumberString (InString)  
{
	if(InString.length==0) return false;
	var RefString="1234567890.";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return true;
		}
			return false;
}

// this function allows only alphanumeric (minimum 5) characters
function isNotAlphanumeric (InString)  
{
	if(InString.length < 5) return true;
	var RefString="1234567890abcdefghijklmnopqrstuvwxyz";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		TempChar=TempChar.toLowerCase()
		if (RefString.indexOf (TempChar, 0)==-1)  
			return true;
		}
		return false;
}

// this function allows only alphanumeric characters
function isNotAlphanumericStr (InString)  
{
	var RefString="1234567890abcdefghijklmnopqrstuvwxyz-_";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		TempChar=TempChar.toLowerCase()
		if (RefString.indexOf (TempChar, 0)==-1)  
			return true;
		}
		return false;
}

// allows only domain automarket.com.au
function isValidDomain(str) 
{
	var sDomain;
	sDomain= str.substring (str.indexOf("@"), str.length);
	if (sDomain == "@automarket.com.au")	{
  		return true;
	}
	return false;
}

// allows non-breakable string of specified length
function isValidString(str,len)
{
	var sArray = str.split(" "); // break string into array of strings
    for (var i=0; i < sArray.length; i++) {
      if (sArray[i].length > len) //is this part of the string too long?
        return false; 
    }
    return true;
}

    function textCounter(field, maxlimit)
        {
        if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        }

    function InStr(strSearch, charSearchFor, intLength)
    {
	    for (i=0; i < Len(strSearch); i++)
	    {
	        if (charSearchFor == Mid(strSearch, i, intLength))
	        {
			    return i;
	        }
	    }
	    return -1;
    }
    function Mid(str, start, len)
            {
                    if (start < 0 || len < 0) return "";

                    var iEnd, iLen = String(str).length;
                    if (start + len > iLen)
                            iEnd = iLen;
                    else
                            iEnd = start + len;

                    return String(str).substring(start,iEnd);
            }
    function Len(str)
            {  return String(str).length;  }

    function TrimLen(str)
            {
            return Len(trimAll(str));
            //return String(str).length;
            }
function Show(id)
{
x = event.clientX + document.body.scrollLeft; // get the mouse left position
y = event.clientY + document.body.scrollTop - 50; // get the mouse top position 
document.getElementById(id).style.display="block"; // display the pop-up
//Popup.style.display="block"; // display the pop-up
//Original Line Above
//Popup.style.left = x; // set the pop-up's left
document.getElementById(id).style.left = x;
//Popup.style.top = y; // set the pop-up's top
document.getElementById(id).style.top = y;
}
// this function hides the pop-up when user moves the mouse out of the link
function Hide(id)
{
document.getElementById(id).style.display="none"; // hide the pop-up
}

var tooltip=function(){
var id = 'tt';
var top = 3;
var left = 3;
var maxw = 300;
var speed = 10;
var timer = 20;
var endalpha = 95;
var alpha = 0;
var tt,t,c,b,h;
var ie = document.all ? true : false;
return{
show:function(v,w){
if(tt == null){
debugger
tt = document.createElement('div');
tt.setAttribute('id',id);
t = document.createElement('div');
t.setAttribute('id',id + 'top');
c = document.createElement('div');
c.setAttribute('id',id + 'cont');
b = document.createElement('div');
b.setAttribute('id',id + 'bot');
tt.appendChild(t);
tt.appendChild(c);
tt.appendChild(b);
document.body.appendChild(tt);
tt.style.opacity = 0;
tt.style.filter = 'alpha(opacity=0)';
document.onmousemove = this.pos;
}
tt.style.display = 'block';
c.innerHTML = v;
c.innerHTML = document.getElementById("txtname").value;
tt.style.width = w ? w + 'px' : 'auto';
if(!w && ie){
t.style.display = 'none';
b.style.display = 'none';
tt.style.width = tt.offsetWidth;
t.style.display = 'block';
b.style.display = 'block';
}
if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
h = parseInt(tt.offsetHeight) + top;
clearInterval(tt.timer);
tt.timer = setInterval(function(){tooltip.fade(1)},timer);
},
pos:function(e){
var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
tt.style.top = (u - h) + 'px';
tt.style.left = (l + left) + 'px';
},
fade:function(d){
var a = alpha;
if((a != endalpha && d == 1) || (a != 0 && d == -1)){
var i = speed;
if(endalpha - a < speed && d == 1){
i = endalpha - a;
}else if(alpha < speed && d == -1){
i = a;
}
alpha = a + (i * d);
tt.style.opacity = alpha * .01;
tt.style.filter = 'alpha(opacity=' + alpha + ')';
}else{
clearInterval(tt.timer);
if(d == -1){tt.style.display = 'none'}
}
},
hide:function(){
clearInterval(tt.timer);
tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
}
};
}();

