//    Toggles between Expand and Collapse for one section of code (between DIVs)
function doExpand(paraNum,arrowNum) 
{
var p=document.getElementById(paraNum);
var a=document.getElementById(arrowNum);
if (p.style.display=="none") {
   p.style.display="block";
   a.src="images/collapse-sign-12px.gif";
}
else {
   p.style.display="none";
   a.src="images/expand-sign-12px.gif";
}
}

//    Expands all sections of code (between DIVs)
function doExpandAll(paraNum,arrowNum) 
{
var p=document.getElementById(paraNum);
var a=document.getElementById(arrowNum);
p.style.display="block";
a.src="images/collapse-sign-12px.gif";
}

//    Collapses all sections of code (between DIVs)
function doCollapseAll(paraNum,arrowNum)
{
var p=document.getElementById(paraNum);
var a=document.getElementById(arrowNum);
p.style.display="none";
a.src="images/expand-sign-12px.gif";
}

 //    Converts data into mailto:email_address to subvert spammers
function eParser(ext,dom,who)
{
	document.write("<a class=\"elink\" href=\"mailto");
	document.write(":" + who + "@" + dom + "." + ext + "\">");
}

//    Places a closing </a> on the email Parser above
function ePEnd()
{
	document.write("<\/a>");
}

//    Creates popup window non-maximized
function wopen(url, name, w, h, resize)
{
	// Fudge factors for window decoration space.
	// should work well on all platforms and browsers
	w += 32;
	h += 96;
	if (resize.toUpperCase()=='FIXED' || resize.toUpperCase=='NO')
	{	resize = 'no'}
	else
	{	resize = 'yes'}
		
	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 
	   'location=no, menubar=yes, status=yes, toolbar=no, scrollbars=' + resize + ', resizable=' + resize + ', ' +
	   'screenX=250, screenY=250');
	win.resizeTo(w, h);
	win.focus();
}  

//    Closes popup window non-maximized
function wclose(name)
{
  win.close(name);
}
   
//		Print Tracking Script -- from MealsAndDeals.com
var url = "print_tracker.php?client=58&coupon=52"; // The server-side script

