//PUT DOMAIN OF WEBSITE HERE; TO ALLOW THS SCRIPT TO IDENTIFY WHETHER LINK IS INTERNAL OR EXTERNAL.
var MySiteDomain='www.ibm.com/software/';
var max=10;

function XBrowserAddHandlerPops(target,eventName,handlerName) {
  if ( target.addEventListener ) {
    target.addEventListener(eventName, function(e){target[handlerName](e);}, false);
  } else if ( target.attachEvent ) {
    target.attachEvent("on" + eventName, function(e){target[handlerName](e);});
  } else {
    var originalHandler = target["on" + eventName];
    if ( originalHandler ) {
      target["on" + eventName] = function(e){originalHandler(e);target[handlerName](e);};
    } else {
      target["on" + eventName] = target[handlerName];
    }
  }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



var x = readCookie('surveycookie');

if (!x) {
//alert("STEP1");

var randomNo;

randomNo=Math.floor(Math.random()*max+1);
//if (randomNo==2) {
//EXECUTION CODE GOES HERE
//alert("STEP2");
	$(document).ready(function(){ tb_show('Survey Question', '/software/websphere/survey/surveySoftware/step1.html?height=325&width=450&inlineId=displayWarning&modal=true', null); });
	createCookie('surveycookie','isActive',28);

//} //FOR RANDOMNO

}


	//eraseCookie('surveycookie');




var Page_ShowPopOnExit = true;



function InternalLink() {
    Page_InternalDest = (this.action != undefined) ? this.action : this;
    Page_ShowPopOnExit = false;
}



function ExternalLink() {
    Page_ExternalDest = (this.action != undefined) ? this.action : this;
		Page_ShowPopOnExit = true;
}


function LinkConvert()
{
	var href;
	var anchors = document.getElementsByTagName('a');

	for(var y=0; y<anchors.length; y++)
	{
		href = anchors[y].href.toLowerCase();
		if (!(href.indexOf("http://")!=-1 && href.indexOf(MySiteDomain)==-1))
			{

			anchors[y].clickhandler=InternalLink
			XBrowserAddHandlerPops(anchors[y],"click","clickhandler");
			}
	}
}










function popup()
{
  win=window.open("/software/websphere/survey/surveySoftware/popupquestions.html", "win","width=675,height=675,top=0,left=0,scrollbars=no");
  //win.blur();
  tb_remove();
}


function siteExit() {
  	 //alert("Page_ShowPopOnExit: " + Page_ShowPopOnExit);
	 //alert("YES...WORKING...0"+Page_ShowPopOnExit);
if (Page_ShowPopOnExit == true) {
	 //alert("YES...WORKING...1");
	 var isActive=readCookie('surveypopup');
	 //alert("IS ACTIVE: " + isActive);
	 if (isActive) {
     //if (win) {
	  //alert("YES...WORKING...2");
	  win=window.open("/software/websphere/survey/surveySoftware/popupquestions.html", "win","width=675,height=675");
	  eraseCookie('surveypopup');
	  self.blur();
	  win.focus();
	 }
	 //}
  }
}

//alert(Page_ShowPopOnExit);

//onload=LinkConvert;

$(document).ready(function(){
LinkConvert();
});

onunload=siteExit;

