﻿
//http://videos.teensnow.com/video121675/carmen_kinsley_and_mckenzee_miles
function f_alpha(e, obj)
{



try
{
var key;
var keychar;

if (window.event)
{
   key = window.event.keyCode;
}
else if (e)
{
   key = e.which;
}
else
{
   return true;
}
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
75

if (key != 8 && key != 0)
{


	if ((('!#$%^&*()+<>{}[]|\";').indexOf(keychar) > -1))
	{
  	 return false;
	}
	else
	{
  	 return true;
	}

}
else
{
   return true;
}

}
catch(e)
{	
	alert ("err: " + e);
}

}


function menuover()
{

	document.getElementById('menu_but').style.visibility ='hidden';

	document.getElementById('left_menu').style.visibility ='visible';
	try
	{
		document.getElementById('display1').style.visibility ='hidden';
	}
	catch (e)
	{
	}
}


function rollover(n)
{

 var x= 0;

	try 
	{
	for (i=1;i<4;i++)
	{

 x = i;

		eval ("document.getElementById('h_button" + i + "').style.visibility ='hidden';");
		eval ("document.getElementById('button" + i + "').style.backgroundColor ='#ffffff';");
	}

	if (n < 4)
	{
		eval ("document.getElementById('h_button" + n + "').style.visibility ='visible';");

		eval ("document.getElementById('button" + n + "').style.backgroundColor ='#e7e5e5';");
	}

	if (document.form1.hide_menu.value == "y")
	{
		document.getElementById('menu_but').style.visibility ='hidden';
		document.getElementById('left_menu').style.visibility ='visible';
	}

	document.form1.h_but.value = n;
	}
	catch(e)
	{
		alert(e + " " + n  + " " + x);
	}
}

function rollout(n)
{


	eval ("document.getElementById('h_button" + n + "').style.visibility ='hidden';");
	eval ("document.getElementById('button" + n + "').style.backgroundColor ='#ffffff';");

	if (document.form1.hide_menu.value == "y")
	{
		document.getElementById('menu_but').style.visibility ='visible';
		document.getElementById('left_menu').style.visibility ='hidden';
	}

	try
	{
		document.getElementById('display1').style.visibility ='visible';
	}
	catch (e)
	{
	}
}


function f_enter()
{

	if (document.form1.h_strip_pos.value != 1)
	{
		move('strip', 'top', -document.form1.strip_up.value);
		move('middle_main', 'top', 105);
		document.form1.h_strip_pos.value = 1; //top
		document.getElementById("strip_arrow").innerHTML = "<img src='images/arrow_down.png'>";
	}

	ajaxStrip(document.form1.feed.value, "update");

}

function strip_move()
{


	if (document.form1.h_strip_pos.value != 1)
	{
		move('strip', 'top', -document.form1.strip_up.value);
		move('middle_main', 'top', 105);
		document.form1.h_strip_pos.value = 1; //top
		document.getElementById("strip_arrow").innerHTML = "<img src='images/arrow_down.png'>";
	}
	else
	{
		move('strip', 'top', 1*document.form1.strip_up.value);
		move('middle_main', 'top', -105);
		document.form1.h_strip_pos.value = 0; //top
		document.getElementById("strip_arrow").innerHTML= "<img src='images/arrow_up.png'>";
	}
}


function move(name, v, value)
{
 var obj;
	try
	{
	obj = document.getElementById(name);

	if (obj)
	{

	if ( obj.currentStyle ) 
	{

		eval ('value = obj.currentStyle.' + v + '.replace( /px/g, "")*1 + value;')

	} 
	else if( window.getComputedStyle)
	{
		value = window.getComputedStyle( obj, null).getPropertyValue( v).replace( /px/g, "")*1 + value; 
	}

			eval('obj.style.' + v + ' = "' + value + 'px";');

	}
	}
	catch(e)
	{
		alert("aaa" + e + name);
	}
}


function browser()
{

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";

	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
 return BrowserDetect.browser;
}


function ajaxStrip(txt, task)
{


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");
  }
else
  {
alert("Your browser does not support XMLHTTP!");
  }


xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {


 //alert ("ajaxStrip : " +	xmlhttp.responseText);

	a = xmlhttp.responseText.split("!@#$");

	//a = a[1].split("|");

 	//document.getElementById("vscore").innerHTML=a[0] + "/" + a[1] + "";


	if (task == "read")
	{
		b = a[1].replace(/guest/gi,"Гость");
		document.getElementById("strip_body").innerHTML = b;
	}
	else
	{
		//alert ("ajaxStrip : " +	xmlhttp.responseText);
	}

  }
}


