/******************************************************************************************/
/* Web Developer: Andrew R Martinez 										  			  */
/* Document Owned by: Macrologic, Inc.										  			  */
/* Date last updated: August 25, 2004  										  			  */
/* document name: macro.js 													   			  */
/* Description: This document is the JavaScript library that contains all scripting logic */
/* 				used across the Macrologic, Inc. website. 								  */
/******************************************************************************************/

// getCurrentDate(): responsible for rendering the date on the website.  Is invoked by all active
// pages.
function getCurrentDate() {
<!--
	var rightNow = new Date();
	var weekDay = rightNow.getDay();
	var theMonth = rightNow.getMonth();
	var theDate = rightNow.getDate();
	var theYear = rightNow.getFullYear();

	// set the days of the week
	var theDayString = new Array(7);
	theDayString[0] = "Sunday";
	theDayString[1] = "Monday";
	theDayString[2] = "Tuesday";
	theDayString[3] = "Wednesday";
	theDayString[4] = "Thursday";
	theDayString[5] = "Friday";
	theDayString[6] = "Saturday";
				
	//set the month of the year
	var theMonthString = new Array(12);
	theMonthString[0] = "January";
	theMonthString[1] = "February";
	theMonthString[2] = "March";
	theMonthString[3] = "April";
	theMonthString[4] = "May";
	theMonthString[5] = "June";
	theMonthString[6] = "July";
	theMonthString[7] = "August";
	theMonthString[8] = "September";
	theMonthString[9] = "October";
	theMonthString[10] = "November";
	theMonthString[11] = "December";
				
	//parse the date and store in the format: Monday, June 14, 2004
	var currentDate = theDayString[weekDay] + ", " + theMonthString[theMonth] + " " + theDate + ", " + theYear;
	
	return currentDate;
	// -->
}

// clock(): responsible for grabbing and instance the system's date/time. It also 'knows' how to update the client browser
// based on the browser-type. This routine handshakes with getCurrentDate() above.
function clock() {
	<!--
	//checking for your browser type; NN4, IE4, IE5 or better and NN 6 or better
	if (!document.layers && !document.all && !document.getElementById) 
		return;
				
	var digital = new Date();
	var hours = digital.getHours();
	var minutes = digital.getMinutes();
	var seconds = digital.getSeconds();
	var amOrPm = "AM";
	//determing if its AM or PM
	if (hours > 11) amOrPm = "PM";
	if (hours > 12) hours = hours - 12;	//eg 1, 2 etc or 10
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;	//eg. 09
	if (seconds <= 9) seconds = "0" + seconds;	//eg. 03
	//store the formatted time
	var dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
	if (document.layers) {		//this is how the time will show on NN 4
		document.layers.timer.document.write(dispTime);
		document.layers.timer.document.close();
	}
	else if (document.getElementById) //this is how the time will show NN6+ or IE5+
		//updated our display after every second.
		document.getElementById("timer").innerHTML = dispTime;
		//take a second breather before refreshing clock.
		setTimeout("clock()", 1000);
	// -->
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


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;
}

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_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_findObj(n, d) { //v4.01
  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);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// routine used to handle all form validations , called from macro_contact_form.asp //
// currently NOT being used!
function getFormsCount() {
	for (count=0;count<document.forms.length;count+=1) {
		alert("Form #: "+count+" = "+document.forms[count].name+" has "+document.forms[count].length+ " elements");
		for (x=0;x<document.forms[count].length;x+=1) {
			var elmts=elmts+'\n'+document.forms[count].elements[x].name;
			if (document.forms[count].elements[x].name == "email") {
			}
		}
			alert("Element Names: "+elmts);
			elmts="";
		var formNum=count+1;
	}
	return formNum;
}

