var quotes = new Array(18);
quotes[0] = "bennett_quote.gif";
quotes[1] = "dror_quote.gif";
quotes[2] = "guerin_quote.gif";
quotes[3] = "hallman_quote.gif";
quotes[4] = "krabil_quote.gif";
quotes[5] = "louvet_quote.gif";
quotes[6] = "marker_quote.gif";
quotes[7] = "mcnulty_quote.gif";
quotes[8] = "novak_quote.gif";
quotes[9] = "saghieh_quote.gif";
quotes[10] = "uppalapati_quote.gif";
quotes[11] = "whitcom_quote_1.gif";
quotes[12] = "whitcom_quote_2.gif";
quotes[13] = "whitcom_quote_3.gif";
quotes[14] = "zimmerman_quote.gif";
quotes[15] = "cantwell_quote.gif";
quotes[16] = "gossage_quote.gif";
quotes[17] = "way_quote.gif";

// breadcrumb variable for organized quote folders
var QuoteBreadCrumb = "";

function hideShow(IdString,ArrowIdString)
{
	var element = document.getElementById(IdString);
	var arrowelement = document.getElementById(ArrowIdString);
			
	if(element.style.display == "none" || element.style.display == "")
	{
		element.style.display = "block";
		arrowelement.src = "/images/arrow_open.gif";
	}
	else
	{
		element.style.display = "none";
		arrowelement.src = "/images/arrow_closed.gif";
	}
}

function randomQuote()
{
	var index = Math.floor(Math.random() * quotes.length);
	return "/images/quotes/" + quotes[index];
}

// TODO
//		quotes organized in folders by product type or some classification scheme
/*function randomQuote()
{
	var index = Math.floor(Math.random() * quotes.length);
	return "/images/quotes/" + QuoteBreadCrumb + "/" + quotes[index];
}
*/

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
	
function checkEmail(addr)
{
	//  Will check for @, period after @ and text in between
	var in_space = addr.indexOf(" ");
	if (in_space != -1)
	{ 
		alert ("E-mail address should contain no spaces and be of the form jdoe\@aol.com");
		return false;
	}

	var len = addr.length;
	var alpha = addr.indexOf("@");
	var last_alpha = addr.lastIndexOf("@");

	if (alpha != last_alpha)
	{
		alert ("Invalid e-mail address. Should contain only one @ and be of the form jdoe\@aol.com");
		return false;
	}

	// No @, in first position, or name too short
	if (alpha == -1 || alpha == 0 || len<6 )
	{
		alert ("Invalid e-mail address. Should contain an @ and be of the form jdoe\@aol.com");
		return false;
	}

	var last_p = addr.lastIndexOf(".");
	// Be sure period at least two spaces after @, but not last char.
	if (last_p - alpha < 2 || last_p == (len - 1) )
	{
		alert ("Invalid e-mail address. Should contain a period after the @ and be of the form jdoe\@aol.com");
		return false;
	}
}

function allTrim(cValue)
{
	var lDone=false;
	while (lDone==false)
	{
		if (cValue.length==0) { return cValue; }
		if (cValue.indexOf(' ')==0) { cValue=cValue.substring(1);lDone=false; continue; }
		else { lDone=true; }
		if (cValue.lastIndexOf(' ')==cValue.length-1) { cValue=cValue.substring(0, cValue.length-1);lDone=false;continue; }
		else { lDone=true; }
	}
	return cValue;
}

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//Function to determine how many checkboxes where checked
function howManyChecked(whichForm,whichCheckBoxArray,myMin)
{
	var _countChecked = 0;
	var err = 0;
	// iterate through all the elements in the checkbox array
	for(i=0;i<document[whichForm][whichCheckBoxArray].length;i++)
	{
		// and check to see if each is checked
		if(document[whichForm][whichCheckBoxArray][i].checked==true)
		{
			// if it is, increment a counter
			_countChecked++;
		}
	}
	if(_countChecked < myMin) { err = 1; }
	if (err == 1) { return false; }
}

 //function to Validate 1 radio button selected
function valButton(btn)
{
	var cnt = -1;
	for (var i=0; i < btn.length; i++)
	{
	   if (btn[i].checked) {cnt = i; i = btn.length;}
	}
	if (cnt > -1) return btn[cnt].value;
	else return null;
}

//  check for valid numeric strings
function IsNumeric(strString)	
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   return blnResult;
}

function FCKEdit_AddEvents( editorInstance )
{
	editorInstance.Events.AttachEvent('OnSelectionChange',UpdatePreview);
	editorInstance.Events.AttachEvent('OnChange',UpdatePreview);
}

function ValidUrl(element)
{
	var regex = new RegExp("http:\/\/([a-zA-Z-_%?.\/])+");
	var result = regex.test(element.value);
	return result;
}


function popUp(URL, w, h) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=" + w +",height=" + h +",left = 500,top = 400');");
}
