﻿// RFP Manager 
// Common JavaScript File

var popUp; 

/* Applicaton path, development and production might be different */
/* Lifted from http://www.gotknowhow.com/articles/how-to-get-the-base-url-with-javascript.aspx */
function basePath() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));

    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }
}

/* Next two functions for the AspxGrid popup date field */
function OpenCalendarPopup(idname) {
	popUp = window.open(basePath() + 'Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate) {
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;				
}


/* ----------------------------------------------------------
* pop
*	Accepts: URL 	(location of page/image to display)
*			 width  (browser window width)
*			 height (browser window height)
*	Creates a new window with the specified height, width,
*	and URL. Focuses the new window.
---------------------------------------------------------- */
function pop(URL, width, height) {
    
	var status = "1";
	var menubar = "1";
	var scrollbars = "1";
	var resizable = "yes";
	var location = "1";
	var toolbar = "1";
	var directories = "0";
	
	var strOptions = "width=" + width + ",height=" + height + ",toolbar=" + toolbar + ",location=" + location + ",directories=" + directories + ",status=" + status + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ",resizable=" + resizable;
	
	popWindow = window.open(URL, "popWindow", strOptions)
	popWindow.focus();
}

/* see comments.txt */
function obfuscateMailLinks()
{
  var a = "ma";
  var b = "ilt";
  var c = "o:";
  if (!document.getElementsByTagName) { return; }
  ar_spans = document.getElementsByTagName('span');
  for (i=0; i<ar_spans.length; i++)
  {
    if (ar_spans[i].className == 'obfmail' && ar_spans[i].firstChild != null)
    {
      ex = ar_spans[i].firstChild.nodeValue.split(',');
      tmp = document.createElement('a');
      tmp.href = a + b + c + ex[1] + '@' + ex[0];
      tmp.title = "Send em" + "ail to " + ex[2];
      tmp.appendChild(document.createTextNode(ex[2] ? ex[2] : ex[1] + '@' + ex[0]));
      ar_spans[i].replaceChild(tmp, ar_spans[i].firstChild);
    }
  }
}    
