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();' 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);


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

function callUser(currentFieldId, user, lets101No, callId)
{
  html = '\
  <table class=popupTable width=100%> \
    <tr><td colspan=2 class="popupTd bottomSpc">\
      To Call <b>' + user + '</b></td></tr>\
      <tr><td class="popupTd instrMsg">1)</td><td class="popupTd instrMsg">Dial <b>'+ lets101No + '</b>, from your registered phone</td></tr>\
      <tr><td class="popupTd instrMsg">2)</td><td class="popupTd instrMsg" >Press <b>1</b> on the Main menu</td></tr>\
      <tr><td class="popupTd instrMsg">3)</td><td class="popupTd instrMsg" >Enter <b>' + callId + '</b>, followed by the <b>#</b> key </td></tr>\
      <tr><td colspan=2 class="popupTd topSpc">  You will be instantly connected.</td></tr>\
      <tr><td colspan=2 class="popupTd topSpc comment instrMsg">(At the moment this feature is available only in US, UK and Canada)</td></tr>\
  </table>';

  createFormDiv(currentFieldId, html, 395, 0, 0, 2);
}

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 showFpPromo(currentFieldId, w, h, dw, dh)
{
  html = "\
              <table class=promoInnerTable  width=100% align=center style='border-collapse: collapse;' border=0> \
                <tr class=promoHeadTr><td align=center>On Purchase Of</td><td align=center>You Get Free</td><td align=center width=46%>Effective Rates Become</td></tr>\
                <tr><td align=center>$10</td><td align=center>$5</td>\
                  <td rowspan=4 align=left style='padding-left:30px;'>\
                  India <span class=strikedOut>4.9&cent;</span><b style='color:red'> 3.3&cent;</b>,\
                  <br>Viet Nam <span class=strikedOut>4.6&cent;</span><b style='color:red'> 3.1&cent;</b>,\
                  <br>UK <span class=strikedOut>1.6&cent;</span><b style='color:red'> 1.1&cent;</b>,\
                  <br>China <span class=strikedOut>1.9&cent;</span><b style='color:red'> 1.3&cent;</b>,\
                  <br>Philippines <span class=strikedOut>14.3&cent;</span><b style='color:red'> 9.5&cent;</b>\
                  </td></tr>\
                <tr><td align=center>$20</td><td align=center>$10</td></tr>\
                <tr><td align=center>$50</td><td align=center>$25</td></tr>\
                <tr><td align=center>$100</td><td align=center>$50</td></tr>\
                <tr><td colspan=3>&nbsp;</td></tr>\
                <tr><td colspan=3 align=center>\
                  <input class=buyButton type=button value='Buy Now! and Also Get 10 Free Minutes!' onclick=\"window.location='/guest/frontpage?joinForm=1'\"/>\
                </td></tr>\
              </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}



function showDirectDial(currentFieldId, w, h, dw, dh)
{
  html = "\
             <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                <span class=h1>Direct Dial is the most appreciated and very convenient feature to make calls.<br>\
                (Please see the example below)</span>\
                <ol>\
                <li style='padding-bottom:5px;'> Login and enter the international numbers, where you frequently call. (One time process)\
                <li style='padding-bottom:5px;'> You will get permanent local phone numbers for each of the international numbers.\
                <li style='padding-bottom:5px;'> Store these local numbers in your phone book and call them directly, to automatically connect to the corresponding international numbers.\
                </ol>\
                <p class=hilite style='padding:10px'>For example :\
                <br>Your Mom's cell in India is +91-9866554422, and you get 408-220-9315 as a permanent local number for it.\
                <br>Now to call Mom, you just have to dial 408-220-9315 from your registered phone and your Mom's cell will ring.\
                </p>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}


function showDirectDialH(currentFieldId, w, h, dw, dh)
{
  html = "\
             <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                <span class=h1>Direct Dial is the most popular and very convenient feature to make calls.<br>\</span>\
                <ol>\
                <li style='padding-bottom:5px;'> Enter the international number, Nick Name, and the Email-ID of the person you want to call. (One time process)\
                <li style='padding-bottom:5px;'> You will get the local number for each international number. Store it in your cell's phone book. \
                <li style='padding-bottom:5px;'> Now just call this local number and you will be automatically connected to international number.\
                <li style='padding-bottom:5px;'> To send only the Voice Message call the local number and press * key before the person picks the phone and record your message, it will be emailed to the person's Email-Id.\
                </ol>\
                <p class=hilite style='padding:10px'>For example :\
                <br>Your Mom's cell in India is +91-9866554422, and you get 408-220-9315 as a permanent local number for it.\
                <br>Now to call Mom, you just have to dial 408-220-9315 from your registered phone and your Mom's cell will ring.\
                </p>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}



function showSpeedDial(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                <span class=h1>Instead of punching long international number you just have to enter 1 or 2 digit number.</span>\
                <ol>\
                  <li style='padding-bottom:5px;'> Login and enter the international numbers where you frequently call. (One time process)\
                  <li style='padding-bottom:5px;'> You will get a single or two digit speed dial number corresponding to each international number.\
                  <li style='padding-bottom:5px;'> Now to make call, dial the Access number, on prompt, enter the Speed Dial number followed by the '#' key. No need to dial long international number\
                  <br> You will immediately be connected to corresponding international number\
                </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}



function showSpeedDialH(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                <span class=h1>Instead of punching long international number you just have to enter 1 or 2 digit number.</span>\
                <ol>\
                  <li style='padding-bottom:5px;'> Click on the 'Add New Speed Dial Number' Button.\
                  <li style='padding-bottom:5px;'> Enter the international number, Nick Name, and the Email-ID. And Click Save. (One time process)\
                  <li style='padding-bottom:5px;'> You will get a single or two digit speed dial number corresponding to each international number.\
                  <li style='padding-bottom:5px;'> Now to make call, dial the Access number, on prompt, enter the Speed Dial number followed by the '#' key. \
                  <li style='padding-bottom:5px;'> To send only the Voice Message call the access number, enter Speed Dial Number and press * key before the user picks the phone and record your message, it will be emailed to the person's Email-Id.\
                </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}


function showSpeedDialH_Cb(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                <span class=h1>Instead of punching long international number you just have to enter 1 or 2 digit number.</span>\
                <ol>\
                  <li style='padding-bottom:5px;'> Click on the 'Add New Speed Dial Number' Button.\
                  <li style='padding-bottom:5px;'> Enter the international number, Nick Name, and the Email-ID. And Click Save. (One time process)\
                  <li style='padding-bottom:5px;'> You will get a single or two digit speed dial number corresponding to each international number.\
                  <li style='padding-bottom:5px;'> Now to make call, dial the Access number, you will receive a call back, on prompt, enter the Speed Dial number followed by the '#' key. \
                  <li style='padding-bottom:5px;'> To send only the Voice Message call the access number, enter Speed Dial Number and press * key before the user picks the phone and record your message, it will be emailed to the person's Email-Id.\
                </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}



function showRegularDial(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                 <span class=h1>Regular Dial is the usual way to make call</span>\
                 <ol>\
                   <li style='padding-bottom:5px;'> Dial the access number from any of your registered phones.\
                   <li style='padding-bottom:5px;'> On prompt, enter the destination number you want to call including the country code followed by the '#' key.\
                   <br> You will immediately be connected to the international number.\
                 </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}

function showRegularDialH(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                 <span class=h1>To call Any Number</span>\
                 <ol>\
                   <li style='padding-bottom:5px;'> Dial the access number from any of your registered phones.\
                   <li style='padding-bottom:5px;'> On prompt, enter the destination number you want to call including the country code followed by the '#' key.\
                   <br> For e.g. to call India at 9822233344, you will enter 919822233344 and # key.\
                 </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}

function showRegularDialH_Cb(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                 <span class=h1>To call Any Number</span>\
                 <ol>\
                   <li style='padding-bottom:5px;'> Dial the access number from any of your registered phones.\
                   <li style='padding-bottom:5px;'> Your call will immediately drop. <b>Do not call again</b>, just wait for few seconds.\
                   <li style='padding-bottom:5px;'> You will receive a call back from our automated system.\
                   <li style='padding-bottom:5px;'> On prompt, enter the destination number you want to call including the country code followed by the '#' key.\
                   <br> For e.g. to call India at 9822233344, you will enter 919822233344 and # key.\
                 </ol>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}


function showRegPhonesH(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left>\
              <tr><td align=left style='font-family:georgia'>\
                 <span class=h1>These are your phone numbers, from where you will call our system.\
                 <br/>You can add any number of your phones here. For e.g. your cell phone, your home phone, your office phone.</span>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}


function showRefMoreDetails(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table align=left style='background:lightyellow;'>\
              <tr><td align=left style='font-family:verdana; font-size:13px;'>\
                 &nbsp;&nbsp;&nbsp;<strong style='font-size:18px;color:navy;'>Grow Your Network and Earn Referral Bonuses for Life!</strong>\
                 <p>\
                 After Sign Up, you can send free gift minutes to your friends. We pay for these gift minutes!\
                 <\p><p>We are very sure your friends will love DialSimple services and would become our regular \
                 customers like you would now after using our services :)\
                 </p><p>Whenever your friends make purchase on our site, we would\
                 give you 5% of the purchase amount as bonus. This is for every time they purchase!\
                 </p><p>Not only this, if your friends refer their friends and earn bonus amounts,\
                 we will give you 5% of the bonus amount they earn! and this keeps going on.\
                 So it's unlimited referral amount flowing in your account for life!\
                 </p><p>Imagine over the time, even if 10 to 15 of your friends join and use DialSimple,\
                 you may not have to buy credit anymore, as you would be making more than required\
                 just from the referral bonuses!\
                </p>\
              </td></tr>\
              <tr><td align=right>\
                <a href='#' onclick=\"hidePopup(); return false;\">Close</a>\
              </td></tr>\
            </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}

function showCountrySpecificDiscountDetails_bak(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table border=0 align=center >\
              <tr><td colspan=3 align=left style='font-family:verdana; font-size:13px;'>\
                 &nbsp;&nbsp;&nbsp;<strong style='font-size:16px;color:navy;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call India for just 2.5&cent;/min for next 1 month!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>\
                </td></tr>\
              <tr><td colspan=3 align=left style='font-family:verdana; font-size:13px;'>\
                 &nbsp;&nbsp;&nbsp;<strong style='font-size:16px;color:navy;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call Vietnam for just 3.1&cent;/min for next 2 weeks!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>\
                </td></tr>\
              <tr><td colspan=3 align=left style='font-family:verdana; font-size:13px;'>\
                 &nbsp;&nbsp;&nbsp;<strong style='font-size:16px;color:navy;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call Pakistan for just 10&cent;/min for next 1 week!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>\
                </td></tr>\
                <tr><td colspan=3 align=center>\
                  <input class=buyButton type=button value='Buy Now! and Also Get Free Minutes!' onclick=\"window.location='/guest/frontpage?joinForm=1'\"/>\
                </td></tr>\
              </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);

}


function showCountrySpecificDiscountDetails(currentFieldId, w, h, dw, dh)
{
  html = "\
            <table border=0 align=center >\
              <tr><td colspan=3 align=left style='font-family:verdana; font-size:13px;'>\
                 When ever you recharge you get the discounted rates for 31 days from that time.\
                 After that <a href='/guest/callrates?countryCode=IN'>normal rates apply (2.49&cent;)</a>. But if you recharge again, the discounted rates apply again for the next 31 days and so on.\
                 <b>Your balance amount never expires!</b>\
                 <br><br>For e.g. you bought $30 on 10th July your rates till 10th August will be 1.99&cent; and after that normal rates will apply. Say your balance on 17th August was $10 and you recharged again for $30 then 1.99&cent; will apply on the entire $40 till 17th September and so on.\
                </td></tr>\
                <tr><td colspan=3 align=center>\
                  <input class=buyButton type=button value='Buy Now! and Also Earn Free Credit!' onclick=\"window.location='/guest/frontpage?joinForm=1'\"/>\
                </td></tr>\
              </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);

}


function showDiscountDetails(pct, currentFieldId, w, h, dw, dh)
{
  rowspan = 4;
  if(pct<50) rowspan += 1;
  if(pct<40) rowspan += 1;
  if(pct<30) rowspan += 1;

  html = "\
            <table align=left >\
              <tr><td colspan=3 align=left style='font-family:verdana; font-size:13px;'>\
                 &nbsp;&nbsp;&nbsp;<strong style='font-size:16px;color:navy;'>Get "+pct+"% FREE Credit (upto $50) On Your First Purchase!</strong>\
                </td></tr>\
                <tr class=promoHeadTr><td align=center>On Purchase Of</td><td align=center>You Get Free</td><td align=center width=46%>Effective Rates Become</td></tr>\
                <tr><td align=center>$10</td><td align=center>$"+Math.round(10*pct/100)+"</td>\
                  <td rowspan="+rowspan+" valign=middle align=left style='vertical-align: middle; padding:auto; padding-left:30px;'>\
                  India <span class=strikedOut>4.9&cent;</span><b style='color:red'> "+Math.round(4.9/(pct/100+1)*10)/10+"&cent;</b>,\
                  <br>Viet Nam <span class=strikedOut>4.6&cent;</span><b style='color:red'> "+Math.round(4.6/(pct/100+1)*10)/10+"&cent;</b>,\
                  <br>Australia <span class=strikedOut>2.0&cent;</span><b style='color:red'> "+Math.round(2.0/(pct/100+1)*10)/10+"&cent;</b>,\
                  <br>UK <span class=strikedOut>1.6&cent;</span><b style='color:red'> "+Math.round(1.6/(pct/100+1)*10)/10+"&cent;</b>,\
                  <br>Philippines <span class=strikedOut>14.3&cent;</span><b style='color:red'> "+Math.round(14.3/(pct/100+1)*10)/10+"&cent;</b>\
                  </td></tr>\
                <tr><td align=center>$20</td><td align=center>$"+Math.round(20*pct/100)+"</td></tr>\
                <tr><td align=center>$50</td><td align=center>$"+Math.round(50*pct/100)+"</td></tr>\
                <tr><td align=center>$100</td><td align=center>$"+Math.round(100*pct/100)+"</td></tr>";
if(pct<50)
{
   amt = Math.round(150*pct/100);
   if(amt>50) amt = 50;
   html = html + "<tr><td align=center>$150</td><td align=center>$"+amt+"</td></tr>";
}
if(pct<40)
{
   amt = Math.round(200*pct/100);
   if(amt>50) amt = 50;
   html = html + "<tr><td align=center>$200</td><td align=center>$"+amt+"</td></tr>";
}
if(pct<30)
{
   amt = Math.round(250*pct/100);
   if(amt>50) amt = 50;
   html = html + "<tr><td align=center>$250</td><td align=center>$"+amt+"</td></tr>";
}
    html = html + "<tr><td colspan=3>&nbsp;</td></tr>\
                <tr><td colspan=3 align=center>\
                  <input class=buyButton type=button value='Buy Now! and Also Get Free Minutes!' onclick=\"window.location='/guest/frontpage?joinForm=1'\"/>\
                </td></tr>\
              </table>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
}


function showSpeedDialPop(currentFieldId, w, h, dw, dh)
{
  html = "<div id=speedDialFormDiv name=speedDialFormDiv></div>";
  createFormDiv(currentFieldId, html, w, h, dw, dh);
  displaySpeedDialForm();
}


document.write("<div id='PopupWrapperDiv' style='display:none; border:0px solid red; background:#E8EEFA; opacity: 0.25; filter:alpha(opacity=25); position:absolute'></div>");
document.write("<div id='PopupFormDiv' style='display:none; padding:3px 3px 3px 3px; border:2px solid lightblue; background:#E8EEFA; position:absolute'></div>");
