
function InitDynamic() {
  document.getElementById('loginlink').href='#';
}

function InitDynamic_Submit() {
  document.getElementById('cnt_title').style.display='inline';
  document.getElementById('cnt_about').style.display='inline';
  document.getElementById('prevbtn').style.display='inline';
}

function ShowLogin() {
  document.getElementById('login1').style.display='block';
  document.getElementById('login2').style.display='block';
}

function HideLogin() {
  document.getElementById('login1').style.display='none';
  document.getElementById('login2').style.display='none';
}

function ShowVid(ID,btn,alnk) {
  if (document.getElementById(ID).style.display == 'block') {
     document.getElementById(ID).style.display='none';
     document.getElementById(btn).src='img/ico_play.png';
  } else {
     document.getElementById(ID).style.display='block';
     document.getElementById(btn).src='img/ico_stop.png';
  }
}

function ShowBBHelp() {
  document.getElementById('bbhelp').style.display='block';
}

function textCounter(inpID,cntID,maxlimit) {
  var tval = document.getElementById(inpID).value;
  var tlen = tval.length;
  if (tlen > maxlimit) {
     document.getElementById(cntID).className='error';
     document.getElementById(cntID).innerHTML = (maxlimit - tlen).toString();
  } else {
     document.getElementById(cntID).className='pass';
     document.getElementById(cntID).innerHTML = '+' + (maxlimit - tlen).toString();
  }
}

function FixURL(inpID) {
  var tval = document.getElementById(inpID).value;
  if (tval == 'http://') {
     document.getElementById(inpID).value = '';
  }
  if (tval != '') {
     if (tval.substr(0,7) != 'http://') {
        document.getElementById(inpID).value = 'http://' + tval;
     }
  }
}

function FixTags(inpID) {
  var tval = document.getElementById(inpID).value;
  tval = tval.replace(/ /,',');
  tval = tval.replace(/,,/,',');
  document.getElementById(inpID).value = tval;
}

function CheckCats() {
  var tval1 = document.getElementById('inp_cat1').value;
  var tval2 = document.getElementById('inp_cat2').value;
  if (tval1 == tval2) {
    if (tval1 > 0) {
      tval2 = 0;
      document.getElementById('inp_cat2').value = 0;
    }
  }
  var w = document.getElementById('inp_cat1').selectedIndex;
  var sel_txt = document.getElementById('inp_cat1').options[w].text;
  var wx = document.getElementById('inp_cat2').selectedIndex;
  var sel_txtx = document.getElementById('inp_cat2').options[wx].text;
  if (sel_txt == 'NSFW') {
     document.getElementById('inp_sfw').checked = false;
  }
  if (sel_txtx == 'NSFW') {
     document.getElementById('inp_sfw').checked = false;
  }
}

//parse a URL to form an object of properties
function parseURL(url)
{
    //save the unmodified url to href property
    //so that the object we get back contains
    //all the same properties as the built-in location object
    var loc = { 'href' : url };

    //split the URL by single-slashes to get the component parts
    var parts = url.replace('//', '/').split('/');

    //store the protocol and host
    loc.protocol = parts[0];
    loc.host = parts[1];

    //extract any port number from the host
    //from which we derive the port and hostname
    parts[1] = parts[1].split(':');
    loc.hostname = parts[1][0];
    loc.port = parts[1].length > 1 ? parts[1][1] : '';

    //splice and join the remainder to get the pathname
    parts.splice(0, 2);
    loc.pathname = '/' + parts.join('/');

    //extract any hash and remove from the pathname
    loc.pathname = loc.pathname.split('#');
    loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //extract any search query and remove from the pathname
    loc.pathname = loc.pathname.split('?');
    loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //return the final object
    return loc;
}

function ShowPreview() {
  var title = document.getElementById('inp_title').value;
  var about = document.getElementById('inp_about').value;
  var url = document.getElementById('inp_url').value;
  if (url == 'http://') { url = ''; }
  if (url == '') { url = '#'; }
  about = about.substr(0,440) + '..';
  var urlhost
  if (url == '#') {
     urlhost = 'www.pijoo.com';
  } else {
     urlhost = parseURL(url).host;
  }
  document.getElementById('prev_title').innerHTML = title;
  document.getElementById('prev_title').href = url;
  document.getElementById('prev_about').innerHTML = about;
  document.getElementById('prev_url').innerHTML = urlhost;
  document.getElementById('prev').style.display='block';
}

