
function positionInfo(object)
{

  var p_elm = object;

  this.getElementLeft = getElementLeft;

  function getElementLeft()
  {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object")
    {
      elm = p_elm;
    }
    else
    {
      elm = document.getElementById(p_elm);
    }
    while (elm != null)
    {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }

  this.getElementWidth = getElementWidth;
  function getElementWidth()
  {
    var elm;
    if(typeof(p_elm) == "object")
    {
      elm = p_elm;
    }
    else
    {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight()
  {
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop()
  {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object")
    {
      elm = p_elm;
    }
    else
    {
      elm = document.getElementById(p_elm);
    }
    while (elm != null)
    {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight()
  {
    var elm;
    if(typeof(p_elm) == "object")
    {
      elm = p_elm;
    }
    else
    {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom()
  {
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
}

function trim(stringToTrim)
{
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function setElementProperty(p_property, p_value, p_elmId)
{
  var p_elm = p_elmId;
  var elm = null;

  if(typeof(p_elm) == "object")
  {
    elm = p_elm;
  }
  else
  {
    elm = document.getElementById(p_elm);
  }
  if((elm != null) && (elm.style != null))
  {
    elm = elm.style;
    elm[ p_property ] = p_value;
  }
}


function createFormDiv(currentFieldId, html, width, height, xOffset, yOffset)
{
  //alert(currentFieldId + len + width);
  htmlInner = "<img src='/images/closePopup.gif' onclick='javascript:hidePopup();setHomepage(0,0);' style=\"position:absolute;left:"+(width-11)+"px; top:"+2+"px\">" + html;

  var formDivId = "PopupFormDiv";
  if(document.getElementById)
  {
    var formDiv = document.getElementById(formDivId);

    formDiv.innerHTML = htmlInner;
    //formDiv.style.display = '';
    setElementProperty('display', 'block', formDivId);

    var fieldPos = new positionInfo(currentFieldId);

    var x = (fieldPos.getElementLeft() + fieldPos.getElementRight() - width)/2 + xOffset;
    var y = fieldPos.getElementBottom() + yOffset;
    //alert(x+ " "+ y);
    setElementProperty('left', x + "px", formDivId);
    setElementProperty('top', y + "px", formDivId);
    if(width!=0)
    {
      setElementProperty('width', width + "px", formDivId);
    }
    if(height!=0)
    {
      setElementProperty('height', height + "px", formDivId);
    }
  }
}

function blurrBackground()
{
  var fieldPos = new positionInfo(document.body);
  wrapperDiv = document.getElementById('PopupWrapperDiv');
  setElementProperty('display', 'block', wrapperDiv);
  setElementProperty('height', fieldPos.getElementHeight()+"px", wrapperDiv);
  setElementProperty('width', fieldPos.getElementWidth()+"px", wrapperDiv);

  setElementProperty('left', '0', wrapperDiv);
  setElementProperty('top', '0', wrapperDiv);
}

function hidePopup()
{
  var formDiv = document.getElementById('PopupFormDiv');
  setElementProperty('display', 'none', formDiv);
  setElementProperty('width', '', formDiv);
  setElementProperty('height', '', formDiv);


  wrapperDiv = document.getElementById('PopupWrapperDiv');
  setElementProperty('display', 'none', wrapperDiv);
  setElementProperty('width', '0px', wrapperDiv);
  setElementProperty('height', '0px', wrapperDiv);
}

function promptWin(currentFieldId, name)
{
  if(name==undefined)
  {
    name = '';
  }

  html = '\
  <table class=popupTable width=100%>\
    <tr><td colspan=2 align=center class="popupTd"><span style="font-size:15px; color:lightyellow; font-family:arial"><b>Please Enter Your Name to Change the Logo</b></span></td></tr>\
    <tr><td colspan=2 align=center class="popupTd"><input type=text id=newName value="'+name+'" style="width:190px"/></td></tr>\
    <tr><td colspan=2 align=center class="popupTd" style="padding-top:10px;padding-bottom:10px;" ><input type=submit style="width:130px; font-size:13px;" name=submit value=Done! onclick="processPromptNoTheme();return false;">&nbsp;&nbsp;&nbsp;&nbsp;<input style="width:135px; font-size:13px;" type=submit name=submit value="Change Theme Too" onclick="processPrompt();return false;"></td></tr>\
  </table>';

  createFormDiv(currentFieldId, html, 380, 93, -255, -46);
  document.getElementById('newName').focus();
  setCookieMins('askInvite','1',0.01);
}

function promptWinA(currentFieldId, name)
{
	  if(name==undefined)
	  {
	    name = '';
	  }

	  html = '\
	  <table class=popupTable width=100%>\
	    <tr><td colspan=2 align=center class="popupTd"><span style="font-size:15px; color:lightyellow; font-family:arial"><b>Please Enter Your Name to Change the Logo</b></span></td></tr>\
	    <tr><td colspan=2 align=center class="popupTd"><input type=text id=newName value="'+name+'" style="width:190px"/></td></tr>\
	    <tr><td colspan=2 align=center class="popupTd" style="padding-top:10px;padding-bottom:10px;" ><input type=submit style="width:130px; font-size:13px;" name=submit value=Done! onclick="processPromptNoTheme();return false;">&nbsp;&nbsp;&nbsp;&nbsp;<input style="width:135px; font-size:13px;" type=submit name=submit value="Change Theme Too" onclick="processPrompt();return false;"></td></tr>\
	  </table>';

	  createFormDiv(currentFieldId, html, 390, 93, -35, -46);
	  document.getElementById('newName').focus();
	  setCookieMins('askInvite','1',0.01);	
}

function promptAddLinkWin(currentFieldId)
{

  html = '\
  <iframe frameborder=0 id=favURLIframe allowTransparency=true style=\'width:100%;height:100%;border:0px solid red; background-color:transparent; text-align:center;\' src=\'/my/myfavorites\' align=center>\
    ';

  createFormDiv(currentFieldId, html, 580, 400, 255, 86);
}

function whatIsThisDiv(currentFieldId, txt, w, h, dw, dh)
{
  html = '\
  <table class=whatIsThisTable width=100%> \
    <tr class=whatIsThisTr><td class=whatIsThisTd>'+txt+'</td></tr>\
  </table>';

  createFormDiv(currentFieldId, html, w, h, dw, dh);
}

function processPrompt()
{
  //var name=promptWin("Please enter name for new Logo","'.$name.'");
  var name = document.getElementById('newName').value;
  //alert(name);
  var hostName = '';
  var loc = window.location +"";
  if(loc.search(/www/i) == -1)
  {
    hostName = "http://www.sleeksearch.com/skins/allthemes?&displayName="+encodeURIComponent(name);
  }

  if (name!=null && name!="")
  {
    window.location.href = hostName+"/skins/allthemes?displayName="+encodeURIComponent(name);
  }
}

function processPromptNoTheme()
{
  //var name=promptWin("Please enter name for new Logo","'.$name.'");
  var name = document.getElementById('newName').value;
  //alert(name);
  var hostName = '';
  var loc = window.location +"";
  if(loc.search(/www/i) == -1)
  {
    hostName = "http://www.sleeksearch.com";
  }

  if (name!=null && name!="")
  {
    window.location.href = hostName+"/?displayName="+encodeURIComponent(name);
  }
}

function setCookieMins(name,value,minutes)
{
  if (minutes)
  {
    var date = new Date();
    date.setTime(date.getTime()+(minutes*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else
  {
    var expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}

function cookieVal(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 promptAskInviteA()
{
  //return promptFollowOnFb();
  var theme = cookieVal('d_theme');
  if(theme == null)
  {
    theme='kitty1';
  }
  if(cookieVal('askInvite') != null)
  {
    return;
  }

  var nm = cookieVal('d_name');
  var sig = 'http://www.sleeksearch.com/?theme'+theme;
  if(nm != null)
  {
    //nm = nm.replace (/\s+/g, '');
    nm = nm.replace (/[^A-Za-z0-9]+/g, '');
    sig = 'http://'+nm+'.sleeksearch.com/?theme='+theme;
  }
  else
  {
    nm = 'www';
  }
  //var link = 'http://'+nm+'.sleeksearch.com/googleskins/'+theme;
  var embedCode = "<a href='"+sig+"'><img border=0 src='http://www.sleeksearch.com/theme/thumbnail?n="+nm+"&t="+theme+"' /></a>";
  var txtAr = "<input style='width:340px;' onclick=\"this.focus(); this.select();\" value=\""+embedCode+"\" >";

  html = '\
  <table class=popupTableWhite style=\'background:#111111\' width=100% height=100%>\
    <tr><td  align=center valign=middle>Your custom signature for your profile, blogs and emails is: <br ><span style="padding:5px;font-size:18px;color:lightyellow;border:0px solid #555555;">'+sig+'</span><span style="font-size:13px;v-align:middle;"><br>Embed Code with Logo Image:'+txtAr+'</span></td></tr>\
    <tr><td colspan=2 align=center class="popupTd" style="color:lightgreen; padding-top:20px;"><span style="font-family:arial,georgia;font-size:21px;color:orange;font-weight:bold">Click <span style="text-align:center; padding:3px 3px 8px 8px; *padding:8px 8px 8px 8px; background:yellow;border:1px solid #666666"><a name="fb_share" type="button" share_url="http://'+nm+'.sleeksearch.com/?from=fbShare_p&theme='+theme+'"></a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></span>&nbsp; to share with friends on Facebook </span> </td></tr>\
    <tr><td colspan=2 align=center class="popupTd" style="color:lightgreen; padding-top:30px;"><a href="#" style="font-family:arial,georgia;font-size:21px;color:orange;font-weight:bold" onclick="window.location=\'/guest/invites\'; return false;">&raquo; Gift this theme to your friends and win their hearts!</a> <br style="font-size:18px;"><br>(Theme will automatically have logo of your friends\' names!) </td></tr>\
    <tr><td colspan=2 align=center valign=top class="" style="color:green; padding-top:20px; font-size:15px"><a href="#" style="font-family:arial,georgia;font-size:15px;color:white" onclick="window.location=\'/guest/invites\'; return false;">&raquo; Gift Now!</a> &nbsp;&nbsp;<a href="#" style="font-family:arial,georgia;font-size:15px;color:white"  onclick="promptFollowOnFb();return false;">Dismiss</a></td></tr>\
  </table>';

  createFormDiv('header', html, 750, 280, 50, 148);
}


function promptAskInvite()
{
  //return promptFollowOnFb();
  var theme = cookieVal('d_theme');
  if(theme == null)
  {
    theme='kitty1';
  }
  if(cookieVal('askInvite') != null)
  {
    return;
  }

  var nm = cookieVal('d_name');
  var sig = 'http://www.sleeksearch.com/?theme'+theme;
  if(nm != null)
  {
    //nm = nm.replace (/\s+/g, '');
    nm = nm.replace (/[^A-Za-z0-9]+/g, '');
    sig = 'http://'+nm+'.sleeksearch.com/?theme='+theme;
  }
  else
  {
    nm = 'www';
  }
  //var link = 'http://'+nm+'.sleeksearch.com/googleskins/'+theme;
  var embedCode = "<a href='"+sig+"'><img border=0 src='http://www.sleeksearch.com/theme/thumbnail?n="+nm+"&t="+theme+"' /></a>";
  var txtAr = "<input style='width:340px;' onclick=\"this.focus(); this.select();\" value=\""+embedCode+"\" >";

  html = '\
  <table class=popupTableWhite style=\'background:#111111\' width=100% height=100%>\
    <tr><td valign=middle  align=center>Your custom signature for your profile, blogs and emails is: <br ><span style="padding:5px;font-size:18px;color:lightyellow;border:0px solid #555555;">'+sig+'</span><span style="font-size:13px;v-align:middle;"><br>Embed Code with Logo Image:'+txtAr+'</span></td></tr>\
    <tr><td colspan=2 align=center class="popupTd" style="color:lightgreen; padding-top:20px;"><span style="font-family:arial,georgia;font-size:21px;color:orange;font-weight:bold">Click <span style="text-align:center; padding:3px 3px 8px 8px; *padding:8px 8px 8px 8px; background:yellow;border:1px solid #666666"><a name="fb_share" type="button" share_url="http://'+nm+'.sleeksearch.com/?from=fbShare_p&theme='+theme+'"></a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></span>&nbsp; to share with friends on Facebook </span> </td></tr>\
    <tr><td colspan=2 align=center class="popupTd" style="color:lightgreen; padding-top:30px;"><a href="#" style="font-family:arial,georgia;font-size:21px;color:orange;font-weight:bold" onclick="window.location=\'/guest/invites\'; return false;">&raquo; Gift this theme to your friends and win their hearts!</a> <br style="font-size:18px;"><br>(Theme will automatically have logo of your friends\' names!) </td></tr>\
    <tr><td colspan=2 align=center valign=top class="" style="color:green; padding-top:20px; font-size:15px"><a href="#" style="font-family:arial,georgia;font-size:15px;color:white" onclick="window.location=\'/guest/invites\'; return false;">&raquo; Gift Now!</a> &nbsp;&nbsp;<a href="#" style="font-family:arial,georgia;font-size:15px;color:white"  onclick="promptFollowOnFb();return false;">Dismiss</a></td></tr>\
  </table>';

  createFormDiv('tab_menu_main', html, 750, 280, -30, -73);
}


function promptFollowOnFb()
{
  var nm = cookieVal('d_name');
  if(nm == null)
  {
    nm = 'Friend';
  }

  html = '\
  <table class=popupTableWhite style=\'background:#111111\' width=100% height=100%>\
    <tr><td><span style="padding:5px;font-size:18px;color:lightyellow;border:0px solid #555555;">'+nm+' click the <img border=0 src="/images/fb-like.png"> icon below to follow us on Facebook!</span><br></td></tr>\
    <tr><td align=center class="popupTd">\
    <iframe src="http://www.facebook.com/plugins/likebox.php?id=103929272995752&amp;width=600&amp;connections=20&amp;stream=false&amp;header=false&amp;height=255" scrolling="no" frameborder="0" style="border:none; background:white;overflow:hidden; width:600px; height:255px;" allowTransparency="false"></iframe>\
    </td></tr>\
    <tr><td colspan=2 align=center valign=top class="" style="color:green; padding-top:20px; font-size:15px"><a href="#" style="font-weight:bold;font-family:arial,georgia;font-size:15px;color:white" onclick="window.open(\'http://www.facebook.com/pages/sleeksearch/103929272995752\'); return false;">Go to Facebook Page</a> &nbsp;&nbsp;<a href="#" style="font-weight:bold;font-family:arial,georgia;font-size:15px;color:white"  onclick="hidePopup();setCookieMins(\'askInvite\',\'1\',3);setHomepage(0,0);return false;">Dismiss</a></td></tr>\
  </table>';

  createFormDiv('tab_menu_main', html, 750, 380, -30, -73);
}


document.write("<div id='PopupWrapperDiv' style='display:none; border:0px solid red; background:#CCFFFF; opacity: 0.25; filter:alpha(opacity=25); position:absolute'></div>");
document.write("<div id='PopupFormDiv' style='display:none; padding:3px 3px 3px 3px; border:1px solid #bbbbbb; color:white; background: url(/images/theme/transbg-gray.png) repeat; position:absolute;'></div>");
