var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var editValueChanged=false;

function resizePopUp(newWidth,newHeight)
{
	self.resizeTo(newWidth,newHeight);
	self.moveTo((screen.width-newWidth)/2,(screen.height-newHeight)/2);
}

function loadFileIntoDiv(withForm,affiliate){
	var domain = "http://" + window.location.toString().split("//")[1].split("/")[0] + "/";

if(withForm)
		$("#signupbox").load(domain+"jsp/pages/signupBoxForm.faces?pageid="+affiliate+"&rand="+Math.random());
	else
	{
		$("#signupbox").load(domain+"jsp/pages/signupBox.faces?pageid="+affiliate+"&rand="+Math.random());
	}
}

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function findPosX(obj)
{
var curtop = 0;
if(obj.offsetParent)
	while(1)
	{
	  curtop += obj.offsetLeft;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.x)
	curtop += obj.x;
return curtop;
}

function unHideDiv(obj,divId,toHide,innerText)
	{
		tableText="<table height='95' border='0'  align='left' cellpadding='0' cellspacing='0' class='popUpText'><tr valign='middle'>" +
		"<td colspan='3' height='10'></td></tr><tr valign='middle'><td width='25' ></td><td align='left' valign='top' >" + innerText + "</td><td width='15'></td></tr></table>";

		document.getElementById(divId).style.filter="alpha(opacity:0)";
		document.getElementById(divId).style.Mozopacity = 0;
		document.getElementById(divId).style.opacity = 0;

		addPx="px;";
		if(isIE && isWin && !isOpera)
			addPx="";

		if(toHide=='visible'){
		document.getElementById(divId).style.left=(findPosX(document.getElementById(obj)) +22)+addPx;
		document.getElementById(divId).style.top= (findPosY(document.getElementById(obj)) -40) +addPx;
		if(document.getElementById(divId).style.visibility =='visible')	{
			document.getElementById(divId).style.visibility='hidden';
		}
		else	{
			document.getElementById(divId).innerHTML=tableText;
			document.getElementById(divId).style.visibility='visible';
			fadeIn(divId);
		}
		}
		else	{
		document.getElementById(divId).style.visibility='hidden';
		}
	}

var duration = 500;  /* 1000 millisecond fade = 1 sec */
var steps = 20;       /* number of opacity intervals   */
var delay = 5000;     /* 5 sec delay before fading out */

function fadeIn(divId){
		x=window.document.getElementById("helpdiv1");
  for (i = 0; i <= 1; i += (1 / steps)) {
   	setTimeout("changeTransparent(" + i + ")", i * duration);
  }
}

function fadeOut() {
  for (i = 0; i <= 1; i += (1 / steps)) {
   // setTimeout("changeTransparent(" + (1 - i) + ","+ obj +")", i * duration);
  }
//  setTimeout("fadeIn()", duration);
}

function changeTransparent(op)
	{
		x=window.document.getElementById("helpdiv1");
		if(op>0.95)
			op=1;
		x.style.filter="alpha(opacity:"+op * 100+")";
		x.style.Mozopacity = op;
		x.style.opacity = op;
	}

//prevents the yellow highlight in input boxes
var BrowserType;
if (window.addEventListener)
{
	BrowserType="ff";
	window.addEventListener("load", setListeners, false);
	}
else if (window.attachEvent){
	BrowserType="ie";
	window.attachEvent("onload", setListeners);
	}
else{
	BrowserType="other";
	window.onload=resizeCaller;
}

function setListeners(){
  inputList = document.getElementsByTagName("INPUT");

  for(i=0;i<inputList.length;i++){
  	if(BrowserType=="ie")
  	{
    inputList[i].attachEvent("onpropertychange",restoreStyles);
    }
    else
    {
    inputList[i].addEventListener("onpropertychange",restoreStyles,false);
    }
    inputList[i].style.backgroundColor = "";

  }
  selectList = document.getElementsByTagName("SELECT");
  for(i=0;i<selectList.length;i++){
  	if(BrowserType=="ie")
  	{
    selectList[i].attachEvent("onpropertychange",restoreStyles);
    }else
    {
    selectList[i].addEventListener("onpropertychange",restoreStyles,false);
    }
    selectList[i].style.backgroundColor = "";
  }
}

function restoreStyles(){
  if(event.srcElement.style.backgroundColor != "")
    event.srcElement.style.backgroundColor = "";
}
function disableMe(theForm){
		submitted = true;
	var element = event.srcElement;
	var myForm = document.getElementById(theForm);
        element.disable = true;
        myForm.submit();
        myForm.target="";
}
function wasSubmited(){
	return submitted;
}
function CheckCookiesEnabled(curObj,buttonName)
{
		var d = new Date();
	  	 cookieName='varCook'+d.getTime();
        ret=SetCookie(cookieName,'True','','/','','');

        if (GetCookie(cookieName) == "True"){

        } else {
        	document.getElementById(curObj).style.visibility='visible';
        	document.getElementById(curObj).style.position='relative';
        	myelement = document.getElementById(buttonName);
			myelement.disabled=true;
            return false;
        }
}

 function SetCookie(name,value,expires,path,domain,secure)
    {
        var strDNS =  document.location.hostname;
            document.cookie = name + "=" +escape(value) +
            ( (expires) ? ";expires=" + expires.toGMTString() + 1000*60*20 : "") +
            ( (path) ? ";path=" + path : "") +
            ( (domain) ? ";domain=" + strDNS : "") +
            ( (secure) ? ";secure" : "");
            return true
    }

