/* 2007 (c) Mallini Design Studio mailto:mallinidesign@gmail.com */


function my_getbyid(id){
	itm=null;
	if(document.getElementById){itm=document.getElementById(id);
	}else if(document.all){itm=document.all[id];
	}else if(document.layers){itm=document.layers[id];
	}return itm;}
function toggleview(id){
	if(!id)return;
	if(itm=my_getbyid(id)){
		if(itm.style.display=="none"){
			my_show_div(itm);
		}else{my_hide_div(itm);}}}
function my_hide_div(itm){if(!itm)return;itm.style.display="none";}
function my_show_div(itm){if(!itm)return;itm.style.display="";}


/*menu*/
function togglecategory(fid,add){
saved=new Array();
clean=new Array();
if(tmp=GetCookie('collapseprefs')){saved=tmp.split("%2C");}
for(i=0;i<saved.length;i++){
 if(saved[i]!=fid&&saved[i]!=""){clean[clean.length]=saved[i];}}
 if(add){clean[clean.length]=fid;
 my_show_div(my_getbyid('fc_'+fid));
 my_hide_div(my_getbyid('fo_'+fid));}
 else{my_show_div(my_getbyid('fo_'+fid));
 my_hide_div(my_getbyid('fc_'+fid));}
}



function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

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 SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
*/
function SetCookie(name, value) { 
var expdate = new Date (); 
expdate.setTime(expdate.getTime() + (3650 * 24 * 60 * 60 * 1000)); 
document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString() + "; path=/"; } 


function x () {return;}
function FocusText() {
    document.form.poster_message.focus();
    document.form.poster_message.select();
    return true; }
function DoSmilie(addSmilie) {
    var revisedmsgage;
    var currentmsgage = document.form.poster_message.value;
    revisedmsgage = currentmsgage+addSmilie;
    document.form.poster_message.value=revisedmsgage;
    document.form.poster_message.focus();
    return;
}
function DoPrompt(action) { var revisedmsgage; var currentmsgage = document.form.qmsgage.value; }



/*
	Поди разберись, что тут нахреначил.
*/

function InputPlaceholder (input, value, cssFilled, cssEmpty)
{
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.SaveOriginal = (input.value == value)
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

	if (input.value == '') this.onBlur();

	return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler)
{
	if (elem.attachEvent)
	{
		elem.attachEvent ('on' + eventType, handler)
	}

	if (elem.addEventListener)
	{
		elem.addEventListener (eventType, handler, false)
	}
}

InputPlaceholder.prototype.onFocus = function()
{
	if (!this.SaveOriginal &&  this.Input.value == this.Value)
	{
		this.Input.value = ''
	}
	else
	{
			this.Input.className = ''
	}
}

InputPlaceholder.prototype.onKeyDown = function()
{
	this.Input.className = ''
}

InputPlaceholder.prototype.onBlur = function()
{
	if (this.Input.value == '' || this.Input.value == this.Value)
	{
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
	}
	else
	{
		this.Input.className = this.CssFilled
	}
}

//Чекаем форму
function WhichClicked(ww) {
  window.document.postmodify.waction.value = ww;
}
function submitonce(theform) {
  if (document.all || document.getElementById) {
    for (i=0;i<theform.length;i++) {
      var tempobj=theform.elements[i];
      if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
        tempobj.disabled=true;
      }
    }
  }
}

var oSubmit;
var aFields={};
var aSubmits={};

Array.prototype.push=function(){
	for(var i=0; i<arguments.length; i++){
		this[this.length]=arguments[i];
	}
}

function getAttribute(oNode, sAttr){
	return (oNode.attributes) ? getAttributeIE(oNode, sAttr) : oNode.getAttribute(sAttr);
}

function getAttributeIE(oNode, sAttr){
	for(var i=0; i<oNode.attributes.length; i++){
		if(oNode.attributes[i].nodeName == sAttr)
			return oNode.attributes[i].nodeValue;
	}
	return null;
}

function getSelected(obj, bNoAutoconvert){
	var sType=(obj.type) ? obj.type : obj[0].type;
	//var sType=getFieldType(obj);
	var ReturnVal=null;
	switch(sType){
		case 'radio':
			//obj=obj.form[obj.name];
			for(var i=0; i<obj.length; i++){
				//if(obj[i].disabled) return 1;
				if(obj[i].checked){
					ReturnVal=(obj[i].disabled) ? 1 : obj[i].value;
					break;
				}
			}
			break;
		case 'select-one':
			if(obj.selectedIndex != -1) ReturnVal=obj[obj.selectedIndex].value;
			if(obj.disabled){ReturnVal=1;}
			break;
		case 'checkbox':
			if(obj.checked) ReturnVal=obj.value;
			if(obj.disabled) ReturnVal=1;
			break;
		default:
			ReturnVal=obj.value;
	}
	if(ReturnVal != null && bNoAutoconvert !=1)
		ReturnVal=parseInt(ReturnVal);
	return ReturnVal;
}

function IndexCheck(oForm){
	if(oForm){
		var oInput=oForm.getElementsByTagName('input');
		aFields[oForm.name]=[];
		for(var i=0; i<oInput.length; i++){
			if(oInput[i].type && oInput[i].type == 'submit'){
				aSubmits[oForm.name]=oInput[i];
				//oSubmit=oInput[i];
				continue;
			}
			if(getAttribute(oInput[i], 'required'))
				aFields[oForm.name].push(oInput[i]);
		}
		
		oInput=oForm.getElementsByTagName('textarea');
		for(var i=0; i<oInput.length; i++){
			if(getAttribute(oInput[i], 'required'))
				aFields[oForm.name].push(oInput[i]);
		}
	}
	
	CheckForm(oForm);
}

function GN_CheckForm(oForm){
	var bOK=true;
	if(oForm && aFields[oForm.name]){
		var aMyFields=aFields[oForm.name];
		for(var i=0; i<aMyFields.length; i++){
			if(!getSelected(aMyFields[i], 1)){
				bOK=false;
				break;
			}
		}
		
		SetSubmit(oForm, bOK);
	}
	return bOK;
}

function SetSubmit(oForm, bOK){
	if(aSubmits[oForm.name])
		aSubmits[oForm.name].disabled=!bOK;
}

function CheckForm(oForm){
	return GN_CheckForm(oForm);
}