var rusChars = new Array('а','б','в','г','д','е','ё','ж','з','и','й',
                             'к','л','м','н','о','п','р','с','т','у','ф','х','ч',
                             'ц','ш','щ','э','ю','я','ы', "ь");
var transChars = new Array('a','b','v','g','d','e','jo','zh','z','i','j',
                           'k','l','m','n','o','p','r','s','t','u','f','h', 'ch',
                           'c','sh','csh','e','ju','ja','y', "");
var engChars = "abcdefghojiklmnopqrstuvwxyz0123456789"

function translit(src){
    src = src.toLowerCase()
    var result = "";
    var len = src.length;
    var character, isRus;
    for(var i=0; i < len; i++){
        character = src.charAt(i,1);
        isRus = false;
        for(var j=0; j < rusChars.length; j++){
          if(character == rusChars[j]){
            isRus = true;
            break;
          }
        }
        if(strpos(engChars, character, 0) === false) character = "_";
        result += (isRus) ? transChars[j] : character;
    }

    return result;
}



function strpos( haystack, needle, offset){
     var i = haystack.indexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function is_object (mixed_var) {
    if (mixed_var instanceof Array) {        return false;
    } else {
        return (mixed_var !== null) && (typeof(mixed_var) == 'object');
    }
}

// возвращает cookie если есть или undefined
function getCookie(name) {
	var matches = document.cookie.match(new RegExp(
	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	))
	return matches ? decodeURIComponent(matches[1]) : undefined
}

// уcтанавливает cookie
function setCookie(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){ updatedCookie += "=" + propValue }
	}
	document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie(name) {
	setCookie(name, null, { expires: -1 })
}

$(document).ready(function(){
    $("input[name$='[delete_object]']").live("click", function(){
        $(this).parents("div.form:first").css("display", "none");
        $(this).parents("div.form:first").find("input").each(function(){
            $(this).val("0")
        });
        $(this).val("1");
    });
});