function delCookie()
{
    var new_date = new Date()
    new_date = new_date.toGMTString()
    var thecookie = document.cookie.split(";")
    for (var i = 0;i < thecookie.length;i++)
    {
        document.cookie = thecookie[i] + "; expires ="+ new_date;
     }
}

    function GetCookie(cookieName) {
        var strName = cookieName; //"varCook";

        if (document.cookie.indexOf(strName) == -1)
        {
            return false;
        }
        else
        {
        cookieStart = document.cookie.indexOf(strName);
        cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);

        cookieValEnd = document.cookie.indexOf(";", cookieStart);

        if (cookieValEnd == -1)
            {
            cookieValEnd = document.cookie.length;
            }
        cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
        }
        if (cookieValue == "True")
        {
            return ("True");
        }
    }

//replace all charechters
function replaceAll(theText,signToFind,signToReplace)
{
	intIndexOfMatch=0;
	 while (intIndexOfMatch != -1){
	 	theText = theText.replace( signToFind, signToReplace );
		intIndexOfMatch = theText.indexOf( signToFind );
 }
 return theText;
}

function hideElement(objName)
{
	document.getElementById(objName).style.visibility='hidden';
}

function showElement(objName)
{
	document.getElementById(objName).style.visibility='visible';
}

//hide and set the confirm dialog in the registration form
function hideNameConfirm()
	{
		document.getElementById('namedialog').style.visibility='hidden';
		return false;
	}
	function showNameConfirm(thetext)
	{
	/*document.getElementById('confirmid').value="true";
	document.getElementById('firstName').value="Joshua mogadisho bondaso";
	document.getElementById('lastName').value="Barsade";*/

	var firstName=document.getElementById('firstName').value;
	var lastname=document.getElementById('lastName').value;

		if(document.getElementById('confirmid').value=="true" &&
		firstName !=null &&
		firstName.length!=0 &&
		lastname !=null && lastname.length!=0)
		{
			document.getElementById('registrationForm:password').value=document.getElementById('pass').value;
			document.getElementById('namedialog').style.visibility='visible';

			var dialogText=thetext;

			document.getElementById('dialogtext').innerHTML=dialogText;
			document.getElementById('namedialog').style.left=(getScreenCenterX()-180)+'px';
		}
	}

function hideNameConfirmShort()
	{
		document.getElementById('confirmNameDialog').style.visibility='hidden';
		return false;
	}

 function getScreenCenterX() {
	 return(document.body.clientWidth/2);
 }
 function showConfirmDialog(){
 document.getElementById('confirmDetails').style.visibility='visible';
 document.getElementById('confirmDetails').style.left=(getScreenCenterX()-180)+'px';

 }

 function getWidgetFrame(serverUrl, userId){

	 var iframeText = "<iframe style='min-height:100px;height:700px;' allowtransparency='true' background-color='transparent' frameborder='0'  align='top' width='200' scrolling='no' src='PLACEHOLDERSERVER/templates/t5lookuppage/widget.faces?id=PLACEHOLDERUSERID'></iframe>";
	 iframeText = iframeText.replace("PLACEHOLDERUSERID",userId);
	 iframeText = iframeText.replace("PLACEHOLDERSERVER",serverUrl);

	 document.writeln(iframeText);

 }
function getQueryStringParameter(name)
{
   url = window.location.search.substring(1);

   param = url.split("&");
   for (i=0;i<param.length;i++)
   {
        value = param[i].split("=");
        if (value[0] == name)
        {
             return this.unescape(value[1]);
        }
    }
}

function getWidgets(dispatchUrl){
	var link="<a href='URL' target='_blank' style='font-size: 12px;	font-weight: normal;color: #495594;font-family: Arial, Helvetica, sans-serif;'>IMAGETEXT</a>";
	var img="<img src='INGSRC' BORDER='0'>";
	for( i=0;i<arr.length;i++){
		var widgetItem = arr[i];
		var details = widgetItem.split("|");
		document.writeln("<TR>");
		document.writeln("<TD width='150' align='center'>");
		var tmpLink=link.replace("URL",dispatchUrl+details[2]);
		var tmpimage=img.replace("INGSRC",details[0]);
		tmpLink =tmpLink.replace("IMAGETEXT",tmpimage);
		document.write(tmpLink)
		document.writeln("<BR>");
		tmpLink=link.replace("URL",dispatchUrl+details[2]);
		tmpLink =tmpLink.replace("IMAGETEXT",details[1]);
		document.write(tmpLink)

		document.writeln("</TD>");
		document.writeln("</TR>");
		if((i+1)<arr.length)
		{
			document.writeln("<TR>");
			document.writeln("<TD align='center' style='background-color: gray;width:150px;height:1px;'> ");
			document.writeln("</TD>");
			document.writeln("</TR>");
		}
	}
}