/* resetFields(): invoked from within macro_contact_form.asp */
function resetFields() {
	document.contact_form.contact_name.value="";
	document.contact_form.company.value="";
	document.contact_form.address.innerHTML="";
	document.contact_form.phone.value="";
	document.contact_form.title.value="";
	document.contact_form.email.value="";
	document.contact_form.otherAboutUs.value="";
	document.contact_form.other_primary.value="";
	document.contact_form.other_interest.value="";
	
	for ( var x=0; x<document.contact_form.length; x+=1 ) {
		if ( ( document.contact_form.elements[x].type == "checkbox" ) || ( document.contact_form.elements[x].type == "radio" ) ) {
			document.contact_form.elements[x].checked=false;
		} 
	}
		
	document.contact_form.other_inquries.innerHTML="";
    return true;	
}
  // here we will pass all form fields to investigate whether they are empty or not
function IsEmpty(aTextField) {
   if ( ( aTextField.value.length==0 ) || ( aTextField.value==null ) ) {
   		return true;
   }
   else {
		return false;
	}
}

// checkFields(): is invoked from macro_viewer_data_capture.asp -- it checks that the three fields namely,
// company_name, contact_name and, email are not empty
// of course, the function does not check for the quality of information being submitted :(
function checkFields() {
	if ( IsEmpty(document.slide_viewer_info.company_name) || IsEmpty(document.slide_viewer_info.contact_name) || IsEmpty(document.slide_viewer_info.email) ) {
		alert("Kindly provide us with your basic contact information before viewing the slide show.");
		return false;
	}
	return true;
}

function checkFieldsQuiz() {
	if ( IsEmpty(document.guest_book.company_name) || IsEmpty(document.guest_book.contact_name) || IsEmpty(document.guest_book.email) ) {
		alert("In order for us to better serve you kindly provide us with your basic contact information.");
		return false;
	} else {
		return true;
	}
}
// IsNumeric(): returns a boolean; true/false to the calling routine. It checks for valid digits 0..9.
function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
   	  if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
   	   }
     }
   return IsNumber;   
  }
  
  // openWin(): is the base container window for all the product features side menu box.  This menu spans the entire site.  
  function openWin(pg) {
    var win_name='featureAtAGlance_window';
	
	var t=200;
	var lf=120;
	var scrX=120;
	var scrY=200;
	var winWidth='width=540';
	var winHeight='height=250';
	
	win_name =	window.open(pg, win_name, winWidth+','+winHeight+',top='+t+',left='+lf+',screenX='+scrX+',screenY='+scrY);
	win_name.focus();		// guarantees window will always be in-front and atop parent window
  } 
  
 // openSlideShow(): is invoked from macro_new_macPlus7.asp. First, it contains the macro_data_capture.asp page and if all is good,
// will then contain the macroLinkv70.htm(the actual MacroLink v7 sample screens slide show)
  function openSlideShow() {
  	var win_name='slide';
	var t=0;
	var lf=0;
	var scrX=0;
	var scrY=0;
	var winWidth='width=680';
	var winHeight='height=520';  
  	var slide_show_win = window.open('macro_viewer_data_capture.asp', win_name, winWidth+','+winHeight+',top='+t+',left='+lf+',screenX='+scrX+',screenY='+scrY);
	slide_show_win.focus();
	return true;
  }
  /* detectSettings(): get/set browserName, browserVersion, platform, if brower supports CSS,
     client's current screen resolution, client's color depth(bitwise) and number of colors client browser supports
     this function IS NOT yet implemented or even tested....on hold for now....
  */
  function detectSettings() {
  	var browserName;
	var browserVer;
	var platform;
	var platformVer;
	var isCSS_support;
	var currentScrResolution;
	var colorDepthInBit;		
	var codeName;				// platform code name
	var numberOfColor;			// total number of colors.
	
	// first, fetch the Browser Name and Version
	browserName=navigator.appName;
	browserVer=navigator.appVersion;
	
	 if (browserVer.indexOf("4.") != -1 &&  browserName.indexOf("Explorer") != -1) {
 		//now, capture the visitors current screen resolution
	     currentScrResolution = screen.width + "x" + screen.height;
	  }
	  if (browserVer.indexOf("4.") != -1 && browserName.indexOf("Netscape") != -1) {
    	 currentScrResolution = screen.width + "x" + (screen.height + 19); // Netscape sees 19 pixels less on Height
	  }	
	 // get/set the other data members 
	  platform=navigator.platform;
	  codeName=navigator.appCodeName;
	  colorDepthInBit=screen.colorDepth;
	  
	  //now, we need to do something based on the client's current screen resolution setting
	  switch ( currentScrResolution ) {
	  	case "640x480":		// default640x480
		case "800x600":		// default800x600
		case "1024x768":	// default1024x768
		case "1024x738":	// default1024x738
		case "1152x864":	// default1152x864
		case "1280x1024":	// default1280x1024
		case "1600x1200":	// default1600x1200
	  }
  }

