﻿// JScript File
//Global Vars
var URL_noop = 0
      function CallPageMethod(methodName, onSuccess, onFail) {
          var args = '';
          var l = arguments.length;
          if (l > 3) {
              for (var i = 3; i < l - 1; i += 2) {
                  if (args.length != 0) args += ',';
                  args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
              }
          }
          var loc = "/services/rendering.aspx";
          $.ajax({
              type: "POST",
              url: loc + "/" + methodName,
              data: "{" + args + "}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: onSuccess,
              fail: onFail
            });
      }

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
        //If set to 0 then expire cookie on end of session
        if (expires==0){
		document.cookie = name + "=" + escape (value) + 
		";path=/";
		}else{
		document.cookie = name + "=" + escape (value) + 
		"; expires=" + expires.toGMTString() +  "; path=/";
		}

}

function getCookie (name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

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 getHTMLEncode(t) {
return t.toString().replace(/&/g,"&amp;").replace(/""/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}	
	
function addToFavorites(urlAddress,pageName)
{
    if (window.sidebar) {window.sidebar.addPanel(pageName, urlAddress,"");} // Mozilla Firefox Bookmark
    else if(window.external){window.external.AddFavorite(urlAddress,pageName);} // IE Favorite
    else if(window.opera && window.print){return true;} // Opera Hotlist
    else {alert("Sorry! Your browser doesn't support this function.");} 
} 

function flash_banner(s,w,h)
{
   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '">\n');
   document.write('<param name="movie" value="/showpicture.aspx?bid=' + s + '" />\n');
   document.write('<param name="quality" value="high" />\n');
   document.write('<embed src="/showpicture.aspx?bid=' + s + '" quality="high" pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>\n');
   document.write('</object>\n');
}

function custom_flash_banner(s,w,h)
{
   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '">\n');
   document.write('<param name="movie" value="' + s + '" />\n');
   document.write('<param name="quality" value="high" />\n');
   document.write('<embed src="' + s + '" quality="high" pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>\n');
   document.write('</object>\n');
}

function openLrgImgWin(theURL,winName,winWidth,winHeight,otherFeatures) {
   var x = 0;
   var y = 0;
   x = (screen.availWidth - 1 - winWidth);
   y = (1);
   if (otherFeatures != "") {otherFeatures = "," + otherFeatures}
   var features = "screenX=" + x + ",screenY=" + y + ",width=" + winWidth
                + ",height=" + winHeight+",top="+y+",left="+x+"'"
                + otherFeatures;
   var popWindow = window.open(theURL,winName,features);
   popWindow.focus();
}

//Get QueryString 
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}
//Parse Querystring set some variables
QueryString_Parse();
    var expdate = new Date();
    var expireSess = "0"
    expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	if (window.location.search.match('spMailingID')){
		setCookie('spMailingID',QueryString('spMailingID'),expdate)
	}
	if (window.location.search.match('spUserID')){
		setCookie('spUserID',QueryString('spUserID'),expdate)
	}
	if (window.location.search.match('spJobID')){
		setCookie('spJobID',QueryString('spJobID'),expdate)
	}
//BVARS	
	if (window.location.search.match('bvar3')){
		setCookie('bvar3',QueryString('bvar3'),expireSess)
	}
	if (window.location.search.match('bvar4')){
		setCookie('bvar4',QueryString('bvar4'),expireSess)
	}
	if (window.location.search.match('bvar7')){
		setCookie('bvar7',QueryString('bvar7'),expireSess)
	}
	if (window.location.search.match('bvar5')){
		setCookie('bvar5',QueryString('bvar5'),expireSess)
	}
	if (window.location.search.match('bvar6')){
		setCookie('bvar6',QueryString('bvar6'),expireSess)
	}
	if (window.location.search.match('bvar9')){
		setCookie('bvar9',QueryString('bvar9'),expireSess)
	}
		if (window.location.search.match('Bvar3')){
		setCookie('bvar3',QueryString('Bvar3'),expireSess)
	}
	if (window.location.search.match('Bvar4')){
		setCookie('bvar4',QueryString('Bvar4'),expireSess)
	}
	if (window.location.search.match('Bvar7')){
		setCookie('bvar7',QueryString('Bvar7'),expireSess)
	}
	if (window.location.search.match('Bvar5')){
		setCookie('bvar5',QueryString('Bvar5'),expireSess)
	}
	if (window.location.search.match('Bvar6')){
		setCookie('bvar6',QueryString('Bvar6'),expireSess)
	}
	if (window.location.search.match('Bvar9')){
		setCookie('bvar9',QueryString('Bvar9'),expireSess)
	}

// Return the decoded string
function URLDecode(psEncodeString){
  var lsRegExp = /\+/g;
  return unescape(String(psEncodeString).replace(lsRegExp, " ")); 
}

function stringcount(strword,lookforitem){
count = 0;
pos = strword.indexOf(lookforitem);
while ( pos != -1 ) {
   count++;
   pos = strword.indexOf(lookforitem,pos+1);
}
 return  count++
}

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);
    }
}



