var nTotalCharacters = 1000;

function confirm_del() {
  var reply = confirm("This will permanantly delete this record! You can't restore it in future.");

  if (reply) {
     return true;
  } else {
     return false;
  }
}


function vote_confirm(frm) {
  var reply = confirm("Do you want to earn a reward credit for completing poll?");

  if (reply) {
     frm.get_registration.value='yes';
     return true;
  } else {
     frm.get_registration.value='no';
     return true;
  }
}


function popUpImg(url, pageWidth, pageHeight) {
    var args = "width=" + (pageWidth + 20) + ",height=" + (pageHeight + 10) + "";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);

    _w = window.open('',name,args);
    _w.document.open();
    _w.document.write("<html>\n<head><title>Viewing " + url + "</title>\n");
    _w.document.write("<meta http-equiv='imagetoolbar' content='no'>\n");
    _w.document.write("<link href='screen.css' type='text/css' rel='stylesheet'  media='screen' />\n");
    _w.document.write("<script language='javascript'><!--\n");
    _w.document.write("var i=0;\n");
    _w.document.write("function resize() {\n");
    _w.document.write("if (navigator.appName == 'Netscape') i=40;\n");
    _w.document.write("if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+100-i);\n");
    _w.document.write("self.focus();\n");
    _w.document.write("}\n");
    _w.document.write("//--></script></head>\n");
    _w.document.write("<body onload='resize();'>\n");
    _w.document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' style='height: 100%'>\n");
    _w.document.write("<tr><td><a href='javascript:window.close()' class='popup'>Close window</a></td></tr>\n");
    _w.document.write("<tr>\n<td align='center' valign='middle'>\n");
    _w.document.write("<a href='javascript:window.close()'><img src='" + url + "' alt='Click to close' border='0' /></a>\n");
    _w.document.write("</td></tr></table>\n");
    _w.document.write("</body>\n</html>");
    _w.document.close();
}

function popUpTxt(content, pageWidth, pageHeight) {
    var args = "width=" + (pageWidth + 20) + ",height=" + (pageHeight + 10) + "";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);

    _w = window.open('',name,args);
    _w.document.open();
    _w.document.write("<html>\n<head><title>Viewing " + url + "</title>\n");
    _w.document.write("<meta http-equiv='imagetoolbar' content='no'>\n");
    _w.document.write("<link href='screen.css' type='text/css' rel='stylesheet'  media='screen' />\n");
    _w.document.write("<script language='javascript'><!--\n");
    _w.document.write("var i=0;\n");
    _w.document.write("function resize() {\n");
    _w.document.write("if (navigator.appName == 'Netscape') i=40;\n");
    _w.document.write("if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+100-i);\n");
    _w.document.write("self.focus();\n");
    _w.document.write("}\n");
    _w.document.write("//--></script></head>\n");
    _w.document.write("<body onload='resize();'>\n");
    _w.document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' style='height: 100%'>\n");
    _w.document.write("<tr><td><a href='javascript:window.close()' class='popup'>Close window</a></td></tr>\n");
    _w.document.write("<tr>\n<td align='center' valign='middle'>\n");
    //_w.document.write("" + content + "");
    _w.document.write("</td></tr></table>\n");
    _w.document.write("</body>\n</html>");
    _w.document.close();
}


function displayHTML(form) {
var inf = form.get_ad_message.value;        alert(document.get_ad_image.type.value);
/*
src = '<img src='+form.get_ad_image.value+' border=1 width=200 align=left>';
inf = src + inf;
win = window.open(", ", 'popup', 'toolbar = no, status = no');
win.document.write("" + inf + "");
*/
}


opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
ie = (document.all && !opera)? true : false;
dom = (document.getElementById && !ie && !opera)? true : false;

var expiration = new Date();
expiration.setTime(expiration.getTime() + 3600*3600*3600);


function doPreview(param1, param2) {

  if (dom) {
    var src = document.getElementById(param1).value;
  } else if (ie) {
    var src = document.all[param1].value;
  }

  if (src.charAt(1)==":") src = "file:/" + src;

  if (dom) {
    document.getElementById(param2).src=src;
  } else if (ie) {
    document.all[param2].src = src;
  }

}


function doPreview1(param1, param2) {

  if (dom) {
    document.getElementById(param2).src=param1;
  } else if (ie) {
    document.all[param2].src = param1;
  }

}


function showtranscript(elemId,displayValue) {
  if (dom) {

      if (displayValue) {
         if (document.getElementById(elemId)) {
           document.getElementById(elemId).style.display = displayValue;
         }
         return 0;
      }

      if (document.getElementById(elemId).style.display == "none") {
         document.getElementById(elemId).style.display = "block";
      } else if (document.getElementById(elemId).style.display == "block") {
         document.getElementById(elemId).style.display = "none";
      }

  } else if (ie) {

    if (displayValue) {
       if (document.all[elemId]) {
         document.all[elemId].style.display =  displayValue;
       }
       return 0;
    }

    if (document.all[elemId].style.display == "block") {
       document.all[elemId].style.display = "none";
    } else if (document.all[elemId].style.display == "none") {
      document.all[elemId].style.display = "block";
    }

  }
}

function display(cookie_name, id) {
    var template_category_cookie;

    template_category_cookie = GetCookie(cookie_name);

    if (template_category_cookie) {
       SetCookie(cookie_name, "1", expiration, "", "","")
       showtranscript(id, 'block');
    } else {
       SetCookie(cookie_name, "", expiration, "", "","")
       showtranscript(id, 'none');
    }

    return true;
}


function onCookieChange(cookie_name, id) {

  if (dom) {
      if (document.getElementById(id).style.display == "none") {
         SetCookie(cookie_name, "", expiration, "", "","")
      } else if (document.getElementById(id).style.display == "block") {
         SetCookie(cookie_name, "1", expiration, "", "","")
      }

  } else if (ie) {

    if (document.all[id].style.display == "block") {
       SetCookie(cookie_name, "1", expiration, "", "","")
    } else if (document.all[id].style.display == "none") {
       SetCookie(cookie_name, "", expiration, "", "","")
    }

  }
}


function SetCookie(name, value, expires, path, domain, secure) {

   var mycookie = name + "=" + escape(value);
   var myexpires = new Date();
   myexpires.setTime(myexpires.getTime() + 5000);
   mycookie = mycookie + "; myexpires=" + myexpires.toGMTString();
   document.cookie = mycookie;
}


function GetCookie(name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while (i < clen) {
     var j = i + alen;
     if (document.cookie.substring(i, j) == arg)  return getCookieVal (j);
     i = document.cookie.indexOf(" ", i) + 1;
     if (i == 0) break;
   }

   return null;
}


function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}


function ShowMemberParams(frm) {
   if (frm.elements['get_ref_status'].value == '2') { 
      showtranscript('member_params', 'block');
   } else {
      showtranscript('member_params', 'none');
   }
}

function fCountCharacters(description,sId, ch) {
        if(ch) ch1 = ch; else ch1 = nTotalCharacters;

  var sValue = description.value
  var nRemaining = ch1 - sValue.length;
  if(nRemaining < 0){
    document.getElementById(sId).value = sValue.slice(0,ch1);
  } else {
    document.getElementById(sId + '-characters-left').innerHTML = nRemaining + ' characters';
  }
}

function fCountCommentsCharacters(description,sId) {

  var sValue = description.value
  var nRemaining = sValue.length;
  document.getElementById(sId + '-characters-left').innerHTML = nRemaining + ' Total Characters Entered';
}
