function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
var loaded = false;
function trapint(form_name,formField) {
	frm = document.forms[form_name];
	var field = frm.elements[formField];
	if (field.value.length == 0) {
		if (event.keyCode==45 || (event.keyCode>46 && event.keyCode<58)) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	} else {
		if (event.keyCode>46 && event.keyCode<58) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	}
}
function trapfloat() {
	if (event.keyCode==13 || event.keyCode==8 || (event.keyCode>45 && event.keyCode<58)) {
		return true;
	} else {
		event.returnValue = false;
		return false;
	}
}
var str = "left=0,screenX=0,top=0,screenY=0";

if (window.screen) {
  var ah = 500;
  var aw = 650;
  str += ",height=" + ah;
  str += ",innerHeight=" + ah;
  str += ",width=" + aw;
  str += ",innerWidth=" + aw;
  str += ",scrollbars=yes";
  str += ",status=yes";
  str += ",resizable";
} else {
  str += ",resizable"; // so the user can resize the window manually
}

function launch(newURL, newName, newFeatures, orgName) {
	var PopWin = window.open(newURL, newName, newFeatures);
	if ((!PopWin) || (PopWin.opener == null)) {
		alert('Warning, a popup was blocked.  Please disable popup blocking for full functionality on this website.')
		PopWin.opener = window;
		PopWin.opener.name = orgName;
	}
	return PopWin;
}

function launchPop(url) {
	if (!window.myPop || window.myPop.closed) {
		myPop = launch(url, "Popchild", str, "PopParent");
		myPop.focus();
	} else {
		myPop.location.href = url;
		myPop.focus();
	}
}

function save_maybes(){
	opener.location.href='index.html?action=login&save_maybes=true';
	self.close();
}