function print_me() {
  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
    //if(results == "") results = "Username <i>"+name+"</i> Is Available...";
    //alert(results + " hi");
	window.print();
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object



//       Text rotation
//window.onload = setup; 

function setup() { 
   if (! document.getElementsByTagName) return false; 
   var elms = document.getElementsByTagName("blockquote"); 
   //var elms = document.getElementById("quotes").getElementsByTagName("h2")
   //var elms = document.getElementsByClass("quotes"); 
   if (! elms.length) return false; 
   rotate(elms, 0); 
} 

function rotate(elms, iElm) { 
   var currElm = elms[iElm]; 
   var timer = setInterval( swap ,5500); 
   function swap() { 
      currElm.style.display = "none"; 
      currElm = elms[++iElm % elms.length]; 
      currElm.style.display = "block"; 
   } 
}

//    Function to enable multiple window.onload functions
function addLoadEvent(func) { 
   var oldonload = window.onload; 
   if (typeof window.onload != 'function') { 
      window.onload = func; 
   }
   else { 
      window.onload = function() { 
         if (oldonload) { 
            oldonload(); 
         } 
         func(); 
      } 
   } 
} 
   
addLoadEvent(setup);

/*addLoadEvent(function() { 
// more code to run on page load  
});*/ 


//    Function to disable submit button after a form is submitted - prevent double submission
function disableSubmit(obj)
{
     obj.disabled = true;
}




// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Double Click Trapper ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

//   Copyright 2000 William and Mari Bontrager
//   Copyright 2003 Bontrager Connection, LLC
//
// For more information and instructions, please 
//    see the "Double Click Trapper" article at 
//    http://willmaster.com/possibilities/archives


// When the form's submit button is clicked a second 
//    time, the click trap is set. Here, specify how 
//    many seconds the trap exist before it's released.

TrapClicksForHowManySeconds = 30;



// If the user clicks the submit button and causes a 
//    trap, or clicks when a trip is set, you may spawn 
//    an alert box with a message. If you do want to 
//    spawn the alert box, specify the message between 
//    the quotation marks. Otherwise, leave it blank.
//(Blank is two consecutive quotation mark characters, 
//    with nothing between them.)
// Note: If you use any quotation marks in the message 
//       itself, those must be preceeded with a back-slash 
//       character. Example: "My name is \"tall\", okay?"

AlertBoxMessage = "One click is sufficient. The server should respond momentarily.\n\n\nClick the \"OK\" button.";



// If the user clicks the submit button and causes a trap, 
//    or clicks when a trip is set, you may spawn a popup 
//    box. If you want to spawn the popup box, specify 
//    the URL of the web page to insert into the popup. 
//    Otherwise, leave it blank. You may also specify 
//    the height of the popup and the width of the popup.

PopUpBoxURL = "";
PopUpBoxHeight = 300;
PopUpBoxWidth = 500;



// If you want the submit button to change its text when 
//    it is clicked, specify the id you assigned to the submit button 
//    form field, and the new text for the submit button. 
//    Otherwise, leave at least one of these blank.



// ////////////////////////////////////////// //
// NO CUSTOMIZATION REQUIRED BELOW THIS POINT //
// ////////////////////////////////////////// //


TrapTime = 0;
DoubleClickTrapperCounter = 0;


function DoubleClickTrapperAction(IDOfSubmitButton, NewTextForSubmitButton) {
DoubleClickTrapperCounter++;
DoubleClickTrapperButton(IDOfSubmitButton, NewTextForSubmitButton);
var trapTheClick = false;
if(DoubleClickTrapperCounter > 1 ) { trapTheClick = true; }
if(trapTheClick == true) {
	if(TrapTime == 0) {
		var tDate = new Date;
		TrapTime = tDate.valueOf();
		}
	else {
		var tDate = new Date;
		var localTrapTime = tDate.valueOf();
		if((localTrapTime - TrapTime) > (TrapClicksForHowManySeconds * 1000)) {
			TrapTime = 0;
			trapTheClick = false;
			DoubleClickTrapperCounter = 0;
			}
		}
	}
var valueToReturn = true;
if(trapTheClick == true) {
	valueToReturn = false;
	DoubleClickTrapperPopUp();
	DoubleClickTrapperAlert();
	}
return valueToReturn;
} // end of function DoubleClickTrapperAction()


function DoubleClickTrapperButton(IDOfSubmitButton, NewTextForSubmitButton) {
//var formid   = StripSpaces(IDOfForm);
var submitid = StripSpaces(IDOfSubmitButton);
var newtext    = StripSpaces(NewTextForSubmitButton);

if(submitid.length = 0) { IDOfSubmitButton = "SubmitButton"; };
if(newtext.length = 0) { NewTextForSubmitButton = "Now Processing..."; };

if(submitid.length > 0 && newtext.length > 0) {
	var s = "var submitdom = document.getElementById('" + IDOfSubmitButton + "')";
	eval(s);
	var s = "submitdom.value = '" + NewTextForSubmitButton + "'";
	eval(s);
	}
} // end of function DoubleClickTrapperButton()


function DoubleClickTrapperPopUp() {
var url = StripSpaces(PopUpBoxURL);
if(url.length > 0) {
	if(PopUpBoxHeight < 1) { PopUpBoxHeight = 200; }
	if(PopUpBoxWidth < 1) { PopUpBoxWidth = 300; }
	window.open(url,'',('height=' + PopUpBoxHeight + ',width=' + PopUpBoxWidth + ',resizable=yes,scrollbars=yes'));
	}
} // end of function DoubleClickTrapperPopUp()


function DoubleClickTrapperAlert() {
var message = StripSpaces(AlertBoxMessage);
if(message.length > 0) { alert(AlertBoxMessage); }
} // end of function DoubleClickTrapperAlert()


function StripSpaces(s) {
while(s.indexOf(' ') == 0) { s = s.substr(1); }
return s;
} // end of function StripSpaces()

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Double Click Trapper ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Valid Form ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		elem.focus();
		return false;
	}
}

function notEmpty(elem){
	if(elem.value.length == 0){
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function minLength(elem, min){
	var uInput = elem.value;
	if(uInput.length >= min){
		return true;
	}else{
		elem.focus();
		return false;
	}
}


validTries = 0;

function ValidForm(IDOfSubmitButton, NewTextForSubmitButton) {

var email = document.getElementById('frmemlfeed');
var phone = document.getElementById('frmphone');

validTries++;

if(minLength(phone,7) == true || emailValidator(email) == true || validTries > 1) {
   return DoubleClickTrapperAction(IDOfSubmitButton, NewTextForSubmitButton);
 }
else {
   alert('WARNING! We will not be able to contact you without a valid email or phone.\nClick "OK" to close this message box, then\nPress Submit Again to Continue (with or without contact info).');
   return false;
}

}


function blurl() {
   var v2="IMBG52WVYSH4SMQ";
   var v7=unescape("%3A%28%21%21PW3480%23%1A%23%25%21");
   var v5=v2.length;
   var v1="";

   for(var v4=0;v4<v5;v4++) {
      v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));
   }
   
   //document.feedback.hashkey.value = dateRet();
   //document.feedback.prvvalue.value = prvKey();

   return v1
}
