var win = null;
//popup window ;)
function PopUpWindow(mypage, myname, w, h, scroll, resizeable){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+resizeable+',';
  win = window.open(mypage, myname, settings);
  if (win.opener == null) {  // for Nav 2.0x
      win.opener = self  // this creates and sets a new property
   }
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

//Clear Forms
function clearForm(formIdent)  { 
  var form, elements, i, elm; 
  form = document.getElementById ? document.getElementById(formIdent) : document.forms[formIdent]; 
  
  if (document.getElementsByTagName) {
  	elements = form.getElementsByTagName('input');
  	for( i=0, elm; elm=elements.item(i++); ) {
  		if (elm.type == "text") {
  			elm.value = '';
  		}
  		else if (elm.type == "radio") {
        elm.checked = false;
      }
  	}
  	elements = form.getElementsByTagName('textarea');
  	for( i=0, elm; elm=elements.item(i++); ) {
  		elm.value = '';
  	}
  }
}

//XMLHTTP object ;)
function getHTTPObject() {
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
     
  }
  return xmlhttp;
}

//login Form :)
function changeLogin(change) {
  var text   = document.getElementById("loginText");
  var reg    = document.getElementById("regLink");
  var pass   = document.getElementById("forgotPass");
  var user   = document.getElementById("userBox");
  var artist = document.getElementById("artistBox");
  
  if (change == 'user') {
    var action = '/user/'+encodeURIComponent("Вход-потребител");
    var ntext  = 'потребители';
    var nreg   = '/user/'+encodeURIComponent("Регистрация");
    var npass  = '/user/'+encodeURIComponent("Забравена_парола");
    var nimgU  = "";
    var nimgA  = "";
  }
  else {
    var action = '/user/'+encodeURIComponent("Вход-артист");
    var ntext  = 'артисти';
    var nreg   = '/user/'+encodeURIComponent("Музикален-изпълнител-регистрация");
    var npass  = '/user/'+encodeURIComponent("Забравена_парола_артист");
    var nimgU  = "url('/images/login_11.gif')";
    var nimgA  = "url('/images/login_21.gif')";
  }
  
  document.login.action = action;
  text.innerHTML = ntext;
  reg.setAttribute('href', nreg);
  pass.setAttribute('href', npass);
  user.style.backgroundImage   = nimgU;
  artist.style.backgroundImage = nimgA;
}

//hide mp3 list
function hideALbMP3(id) {
  // box
  var box  = document.getElementById("box_"+id);
  box.style.backgroundColor = "";

  //link
  var more = document.getElementById("more_"+id);
  more.innerHTML = '<a href="javascript: showAlbMP3('+id+')"><img src="/images/album_expand_butt.gif" alt="show mp3" border="0" /></a>';

  //content -- clear
  var list = document.getElementById("mp3_"+id);
  list.style.visibility = "hidden";
  list.style.fontSize   = "0px";
  list.innerHTML        = "";
}

//SPAM FOLK Filter
function showfolks(bool) {
//  var d = new Date();
//  d.setDate(d.getDate() + 14);
//  var exp = d.toUTCString();
//	var host = window.location.hostname.split('.').reverse();
//	var d = host[1] + '.' + host[0];
  
  if (bool)
	  $.cookie("showfolk", 1, {path : '/', domain: '.' + window.location.hostname});
  else
	  $.cookie("showfolk", 0, {path : '/', domain: '.' + window.location.hostname});
  
    window.location.href = window.location.href;
}

//Redirect Function
function toUrl(url, time) {
  setTimeout("window.location = '"+url+"'", time);
}

//pay for mp3
function payMP3(id, type) {
  var url;
  list = document.getElementById("payMSG");

  if (type == 'mp3')
    url = '/payformp3.php';
  else
    url = '/payforalbum.php';

  //start AJAX code
  http = getHTTPObject();
  http.open("GET", url + "?id=" + escape(id), true);
  http.onreadystatechange = function() {
    if (http.readyState == 4) {
      if (http.status == 200) {
        var xml     = http.responseXML;
        var results = xml.getElementsByTagName("x")[0].firstChild.nodeValue;
        list.innerHTML = results;
      }
      else
        list.innerHTML = "Сървърът е претоварен моля опитайте по-късно пак!";
    }
    else
      list.innerHTML = '<h4><img src="/images/ajax-loader.gif" alt="loading" /><br />Моля изчакайте системата да отчете разплащането Ви.</h4>';
  }
  http.send(null);
  
  window.opener.location.href = window.opener.location.href;
}

//sms activate
function smsActive(id) {
  var act_code = document.getElementById("acode");
  var txt_info = document.getElementById("pay");
  
  //start AJAX code
  var http = getHTTPObject();
  http.open("GET", "sms_activate.php?id=" + escape(id) + "&code="+ act_code.value, true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      var xml     = http.responseXML;
      var results = xml.getElementsByTagName("x")[0].firstChild.nodeValue;
      txt_info.innerHTML = results;
    }
  }
  http.send(null);
  
  window.opener.location.href = window.opener.location.href;
}

//redirect to insert money from PopUp
function iMoney(url) {
  window.opener.location.href = "/user/"+encodeURIComponent(url);
  window.close();
}

//get Album Info
function getAInfo(id, pos) {
	var albLink    = document.getElementById("albumLINK");
	var albImg     = document.getElementById("albumIMG");
	var albumTxt   = document.getElementById("albumTXT");
	var albumlinks = document.getElementById("aLInks");
    
	var list = albumlinks.getElementsByTagName('a');
	for (var i = 0; i < list.length; i++) { 
    	if (i == pos)
			list[i].className = 'albClick';
		else
			list[i].className = 'albNClick';
	}
	
	albImg.src   = '/images/albums/'+id+'/midle.jpg';
  
	//start AJAX code
	var http = getHTTPObject();
	http.open("GET", "/get_albInfo.php?id=" + escape(id), true);
	http.onreadystatechange = function() {
	if (http.readyState == 4 && http.status == 200) {
      var xml     = http.responseXML;
      var results = xml.getElementsByTagName("x")[0].childNodes[0].nodeValue;
      albumTxt.innerHTML = results;
	  var results = xml.getElementsByTagName("y")[0].childNodes[0].nodeValue;
	  albLink.href = results;
    }
  }
  http.send(null);
}

function switch_galeries(tab) {
	$('.gglinks').hide();
	$('#' + tab).show();
}