function closer(){
	opener.focus();
	self.close();
}
function MakeArray(n) {
	this.length = n;
	for (var i = 1; i <= n; i++) {
		this[i] = 0;
	}
	return this;
}
function pickSelectedId(elId, elVal) {
	var el = window.opener.document.getElementById(elId);
	for (i = 0; i < el.options.length; i++) {
		if (elVal == el.options[i].value) {
			el.selectedIndex = i;
		}
	}
	window.opener.focus();
	self.close();
}
function pickSelected(form,formField,Index){
	var frm = window.opener.document.forms[form];
	var field = frm.elements[formField];
	field.selectedIndex = Index;
	window.opener.focus();
	self.close();
}
function qfRequireState(a,b,c) {
	var stateVal = b;
	stateObj = document.getElementById(c);
	if (stateObj.options.length < 2) {
		// selected country has no states
		return true;
	}
	if ('' == stateVal) {
		return false;
	}
	return true;
	
}
var loadedStates = new Array();
var stateObj;
var updateStateRunning = false;
function updateStates(stateId, countryId) {
	if (true == updateStateRunning) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',100);
		return;
	}
	if (false == window.loaded) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',10);
		return;
	}
	updateStateRunning = true;
	countryObj = document.getElementById(countryId);
	var selectedCountry = countryObj.options[countryObj.selectedIndex].value;
	stateObj = countryObj.form[stateId];
	var numOpts = stateObj.options.length;
	if (numOpts) {
		stateObj.options[0].selected = true;
		stateObj.options[0].innerHTML = 'Loading...';
		for (var i = numOpts; i > 0; i--) {
			stateObj.options[i] = null;
		}
	}
	if (loadedStates[selectedCountry]) {
		setStateOptions(selectedCountry);
	} else {
		var stateScript = document.body.appendChild(document.createElement('iframe'));
		stateScript.setAttribute('height', 0);
		stateScript.setAttribute('width', 0);
		stateScript.setAttribute('src', '/jsrpc.html?action=loadStates&countryCode='+selectedCountry+'&stateId='+stateId);
		stateScript.setAttribute('id', 'loadStates'+selectedCountry);
	}
}
function setStateOptions(selectedCountry) {
	var opt;
	var selected;
	if (loadedStates[selectedCountry]) {
		eval('selected = '+stateObj.id+';');
		for (var key in loadedStates[selectedCountry]) {
			opt = document.createElement('option');
			opt.setAttribute('value', key);
			if (key == selected) {
				opt.setAttribute('selected', true);
			}
			opt.innerHTML = loadedStates[selectedCountry][key];
			stateObj.appendChild(opt);
		}
		stateObj.options[0].innerHTML = 'Select State';
	} else {
		stateObj.options[0].innerHTML = 'No Known States for '+selectedCountry;
	}
	updateStateRunning = false;
	return false;
}
function show_calendar(id) {
	url = "/calendar.html?id=" + id;
	size = 190;
	win = window.open(url, 'calendar', 'height='+size+',width='+size+',status=no,location=no');
	win.moveTo((screen.width-size)/2, (screen.height-size)/2);
	return win;
}
function erase(p_item){
	frm = document.getElementById(p_item);
	frm.value='';
}
function strpos(haystack, needle) {
	nlen = needle.length;
	for (var i = 0; i < haystack.length; i++)
	if (haystack.substring(i, i+nlen) == needle) return i;
	return -1;
}
function checkEmail(element) {
	val = element.value;
	if (val.length) {
		fs = document.body.appendChild(document.createElement('iframe'));
		fs.setAttribute('height', 0);
		fs.setAttribute('width', 0);
		fs.setAttribute('src', '/jsrpc.html?action=checkEmail&email='+val);
		fs.setAttribute('id', 'checkEmail');
	}
}
function in_array(n, h) {
	for (var i=0; i<h.length; i++) { if (n == h[i]) { return true; } } return false;
}

	function photoPop(img_dir, photo, length, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/photograph.html?img_dir=" + img_dir + "&photo=" + photo + "&length=" + length;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 525;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) { popWindow.opener = self; }
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
	function screenPop(photo, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/popup.html?action=screen_grab&photo=" + photo;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 520;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) { popWindow.opener = self; }
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function updAddrNm(a,b,c) {
	if ((aa = document.getElementById(a)) && (bb = document.getElementById(b)) && (cc = document.getElementById(c))) aa.value=bb.value+' '+cc.value;
}
function alternateRows(tab, cls1, cls2) {
	rows = tab.getElementsByTagName('tr');
	for (j=0; j<rows.length; j++) {
		if (j%2 == 0) {
			cls = cls1;
		} else {
			cls = cls2;
		}
		rows[j].setAttribute('class', cls);
	}
}	
function initPage() {
	if (bcn = document.getElementById('navLevel3')) { var hideNav3 = true; for (i=0; i<bcn.childNodes.length; i++) { if (bcn.childNodes[i].childNodes.length > 0) { hideNav3 = false; } } if (hideNav3) { bcn.style.display = 'none'; } } if (hrarh = document.getElementById('hrAboveResultsHeader')) { if (sechdr = document.getElementById('sectionHeader')) { if (sechdr.childNodes.length < 2 && !hideNav3) { hrarh.style.display = 'none'; } } }
	dbEnt = getElementsByClass('dbEntity');
	for (i=0; i<dbEnt.length; i++) {
		alternateRows(dbEnt[i], 'alt', '');
	}
	window.loaded=true;
}
function getElementsByClass(className) {
	var out = new Array();
	allElements = document.getElementsByTagName('*');
	j = 0;
	for (i=0; i<allElements.length; i++) {
		if (className == allElements[i].className) {
			out[j++] = allElements[i];
		}
	}
	return out;
}

function validate_smarterstarterlogin() {
	fld = document.getElementById('qf_1_password');
	if (fld.value && fld.value.toUpperCase() != 'HARLAND') {
		alert('Please enter a valid temporary e-Micr number');
		fld.focus();
		return false;
	} else {
		return true;
	}
}

function validate_software(form) {
	jumpto = "";
	var errors = "";

	var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
	var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	var reg1 = new RegExp(reg1str);
	var reg2 = new RegExp(reg2str);
	if (reg1.test(document.forms[1].email.value) || !reg2.test(document.forms[1].email.value)) {
		errors += 'Please Enter a Valid E-mail Address:\n';
		if (!jumpto) {
			jumpto = document.forms[1].email;
		}
	}
	if (document.forms[1].business_name.value == "") {
		errors += 'Please enter a Name:\n';
		if (!jumpto) {
			jumpto = document.forms[1].business_name;
		}
	}
	if (document.forms[1].name.value == "") {
		errors += 'Please enter a Financial Institution:\n';
		if (!jumpto) {
			jumpto = document.forms[1].name;
		}
	}
	if (document.forms[1].address.value == "") {
		errors += 'Please enter an Address:\n';
		if (!jumpto) {
			jumpto = document.forms[1].address;
		}
	}
	if (document.forms[1].city.value == "") {
		errors += 'Please enter the City:\n';
		if (!jumpto) {
			jumpto = document.forms[1].city;
		}
	}
	if (document.forms[1].state.value == "") {
		errors += 'Please choose a State:\n';
		if (!jumpto) {
			jumpto = document.forms[1].state;
		}
	}
	if (document.forms[1].zip.value == "") {
		errors += 'Please enter your Zip:\n';
		if (!jumpto) {
			jumpto = document.forms[1].zip;
		}
	}
	if (document.forms[1].phone_1.value == "") {
		errors += 'Please enter your Phone Number:\n';
		if (!jumpto) {
			jumpto = document.forms[1].phone_1;
		}
	}

	if (!errors) {
		return true;
	}
	else {
		string = "The following fields were incomplete or invalid. Please complete them to continue.\n\n"+errors;
		alert(string);
		jumpto.focus();
		return false;
	}
	return false;
}

function autofocus(field, limit, next, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && field.value.length == limit) {
        field.form.elements[next].focus( );
    }
}

var legacySDs1 = new Array();
var essentialSDs1 = new Array();
var essentialSDs2 = new Array();
var classicSDs1 = new Array();
var classicSDs2 = new Array();

function showFullImage(id,src,itemId,parent){
	url = "/popup.html?action=zoom_image&item_id="+itemId;
	document.getElementById(id).onclick = function(){launchPop(url)};
	document.getElementById(id).src = '/images/product_images/'+src;
	if(parent == 'legacy1'){
		document.getElementById('legacy1_sd').innerHTML=legacySDs1[itemId];
	}
	if(parent == 'essential1'){
		document.getElementById('essential1_sd').innerHTML=essentialSDs1[itemId];
	}
	if(parent == 'essential2'){
		document.getElementById('essential2_sd').innerHTML=essentialSDs2[itemId];
	}
	if(parent == 'classic1'){
		document.getElementById('classic1_sd').innerHTML=classicSDs1[itemId];
	}
	if(parent == 'classic2'){
		document.getElementById('classic2_sd').innerHTML=classicSDs2[itemId];
	}
}

var legacyImgs1 = new Array();
var essentialImgs1 = new Array();
var essentialImgs2 = new Array();
var classicImgs1 = new Array();
var classicImgs2 = new Array();



function setOrderItem(qtyId,checkId,name,itemsImgs){

	if(itemsImgs == 'legacyImgs1'){
		for (i=0;i<legacyImgs1.length;i++)
		{
			thisId = legacyImgs1[i];
			document.getElementById(thisId).style.borderColor='black';
		}
		thisId = name+'l';
		document.getElementById(thisId).style.borderColor='red';
	}
	if(itemsImgs == 'essentialImgs1'){
		for (i=0;i<essentialImgs1.length;i++)
		{
			thisId = essentialImgs1[i];
			document.getElementById(thisId).style.borderColor='black';
		}
		thisId = name+'e';
		document.getElementById(thisId).style.borderColor='red';
	}
	if(itemsImgs == 'essentialImgs2'){
		for (i=0;i<essentialImgs2.length;i++)
		{
			thisId = essentialImgs2[i];
			document.getElementById(thisId).style.borderColor='black';
		}
		thisId = name+'e';
		document.getElementById(thisId).style.borderColor='red';
	}
	if(itemsImgs == 'classicImgs1'){
		for (i=0;i<classicImgs1.length;i++)
		{
			thisId = classicImgs1[i];
			document.getElementById(thisId).style.borderColor='black';
		}
		thisId = name+'c';
		document.getElementById(thisId).style.borderColor='red';
	}
	if(itemsImgs == 'classicImgs2'){
		for (i=0;i<classicImgs2.length;i++)
		{
			thisId = classicImgs2[i];
			document.getElementById(thisId).style.borderColor='black';
		}
		thisId = name+'c';
		document.getElementById(thisId).style.borderColor='red';
	}


	document.getElementById(checkId).disabled = false;
	document.getElementById(checkId).name = 'order_items['+name+']';
	document.getElementById(qtyId).name = 'qty['+name+']';
}

function prueba(val){
    
    var msg = "All 2nd day and next day orders must be phone verified due to the high cost of shipping. Please call 1.888.500.MICR to confirm that you want your order shipped via this method.";
    
    if(val == 3 || val == 4){
        document.getElementById('msg').style.display='block';
        document.getElementById('msg').innerHTML=msg;
    }else{
        document.getElementById('msg').style.display='none';
        document.getElementById('msg').innerHTML="";
    }
    
}