xmlhttp.open("GET","ajax/strip_ajax.php?task=" + task + "&txt=" + encodeURIComponent(txt),true);
xmlhttp.send(null);

}


function read_strip()
{
	window.setTimeout('read_strip()', 2000);
	//document.getElementById("strip_body").innerHTML = Date();
	ajaxStrip(document.form1.feed.value, "read");
}



function read_minus(task, sort1, sort2, page)
{

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");
  }
else
  {
alert("Your browser does not support XMLHTTP!");
  }


xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {


 //alert ("ajaxMinus : " +	xmlhttp.responseText);

	b = xmlhttp.responseText.split("!@#$");
	a = b[1].split("|");

	if (task == "read")
	{
		document.getElementById("minus_b").innerHTML= a[0];

	}
	else if (task == "sort")
	{
		document.getElementById("minus_b").innerHTML= a[0];
	}

	per_page = 20;
	cnt = a[1];

	if (cnt > per_page)
	{
		t1 = "";
		t2 = "";
		t3 = "";

		if (document.form1.h_curr_page.value > 1)
		{
			t1 = "<a href=# onclick='minus_next(\"prev\");'>Prev</a>&nbsp;";
		}
		if (document.form1.h_curr_page.value < cnt/per_page)
		{
			t3 = "<a href=# onclick='minus_next(\"next\");'>Next</a>&nbsp;";
		}

		for (i=1;i<(cnt/per_page)+1;i++)
		{
			if(i == document.form1.h_curr_page.value)	
			{	
				t2 = t2 + "<u>" + i + "</u>" + "&nbsp;";
			}
			else
			{
				t2 = t2 + "<a href=# onclick='minus_next(" + i + ");'>" + i +"</a>&nbsp;";
			}
		}


		t = t1 + t2 + t3;
	}

	document.getElementById("minus_nav").innerHTML = t;
  }
}


xmlhttp.open("GET","ajax/minus_ajax.php?task=" + task + "&sort1=" + sort1 + "&sort2=" + sort2 + "&page=" + page,true);
xmlhttp.send(null);

}



function read_display(id)
{

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");
  }
else
  {
alert("Your browser does not support XMLHTTP!");
  }


xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {


 //alert ("ajaxDisplay : " +	xmlhttp.responseText);

	b = xmlhttp.responseText.split("!@#$");

	document.getElementById("display1").innerHTML = "<b>" + id + "</b> <br>" + b[1];
  }
}


xmlhttp.open("GET","ajax/display_ajax.php",true);
xmlhttp.send(null);

}


function minus_next(n)
{

	c = 0 + document.form1.h_curr_page.value*1;
	if (n == "next")
	{
		document.form1.h_curr_page.value = (c + 1);
	}
	else if (n == "prev")
	{
		document.form1.h_curr_page.value = (c - 1);
	}
	else
	{
		document.form1.h_curr_page.value = n;

	}

	read_minus("sort", document.form1.h_sort_column.value, document.form1.h_sort_up.value, document.form1.h_curr_page.value);

}

function minus_sort(col)
{

	if (col == document.form1.h_sort_column.value)
	{

		if (document.form1.h_sort_up.value == 2)
		{
			document.form1.h_sort_up.value = 1;
		}
		else
		{
			document.form1.h_sort_up.value = 2;
		}
	}
	else
	{
		document.form1.h_sort_up.value = 2;
	}

	document.form1.h_sort_column.value = col;
	read_minus("sort", col, document.form1.h_sort_up.value, document.form1.h_curr_page.value);
}

