﻿// JScript File
//----------------------------------------------------------------------------------------------------
//-- Records the click on an ad in the right column of the site
//----------------------------------------------------------------------------------------------------
var http_request = false; 

function makeRequest(url) { 
    //alert(url);
    if (window.XMLHttpRequest) { // Mozilla, Safari, IE7... 
        http_request = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { // IE6 and older 
        http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    http_request.open('POST', url, true); 
    http_request.send(null); 
} 

function adClick(adid) {
    makeRequest('http://localhost/imi/AdTracker.aspx?ad=' + adid);
}
//----------------------------------------------------------------------------------------------------
//-- Buy Now button click and add item to cart
//----------------------------------------------------------------------------------------------------
function buyNow(modelNumber) {
    makeRequest('http://localhost/imi/Add2Cart.aspx?item=' + modelNumber);
}
//----------------------------------------------------------------------------------------------------
//-- Clears the default text from a text box...text box calls funtion onFocus
//----------------------------------------------------------------------------------------------------
function clearTextBox(obj) {
	obj.value = '';
}
//----------------------------------------------------------------------------------------------------
//-- Check for enter key and set focus and click object provided
//----------------------------------------------------------------------------------------------------
function CheckFormEnter(e, sButtonName) {
	var characterCode;
	if(e && e.which) { 
		e = e;
		characterCode = e.which; // (for NN4 support)
	} else {
		e = event;
		characterCode = e.keyCode; // (for IE)
	}
	if(characterCode == 13) { //(ascii 13 - enter key)
		var button = document.getElementById(sButtonName);
		button.focus();
		button.click();
	}
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Locked Window
//----------------------------------------------------------------------------------------------------
function openGenericLockedWindow(loc, name, newWidth, newHeight) {
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Unlocked Window
//----------------------------------------------------------------------------------------------------
function openGenericUnLockedWindow(loc, name, newWidth, newHeight){
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Unlocked Window
//----------------------------------------------------------------------------------------------------
function openGenericLockedScrollWindow(loc, name, newWidth, newHeight){
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Unlocked Window
//----------------------------------------------------------------------------------------------------
function openUnLockedWindow(loc, name){
	var reportWindow;
	reportWindow = window.open(loc, name);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Allow user to bookmark a specific page.  Used in Support Sections.  Link is on the sidebar
//----------------------------------------------------------------------------------------------------
function bookmark() {
	if (document.all) {
		window.external.AddFavorite(location.href, document.title); return false;
	}
}
//----------------------------------------------------------------------------------------------------
//-- Pre loads images
//-- To use type the following on a page:
//-- jsLoadImages('/enterfoldername/enterimagename.gif or jpg',
//--              '/enterfoldername/enterimagename.gif or jpg');
//----------------------------------------------------------------------------------------------------
var images = new Array();
function jsLoadImages(){ 
	for (var i=0; i < jsLoadImages.arguments.length; i++) {
		images[i] = new Image();
		images[i].src = jsLoadImages.arguments[i];
	}
}
//----------------------------------------------------------------------------------------------------
//-- Redirect the browser to the url provided
//----------------------------------------------------------------------------------------------------
function redirectBrowser(url) {
	location.href = url;
}
//----------------------------------------------------------------------------------------------------
//-- Check for valid e-mail address
//----------------------------------------------------------------------------------------------------
function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (len<2) {
		return false;
	}
	return true;
}
//----------------------------------------------------------------------------------------------------
//-- Returns date formatted like this January 3, 2008
//----------------------------------------------------------------------------------------------------
function GetFormattedDate()
{
    var armonth = new Array(12);
        armonth[0]="January";
        armonth[1]="February";
        armonth[2]="March";
        armonth[3]="April";
        armonth[4]="May";
        armonth[5]="June";
        armonth[6]="July";
        armonth[7]="August";
        armonth[8]="September";
        armonth[9]="October";
        armonth[10]="November";
        armonth[11]="December";

    var currentTime = new Date();
    var month = currentTime.getMonth();
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var formatteddate = armonth[month] + " " + day + ", " + year;
    
    return formatteddate;
}

//----------------------------------------------------------------------------------------------------
//-- Returns full Year ex. 2008
//----------------------------------------------------------------------------------------------------
function getFullYear()
{
    var currentdate = new Date();
    var fullyear = currentdate.getFullYear();
    
    return fullyear;
}