﻿var win;
var Dom =
{
	get: function(el, frm)
	{
		if (typeof el === 'string')
		{
			return document.getElementById(el);
		}
		else
		{
			return el;
		}
	},
	add: function(el, dest, frm)
	{
		var el = this.get(el, frm);
		var dest = this.get(dest, frm);
		dest.appendChild(el);
	},

	remove: function(el, frm)
	{
		var el = this.get(el, frm);
		el.parentNode.removeChild(el);
	}
};
var Event =
{
	add: function()
	{
		if (window.addEventListener)
		{
			return function(el, type, fn)
			{
				Dom.get(el).addEventListener(type, fn, false);
			};
		}
		else if (window.attachEvent)
		{
			return function(el, type, fn)
			{
				var f = function()
				{
					fn.call(Dom.get(el), window.event);
				};
				Dom.get(el).attachEvent('on' + type, f);
			};
		}
	}()
};
function getElementsByClassName(strClassName, node)
{
	var retnode = [];
	var myclass = new RegExp('\\b'+strClassName+'\\b');
	var elem = node.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++)
	{
		var classes = elem[i].className;
		if (myclass.test(classes))
		{
			retnode.push(elem[i]);
		}
	}
	return retnode;
}
function getElementsByTagAndClassName(strClassName, tag, node)
{
	var retnode = [];
	var myclass = new RegExp('\\b'+strClassName+'\\b');
	var elem = node.getElementsByTagName(tag);
	for (var i = 0; i < elem.length; i++)
	{
		var classes = elem[i].className;
		if (myclass.test(classes))
		{
			retnode.push(elem[i]);
		}
	}
	return retnode;
}
function openReviews(strId)
{
    openWindow('\Reviews.aspx?min=y&id='+strId)
    //window.open('\Reviews.aspx?min=y&id='+strId,'win','menubar=0,resizable=1,location=0,status=0,scrollbars=1,width=750,height=450'); 
}
function openWindow(url)
{
    window.open(url,'win','menubar=0,resizable=1,location=0,status=0,scrollbars=1,width=750,height=450');
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function isValidDate( strValue ) {
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    //check for February
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}   
function addValidationSummaryItem(text, valSum)
{
    var newLI = document.createElement("LI");
    newLI.innerHTML = text;
    valSum.style.display = "block";
    valSum.appendChild(newLI);
}
function highlightField(field)
{
    field.parentNode.className = "errorField";
}
function selectItem(objSelectBox, strSelectText)
{
	for(var i = 0; i < objSelectBox.options.length; i++)
	{
		if(objSelectBox.options[i].text == strSelectText)
		{
			objSelectBox.options[i].selected = true;
		}
	}
}
function setFormFocus(strForm, strField)
{
	if (strField)
	{
	    strField.focus();
	}
}
function formatCurrency(num)
{
    var asterisk;
    if (num.substring(num.length-1) == "*")
    {
        asterisk = true;
        num = num.substring(0,num.length-1);
    }
    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));
    num = (((sign)?'':'-') + '$' + num + '.' + cents);
    if (asterisk)
    {
        num = num + "*";
    }
    return num;
}
function showInfoMsg(e, divDestination, strType)
{
	var objInfoMsg = document.createElement('div');
    objInfoMsg.style.zIndex = "202";
	objInfoMsg.className = "InfoMsg";
    if (navigator.appName != "Microsoft Internet Explorer")
    {
        objInfoMsg.style.left = mouseX(e) - 350;
        objInfoMsg.style.top = mouseY(e) + 15;
    }    
    msg = "";
    if (strType == 'date')
    {
        msg = strDateNotAvailableMsg;
    }
    else if (strType == 'rate')
    {
        msg = strRateNotAvailableMsg;
    }
    else
    {
        msg = strType;
        objInfoMsg.style.color = "black";
        objInfoMsg.style.width = "50px";
    }
    objInfoMsg.innerHTML = msg;             
    Event.add(divDestination, 'mouseout',
        function() {
            hideInfoMsg();
        }
    );
	Dom.add(objInfoMsg, divDestination, document.form);
}
function hideInfoMsg()
{
	var objInfoMsg = getElementsByTagAndClassName('InfoMsg', 'div', document);
    for (var i=0; i<objInfoMsg.length; i++)
    {
	    if(objInfoMsg[i])
	    {
		    Dom.remove(objInfoMsg[i]);
	    }
    }    
}
function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}
var dtCh= "/";
var minYear=2010;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}
function showMessage(e, strID)
{
    var objMessage = document.getElementById(strID);
    
    if(objMessage)
    {
        var mWidth = parseInt(objMessage.style.width)
        if(mWidth==0)
        {
            mWidth = 70;
        }
        else
        {
            mWidth = (mWidth / 2) + 5
        }
        
        objMessage.style.display = "inline";
        objMessage.style.left = mouseX(e) - mWidth;
        objMessage.style.top = mouseY(e) + 15;
    }
}
function hideMessage(strID)
{
    if(document.getElementById(strID))
    {
        var objMessage = document.getElementById(strID);
        objMessage.style.display = "none";
    }
    else
    {
        return false;
    }
}
function validPhoneNum(strPhoneNum)
{
    var rePhone = /^[1]*[\s|-]*\(*[0-9]{3}\)*[\s|-]*[0-9]{3}[\s|-]*[0-9]{4}$/gi;
    rePhone.lastIndex = 0;
    return(rePhone.test(trim(strPhoneNum)));
}
function trackWebAnalyticEvent(intID, strValue)
{
	var objAJAX = new clsAJAX();

	objAJAX.open("GET", "/AJAX/WebAnalyticsEvent.aspx?eid="+intID+"&ev="+strValue+"&vs="+strWAVisitorSession+"&vi="+intWAVisitID+"&site="+strWASite+"&page="+strWAPage+"&date="+Date(), true);
	objAJAX.send(null);
}
window.scrollTo = function() { }