function f_play(i)
{

	if (document.form1.h_play_id.value != 0)
	{
		eval ('document.getElementById("td_play' + document.form1.h_play_id.value + '").innerHTML = document.form1.h_play_html.value ');

	var tblMain = document.getElementById("tm");
  	var tBody = tblMain.getElementsByTagName("tbody")[0];
  	var firstRow = tBody.getElementsByTagName("tr")[document.form1.h_play_id.value];
  	var myCell = firstRow.getElementsByTagName("td")[3];
  	//myCell.colSpan = "1";

		//eval ('document.getElementById("tdd' + document.form1.h_play_id.value + '").innerHTML = document.form1.h_date_html.value ');
	}

	document.form1.h_play_id.value = i;
	eval ('document.form1.h_play_html.value = document.getElementById("td_play' + i + '").innerHTML');
	//eval ('document.form1.h_date_html.value = document.getElementById("td_date' + i + '").innerHTML');
 	eval('document.getElementById("td_play' + i + '").innerHTML = \'<embed src="music/3DAYSK.mid" width="140" height="15" autostart="true" loop="FALSE"> </embed>\';');

 	//eval('document.getElementById("tdd' + i + '").innerHTML = "";');


	var tblMain = document.getElementById("tm");
  	var tBody = tblMain.getElementsByTagName("tbody")[0];
  	var firstRow = tBody.getElementsByTagName("tr")[i];
 	var myCell = firstRow.getElementsByTagName("td")[3];
  	//myCell.colSpan = "2";


}

function display_song(s)
{

	read_display(s)

}

function legend_in()
{

		document.getElementById("grab1").innerHTML = '<img src="images/legend.png"  > </img>';

}

function legend_out()
{

		document.getElementById("grab1").innerHTML = '<img src="images/legend1.png"  > </img>';

}

function login(n)
{

	if (n ==0)
	{
		replaceP(document.form1.password);
		document.getElementById('login2_outer').style.visibility ='hidden';
		document.form1.email.value = "Email адрес";
		document.form1.password.value = "Пароль";


	}
	else
	{

		document.getElementById('login2_outer').style.visibility ='visible';

	}

}

function focusNClearInput(obj)
{
 
	if ((obj.value.indexOf('добавить новую категорию') != -1) || (obj.value.indexOf('Email адрес') != -1) || (obj.value.indexOf('Пароль') != -1) || (obj.value.indexOf('о чем задумался? напиши одной строкой...') !=-1))
	{
		obj.value = "";
	}
 

}

function replaceT(obj)
{

	var newO=document.createElement('input');
	newO.setAttribute('type', 'password');
	newO.setAttribute('name',obj.getAttribute('name'));
	newO.setAttribute('style',obj.getAttribute('style'));
	newO.setAttribute('onKeyPress',obj.getAttribute('onKeyPress'));
	obj.parentNode.replaceChild(newO,obj);
	newO.focus();
	document.form1.password.focus();
}


function replaceP(obj)
{
	var newO=document.createElement('input');
	newO.setAttribute('type', 'text');
	newO.setAttribute('name',obj.getAttribute('name'));
	newO.setAttribute('style',obj.getAttribute('style'));
	newO.setAttribute('onFocus','replaceT(this)');
	newO.setAttribute('onKeyPress',obj.getAttribute('onKeyPress'));
	obj.parentNode.replaceChild(newO,obj);

}


function ajaxCaptcha()
{
var xmlhttp;
var cpt;


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");
  }
else
  {
alert("Your browser does not support XMLHTTP!");
  }


xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {

	str = xmlhttp.responseText.split(";");

 //alert(str[0] + " : " + document.form1.h_from.value);

str[0] = 1; //test

	if (str[0] == 1)
	{
	
		if (document.form1.h_from.value == "update.php")
		{
			ajaxPass(); 
		}
		
		document.form1.ok.value = "ok"
		document.form1.submit();
	
	}
	else
	{
		document.form1.ok.value = "ok"

		//handle var in action
		var mtch = document.form1.action.search("=");
		if (mtch == -1)
		{
			document.form1.action = document.form1.action + "?";
		}

		document.form1.action = document.form1.action + "&err=1";
		document.form1.submit();
	}

	
  }
	
}

str = "ajax/captcha_ajax.php?txtCaptcha=" + document.form1.txtCaptcha.value;

xmlhttp.open("Post",str,true);
xmlhttp.send(null);


}

function trim(s) {
	s = s.replace(/(^\s*)|(\s*$)/gi,"");
	s = s.replace(/[ ]{2,}/gi," ");
	s = s.replace(/\n /,"\n");
	return s;
}

function fSubmit_login()
{

        document.form1.action = "login.php";
  	document.form1.submit();

}

function my_alert(v)
{	


	if (v == '')
	{
		document.getElementById('msg_box').style.visibility = 'hidden';
	}
	else
	{
		document.getElementById("msg_box").style.visibility = 'visible';
		document.getElementById("msg_txt").innerHTML = v;
	}
}