// JScript source code

function openwindow(page, width, height)
{
window.open(page, "_blank", "height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
}


function PopupBlocked() {
    var pbt = window.open(null, "", "width=100,height=100");
    try { pbt.close(); return false; }
    catch (e) { return true; }
}

-


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;
strString = strString+"";
   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 formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function nosee(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function cansee(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}


function showhide_all_divs(link_id, default_text, switch_text)
{
var array_obj = document.getElementsByTagName("DIV");
var link_obj = document.getElementById(link_id);

	for(var i=0;i<=array_obj.length;i++)
	{
	//alert(array_obj[i].style.display);
	if(array_obj[i].style.display=='')
			{
			array_obj[i].style.display='none';
			link_obj.innerHTML = switch_text;
			}
			else
			{
			array_obj[i].style.display='';
			link_obj.innerHTML = default_text;
			} 
			
			
	}

}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function showhide_all_spans(link_id, default_text, switch_text)
{
var array_obj = document.getElementsByTagName("SPAN");
var link_obj = document.getElementById(link_id);

	for(var i=0;i<=array_obj.length;i++)
	{
	//alert(array_obj[i].style.display);
		if(array_obj[i])
		{
				if(array_obj[i].style.display=='')
				{
				array_obj[i].style.display='none';
				link_obj.innerHTML = switch_text;
				}
				else
				{
				array_obj[i].style.display='';
				link_obj.innerHTML = default_text;
				} 
		}	
			
	}

}

function togglevisible(divname, aname, showname, hidename)
	{
		var obj = document.getElementById(divname);
		var a = document.getElementById(aname);
		
		
		if(obj.style.display=="none")
		{
		obj.style.display="";
		a.innerHTML = hidename;
		}
		else
		{
		obj.style.display="none";
		a.innerHTML = showname;
		} 
	}
function showpreview(divname, aname, showname, hidename)
	{
		var obj = document.getElementById(divname);
		var a = document.getElementById(aname);
		
		
		if(obj.className=="preview_off")
		{
		obj.className="preview_on";
		a.innerHTML = hidename;
		}
		else
		{
		obj.className="preview_off";
		a.innerHTML = showname;
		} 
	}
	
function instr(v, srch)
{
 if (v.indexOf(srch)>0)
  {
  return true;
  }
  else
  {
  return false;
  }
}
	
	
function validemail(eml)
	{
	var reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

        //make sure this is a valid email address
        if (!reEmail.test(eml)) {
            alert("Please enter a valid email address to continue.");
           return false;
        }
        return true;
    }
    
function feedpop(URL) {
var popthis=URL+'&s=2420';
var windowprops = "location=no,menubars=yes,toolbars=no,resizable=yes,scrollbars=no,width=620,height=230";
popup = window.open(popthis,"MenuPopup",windowprops);

}
function blogpop(URL) {
var windowblog = "location=yes,menubars=yes,toolbars=yes,resizable=yes,scrollbars=yes,width=400,height=560";
blogpopup = window.open(URL,"blogMenuPopup",windowblog);


}
function imagepop(URL) {

var windowblog = "location=yes,menubars=yes,toolbars=yes,resizable=yes,scrollbars=yes,width=600,height=560";
imagepop = window.open(URL,"imagepop",windowblog);


}

function premiumpop(URL) {
var windowblog = "location=yes,menubars=yes,toolbars=yes,resizable=yes,scrollbars=yes,width=400,height=350";
blogpopup = window.open(URL,"blogMenuPopup",windowblog);


}

function winPopup(page, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,location=no,menubars=no,toolbars=no,resizable=yes';
	var win = window.open(page, 'popup', winprops)
	return true;
}

function Minimize(obj)
{
obj.innerWidth = 100;
obj.innerHeight = 100;
obj.screenX = screen.width;
obj.screenY = screen.height;
alwaysLowered = true;
}

function Maximize(obj)
{
obj.innerWidth = screen.width;
obj.innerHeight = screen.height;
obj.screenX = 0;
obj.screenY = 0;
alwaysLowered = false;
}


function fader(id, oStart, oEnd, mSec) {
    
    var speed = Math.round(mSec / 100);
    var timer = 0;
    

    if(oStart > oEnd) {
        for(i = oStart; i >= oEnd; i--) {
            setTimeout("setOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(oStart < oEnd) {
        for(i = oStart; i <= oEnd; i++)
            {
            setTimeout("setOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function setOpacity(val, id) {
    var object = document.getElementById(id).style;
    object.display = "block";
    object.opacity = (val / 100);
    object.MozOpacity = (val / 100);
    object.KhtmlOpacity = (val / 100);
    object.filter = "alpha(opacity=" + val + ")";
        if(val == 0)
        document.getElementById(id).style.display = 'none';
} 

/*window.onload = function(e) {
   if (document.getElementById && document.getElementById("savedsize") != null) {
	if(document.getElementById("savedsize").value == "")
		resetsavedsize();
	else
		setsavedsize(document.getElementById("savedsize").value);
 
    document.getElementById("textSizer").style.cssText = "display: block; float: right;";
  }
}*/
var settosize=12
	
function getsavedsize() {
  return settosize;
}

function setsavedsize(newsize, obj) {
  settosize = newsize;
  if (document.getElementById) {
  	document.getElementById(obj).style.cssText = "font-size:"+settosize+"px;";
  	
  }  
}

function resetsavedsize(obj) {
  settosize = 12;
 // document.getElementById("savedsize").value = savedsize;
  if (document.getElementById) {
  	document.getElementById(obj).style.cssText = "font-size:"+settosize+"px";  	
  }
}

function fontbigger(obj) {
  if (document.getElementById) {
    settosize++;
    //document.getElementById("savedsize").value = savedsize;
    document.getElementById(obj).style.cssText = "font-size:"+settosize+"px";
  }
}

function fontsmaller(obj) {
  if (document.getElementById) {
    settosize--;
    document.getElementById(obj).style.cssText = "font-size:"+settosize+"px";
  }
}

//==============cookies
// JScript source code
function setMPCookie (name,value,expires,path,theDomain,secure) { 
   value = escape(value);
   var theCookie = name + "=" + value + 
   ((expires)    ? "; expires=" + expires.toGMTString() : "") + 
   ((path)       ? "; path="    + path   : "") + 
   ((theDomain)  ? "; domain="  + theDomain : "") + 
   ((secure)     ? "; secure"            : ""); 
   document.cookie = theCookie;
} 

function getMPCookie(Name) { 
   var search = Name + "=" 
   if (document.cookie.length > 0) { // if there are any cookies 
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value 
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value 
         if (end == -1) end = document.cookie.length 
         return unescape(document.cookie.substring(offset, end)) 
      } 
   } 
} 
function delMPCookie(name,path,domain) {
   if (getMPCookie(name)) document.cookie = name + "=" +
      ((path)   ? ";path="   + path   : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function MPCookieExists(name){var rs=null;var mc=" " + document.cookie + ";";
var sn=" " + name + "=";var sc=mc.indexOf(sn);var ec;
if (sc!=-1) {sc+=sn.length;ec=mc.indexOf(";",sc);
rs=unescape(mc.substring(sc,ec));}return rs;}


function removehtml(v)
{
var oldtext = v;
var newtext = oldtext.replace(/<[^>]+>/g,'');
return newtext;
}

function countchars(val, max, msgname)
{
var txt = val.value;
var l = txt.length;
    
    if(l>max)
    {
      val.value = Left(txt, max)
    }

	if(document.getElementById(msgname))
		{
		if(l>0)
		{
			document.getElementById(msgname).innerHTML = '<b>Length: '+ l+'<br>Maximum: '+max+'</b>';
		}
		else
		{
			document.getElementById(msgname).innerHTML = '';
		}
		}
}

function setclassname(objname, newclass)
	{
		var obj = document.getElementById(objname);
		obj.className=newclass;
	}
//==============


function isWhitespace (charToCheck)
{
	var whitespaceChars = " \t\n\r\f";
	return whitespaceChars.indexOf (charToCheck) != -1;
}

function ltrim (str)
{
	for (var k = 0; k < str.length && isWhitespace (str.charAt (k)); k++);
	return str.substring (k, str.length);
}

function rtrim (str)
{
	for (var j = str.length-1; j >= 0 && isWhitespace (str.charAt (j)); j--);
	return str.substring (0, j+1);
}

function trim (str)
{
	return ltrim (rtrim (str));
}

function KeepAlphaNum (str)
{
	var result = "";
	for (var i = 0; i < str.length; i++)
	{
		var c = str.charAt (i).toLowerCase ();
		if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c == ' '))
		{
			result += c;
		}
	}
	result = trim (result);
	return result;
}

function addinnerhtml(elem, v)
{
obj = document.getElementById(elem);
	if(v!='')
	{
	obj.innerHTML=v;
	}
	else
	{
	obj.innerHTML='';
	}
}
 
 function removetags(v)
 {
 str = v;
 return str.replace(/<[^>]+>/g,'')
 }
 
 function sponsored_link_track(id)
 {
  ajaxgo('/advertising/track/?id='+id);
 }


function URLEncode (clearString) {
           var output = '';
           var x = 0;
           clearString = clearString.toString();
           var regex = /(^[a-zA-Z0-9_.]*)/;
           while (x < clearString.length) {
               var match = regex.exec(clearString.substr(x));
               if (match != null && match.length > 1 && match[1] != '') {
               	  output += match[1];
                  x += match[1].length;
               } else {
                  if (clearString[x] == ' ')
                      output += '+';
                  else {
                      var charCode = clearString.charCodeAt(x);
                      var hexVal = charCode.toString(16);
                      output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
                  }
               x++;
               }
           }
      return output;
  }

  function showDirectOverlay(title, url, width, height, modal, params, objParams) {
		//params is not currently used, just there in case it's needed later..
		
		var m_width;
		var m_height;
		var m_iframe;
		var m_transition;
		var m_escKey;
		var m_overlayClose;
		
		//Setup width
		if(width<0) {
			m_width=false;
		} else {
			m_width=width+'px';
		}
		
		//Setup height
		if(height<0) {
			m_height=false;
		} else {
			m_height=height+'px';
		}
		
		//Set transition, disable effect for IE
		if(navigator.userAgent.indexOf('MSIE') !=-1) {
			m_transition = 'none';
		} else {
			m_transition = 'elastic';
		}
		 
		//Setup modal mode variables
		if(modal==true) {
			m_escKey = false;
			m_overlayClose = false;
		} else {
			m_escKey = true;
			m_overlayClose = true;
		}
		
		//Setup IFrame option
		if(params.indexOf('iframe:true') !=-1) {
			m_iframe=true;
			if(m_height==false) m_height=450;
		} else {
			m_iframe=false;
		}
		  
		var objBase = {title:title,href:url,width:m_width,height:m_height, opacity:1.0, overlayClose:m_overlayClose, escKey:m_escKey, transition:m_transition, iframe:m_iframe,
						onComplete: function() {
							//Only resize if no IFrame
							if(params.indexOf('iframe:true') ==-1) {
								$.colorbox.resize();
							}		
						},
						onCleanup: function(){
							if(params.indexOf('iframe:true') !=-1) {
								$('.cboxIframe').attr('src', 'http://www.marketingprofs.com/preview/popupclose.html');
							}
						}} ;
		var objFinal = {};
		
		//create array and add base parameters passed in directly, fixed params
	    for(var item in objBase) {
			objFinal[item] = objBase[item];
		}		
		//add the parameters from obj passed in (variable params/values)
	    for(var item in objParams) {
			objFinal[item] = objParams[item]
		}	

		//call function with combined parameters in object		
		$.colorbox(objFinal)
  }
  
  function closeOverlay(id) {
		//id not needed for the current implementation, just there as a placeholder
		$.colorbox.close()
  }
    
  (function($) {

      $.fn.extend({

          //pass the options variable to the function
          getpage: function(options) {


              //Set the default values, use comma to separate the settings, example:
              var defaults = {
                  url: '/api/src/articlelist.asp',
                  category: 0,
                  recs: 10,
                  bakecookie: true,
                  cookiename: 'mpcat',
                  fader: true
              }

              var options = $.extend(defaults, options);

              return this.each(function() {
                  var o = options;
                  if (o.fader) { $(this).fadeOut(); }
                  $(this).load(o.url, { category: o.category, recs: o.recs });
                  if (o.fader) { $(this).fadeIn(); }
                  if (o.bakecookie) { $.cookie(o.cookiename, o.category, { expires: 1, path: '/', domain: '' }); }
              });
          }
      });

  })(jQuery);
  
  $(document).ready(function() {
	  $('.showpopup').colorbox();
  });

  $(document).ready(function() {
	$(".disableonsubmit").click(function(){  
		$(".disableonsubmit").each(function(i){
			$(this).clone().attr("value", " working.. ").attr("disabled", "disabled").attr("id", "").removeClass('disableonsubmit').insertAfter(this);
			$(this).hide();
		});
	});
  });
  
  function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

//ensure drop menus in the nav bar stay within the site content width
$(function() {
   $('#navbar ul.tabs li.dropmenu').hover( function(){
	var iDropLeft = 0;
	var iDropRight = $(this).offset().left + $(this).find('.dropnav').outerWidth();
	var iNavRight = $("#navbar").offset().left + $("#navbar").outerWidth();
	if(iDropRight > iNavRight) iDropLeft = iNavRight - iDropRight;
	$(this).find('.dropnav').css('left', iDropLeft);
   },
   function(){
	$(this).find('.dropnav').css('left','-9999px');
   });
});

/* begin drawer code */ 

$(document).ready(function(){ 
	$(".drawer_form_reset").click(function () { 
		$(".error_border").removeClass("error_border");
		resetDrawerForm();
		$("#drawer").hide();}
	); 

	$.validator.addClassRules("jvnonzero", {
		required: true,
		min: 1
	});
 
	$(".drawer_form").validate(
		{
			onfocusout: false,
			focusInvalid: false, //prevents form auto-scrolling to first problem field, can be visually disorienting
			errorClass: "no_qualifier",  //necessary to prevent validator from inappropriately replacing existing <label> values..
			showErrors: function(errorMap, errorList) {
				var i, length = errorList.length, el;
				for (i = 0; i < length; i++) {
					el = errorList[i].element;
					$("#" + el.id).addClass("error_border");}
			},
			invalidHandler: function (form, validator) {
					$(".error_border").removeClass("error_border");
					var drawer = $("#drawer"); 
					drawer.html("<h3>Please review the required fields marked with a red border.</h3>");
					drawer.slideDown('fast',function()  {setTimeout(function() { drawer.slideUp('fast'); }, 7500);});
				},
			submitHandler: function (form, validator) {
				$(".drawer_form .drawer_submit").each(function(i){$(this).hide();});	
				$(".drawer_form .drawer_submit_processing").each(function(i){$(this).show();});					
				var drawer = $("#drawer");				
				drawer.slideUp();
				setTimeout(function() { 
					var drawer = $("#drawer");
					drawer.html('<h3><a href="javascript:resetDrawerForm();">Hmmm ... submitting this form seems to be taking too long.  Click this message to reset and try again.</a></h3>');
					drawer.slideDown('fast');
				}, 18000);
				form.submit();
			}
		}
	);
});


function resetDrawerForm(){
$(".drawer_submit_processing").each(function(i){$(this).hide();});  
$(".drawer_submit").each(function(i){$(this).show();});
}
/* end drawer code */

(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)