//calMyBillingIQ(): invoked from macro_QUIZ.asp. Responsible for traversing the quiz form, adding the total
// can do's on the quiz and finally passing that score to rateMyScore(score).  
function calcMyBillingIQ() {
	<!-- those darn old browsers
	var canDos=0;		// keeps a count of the Can Do's

	for (count=0;count<document.forms.length;count+=1) {
		for (x=0;x<document.forms[count].length;x+=1) {
			if (document.forms[count].elements[x].type == "radio") {			
				if (document.forms[count].elements[x].checked) {
					canDos = canDos+parseInt(document.forms[count].elements[x].value);
				}	// end if radio button is checked				
			}// end if element.type == "radio"
		} // end for loop thru form elements
	}	// end for, forms counter...just in case we have multiple forms.
  	var win_name='slide';
	var t=200;
	var lf=300;
	var scrX=0;
	var scrY=300;
	var winWidth='width=460';
	var winHeight='height=195';  
//  	var slide_show_win = window.open('macro_IQ_message2.asp?TotalScore='+canDos, win_name, winWidth+','+winHeight+',top='+t+',left='+lf+',screenX='+scrX+',screenY='+scrY+',toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no');
	document.location.href='macro_IQ_message.asp?TotalScore='+canDos;

	return canDos;
// -->			
}		

// rateMyScore(score): is invoked from calcMyBillingIQ(). Responsible for rating the user's score and 
// outputting the resulting score with a message appropriate to the score received.
function rateMyScore( score ) {
<!--
	var iqMsg = "Your Billing system IQ is: "+ score;
	switch (score) {
		// score 0..12
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5: 
		case 6:
		case 7:
		case 8:
		case 9:
		case 10: 
		case 11:
		case 12:
			{ 
				iqMsg=iqMsg+'\n\n'+"Your billing System is gasping for air and needs life support.  Don't worry!  ";
				iqMsg=iqMsg+"You don't have to spend a lot of money on a costly resuscitation.  There are quick  ";
				iqMsg=iqMsg+"and very cost effective ways to breathe new life into your business with feature-rich  ";
				iqMsg=iqMsg+"billing.  Click here to let us explain how!";						
				alert(iqMsg); 
				document.location.href='macro_contact_form.asp';						
				break;
			}		
			// score 13..15
		case 13:				
		case 14:
		case 15:
			{
				iqMsg=iqMsg+'\n\n'+"Oh No!  You must be struggling to work around those little 'holes' in your billing system.  ";
				iqMsg=iqMsg+"Help is just a click away. click now and let us explain how!";
				alert(iqMsg);
				document.location.href='macro_contact_form.asp';						
				break;
			}		
		// score 16..18		
		case 16: 
		case 17:
		case 18:
			{
				iqMsg=iqMsg+"\n\nRespectable!  your system does the basics, but doesn't give you an edge over your competitors.  ";
				iqMsg=iqMsg+"Click here to learn how easy and cost effective it is to be the best you can be!"						
				alert(iqMsg);
				document.location.href='macro_contact_form.asp';						
				break;
			}		
		// score 19
		case 19:
			 {
			  	iqMsg=iqMsg+"\n\nCongratulations!  You must be using Macrologic's MacroLink Plus billing software.  ";
				iqMsg=iqMsg+"You are using the best competitive edge available for your billing and business needs!";
				alert(iqMsg);
				document.location.href='macro_new_MacPlus7.asp';
				break;
			}
		}	//end switch
		// -->		
}