function ShowInvitePreview() {
  var usertxt = document.getElementById('inp_about').value;
  var foottxt = document.getElementById('inp_hid').value;
  document.getElementById('prev').innerHTML = usertxt+foottxt;
  document.getElementById('prev').style.display='block';
  document.getElementById('prevbtn').value = 'Update Preview';
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ReplyCom(usern) {
  var instxt = '';
  instxt = instxt + '@' + usern + ', ';
  document.getElementById('inp_com').value = instxt;
}

function QuoteCom(usern,quot) {
  var qtxt = document.getElementById(quot).innerHTML;
  var instxt = '';
  instxt = instxt + '[quote]';
  instxt = instxt + trim(qtxt,' ');
  instxt = instxt + '[/quote]\n\r';
  instxt = instxt + '@' + usern + ', ';
  document.getElementById('inp_com').value = instxt;
}

// ajaxVote(25,1)
function ajaxVote(PID,UPDN)
{
if (PID == -1) { return 0; }
//update links
  document.getElementById('vbtn_up'+PID).href = "#";
  document.getElementById('vbtn_up'+PID).onclick = "return false;";
  document.getElementById('vbtn_dn'+PID).href = "#";
  document.getElementById('vbtn_dn'+PID).onclick = "return false;";
//update buttons
  if (UPDN == 1) {
     document.getElementById('votenum'+PID).className = "vote_top_grn";
     var vint = 0;
     var vscore = document.getElementById('votenum'+PID).innerHTML;
     vint = parseInt(vscore);
     vint = vint + 1;
     document.getElementById('votenum'+PID).innerHTML = vint.toString();
     document.getElementById('vimg_up'+PID).src = 'img/score_up1.png';
  } else {
     document.getElementById('votenum'+PID).className = "vote_top_red";
     var vint = 0;
     var vscore = document.getElementById('votenum'+PID).innerHTML;
     vint = parseInt(vscore);
     vint = vint - 1;
     document.getElementById('votenum'+PID).innerHTML = vint.toString();
     document.getElementById('vimg_dn'+PID).src = 'img/score_dn1.png';
  }
//
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function(){}

var URL = "ajaxvote.php?PID=" + PID + "&UPDN=" + UPDN;
xmlhttp.open("GET",URL,true);
xmlhttp.send(null);
}

// ajaxCVote(25,1)
function ajaxCVote(CID,UPDN)
{
if (CID == -1) { return 0; }
//update links
  document.getElementById('cbtn_up'+CID).href = "#";
  document.getElementById('cbtn_up'+CID).onclick = "return false;";
  document.getElementById('cbtn_dn'+CID).href = "#";
  document.getElementById('cbtn_dn'+CID).onclick = "return false;";
//update buttons
  if (UPDN == 1) {
     var vint = 0;
     var vscore = document.getElementById('cscore'+CID).innerHTML;
     vint = parseInt(vscore);
     vint = vint + 1;
     document.getElementById('cscore'+CID).innerHTML = vint.toString();
     document.getElementById('cimg_up'+CID).src = 'img/com_up1.png';
  } else {
     var vint = 0;
     var vscore = document.getElementById('cscore'+CID).innerHTML;
     vint = parseInt(vscore);
     vint = vint - 1;
     document.getElementById('cscore'+CID).innerHTML = vint.toString();
     document.getElementById('cimg_dn'+CID).src = 'img/com_dn1.png';
  }
//
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function(){}

var URL = "ajaxcvote.php?CID=" + CID + "&UPDN=" + UPDN;
xmlhttp.open("GET",URL,true);
xmlhttp.send(null);
}

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 closeAlert(AID) {
  document.getElementById('alert').style.display='none';
  createCookie("PIJOO_AHF100a" + AID,"011",90);
}