// JScript source code

function openwindow(page, args)
{
window.open(page, "_blank", args);
}

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 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 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 highlight(id, classname)
	{
		var obj = document.getElementById(id);
		if(obj)
		{
		obj.className=classname;
		}
	}

function instr(v, srch)
{
 if (v.indexOf(srch)>0)
  {
  return true;
  }
  else
  {
  return false;
  }
}
function countit(val, max, obj)
{
var txt = val.value;
var l = txt.length;
    
    if(l>max)
    {
      val.value = Left(txt, max)
    }
	if(l>=0)
	{
	document.getElementById(obj).innerHTML = '(<b>Current Length:&nbsp;'+ l+'</b>&nbsp;&nbsp;Maximum: '+max+')';
	}
}	

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 InsertIntoTextarea(objID,obj) {
        var ta=document.getElementById(objID);
        var sel;
        var str = obj.value;
        if (document.selection) {  
           ta.focus();        
           sel = document.selection.createRange();
           if (!sel) return;
           sel.text = str;
        }
        else if (ta.selectionStart || ta.selectionStart == '0') {
          var startPos = ta.selectionStart;
          var endPos = ta.selectionEnd;
          ta.value = ta.value.substring(0, startPos)+ str+ta.value.substring(endPos, ta.value.length);
        } else {
        ta.value += str;
    }
 }

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 + ")";
} 

/*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 SetSiteCookie (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 GetSiteCookie(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 (GetSiteCookie(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;
}

//jquery required
//==============
$(document).ready(function() {
$('a').click(function() {
        var curHost = (("https:" == document.location.protocol) ? "https://www." : "http://www.");
        $.post(curHost+'marketingprofsu.com/track', { txt: $(this).text(), curpage: window.location.href, tgtpage: $(this).attr("href") });
        return true;
    });
});

function scrolltotop() { jQuery("html, body").animate({ scrollTop: 0 }, "slow"); }

function showDirectOverlay(title, url, width, height, modal, params) {
	//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;
	var m_inline;
	var ustr = url;
	
	//determine if URL or referencing an on-page container
	
	if(ustr.charAt(0)=='#'){
		m_inline=true;
	} else {
		m_inline=false;
	}

	//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;
	}
	
	$.colorbox({title:title,href:url,inline:m_inline,width:m_width,height:m_height, opacity:0.6, 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();
		}
	}})
}
  
function closeOverlay(id) {
	//id not needed for the current implementation, just there as a placeholder
	$.colorbox.close()
}

function getParameterFromURL(uri, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(uri);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

//track social
//=====================================
$(document).ready(function() {
if (typeof twttr != 'undefined') {
        twttr.events.bind('tweet', function(event) {
            if (event) {
                var targetUrl;
                if (event.target && event.target.nodeName == 'IFRAME') {
                    targetUrl = getParameterFromURL(event.target.src, 'url');
                }
                _gaq.push(['_trackSocial', 'twitter', 'tweet', targetUrl]);
            }
        });
    }
});

//facebook tracksocial
window.fbAsyncInit = function() {
    FB.init({ xfbml: true, channelUrl: 'http://www.marketingprofsu.com/includes/jscript/fb/channel.html' });
    FB.Event.subscribe('edge.create', function(targetUrl) {
        _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
    });
    FB.Event.subscribe('edge.remove', function(targetUrl) {
        _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
    });
    FB.Event.subscribe('message.send', function(targetUrl) {
        _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);
    });

};
//==================================track social end
