var browserName=navigator.appName;

function open_rubr(t,id) {
	//$('mrubr_'+id).style.fontWeight = 'bold';
	if (t == 1) {
		$('srubr_blank').style.display = 'none';
		arr = $('jsarraymr').value;
		arr = arr.split(',');
		so = arr.length;
		for (i=0;i<so;i++) {
			$('srubr_'+arr[i]).style.display = 'none';
		}
		$('srubr_'+id).style.display = '';
	}
	else if (t == 2) {
		$('srubr2_blank').style.display = 'none';
		arr = $('jsarraysr').value;
		arr = arr.split(',');
		so = arr.length;
		for (i=0;i<so;i++) {
			$('srubr2_'+arr[i]).style.display = 'none';
		}
		$('srubr2_'+id).style.display = '';
	}
	else if (t == 3) {
		$('srubr3_blank').style.display = 'none';
		arr = $('jsarrays2r').value;
		arr = arr.split(',');
		so = arr.length;
		for (i=0;i<so;i++) {
			$('srubr3_'+arr[i]).style.display = 'none';
		}
		$('srubr3_'+id).style.display = '';
	}
}

function help_message(text) {
	winX = parseInt(window.innerWidth || document.documentElement.clientWidth)/2 - 200;
	winY = parseInt(window.innerHeight || document.documentElement.clientHeight)/2;
	left = 'left='+winX;
	top = 'top='+winY;
	wWidth = text.length;
	wHeight = text.length;
	if (wWidth >= 400) wWidth = 400;
	if (wHeight >= 200) wHeight = 200;
	window.open(_SITE+'msg.php?msg='+text,"","width="+wWidth+",height="+wHeight+",status=0,toolbar=0,"+top+","+left); 
}

function textCounter(field,maxlimit, s) {
	if (field.value.length > maxlimit) {
		alert(s);
		field.value = field.value.substring(0, maxlimit);
	}
}

function pip_choose_srubr() {
	var id = $('rubr').value;
	for (i=0;i<=23;i++) {
		$('mrubr_'+i).style.display = 'none';
	}
	$('mrubr_'+id).style.display = '';
}

function pip_showhide_cp(id) {
	if ($('cargo_param_'+id).value == 0) {
		$('product_cp_'+id).style.display = 'none';
	}
	else {
		$('product_cp_'+id).style.display = '';
	}
}

function pip_showhide_code(id) {
	if ($('tcode_'+id).value == 0)
		$('product_code_'+id).style.display = 'none';
	else
		$('product_code_'+id).style.display = '';
}

function pip_showhide_price(id) {
	if ($('shprice_'+id).value == 0) {
		$('product_price_'+id).style.display = 'none';
	}
	else {
		$('product_price_'+id).style.display = '';
	}
}

function pip_open_srubr() {
	var selectedArray = new Array(), i, count = 0;
	for (j=1;j<=16;j++) {
		if (j!=2&&j!=3) {
			var selObj = $('mrubr_'+j);
			for (i=0; i<selObj.options.length; i++) {
				if (selObj.options[i].selected) {
					selectedArray[count] = selObj.options[i].value;
					count++;
				}
			}
		}
	}
	$('srubr_array').value = selectedArray;
}

function pip_open_mrubr() {
	var selectedArray = new Array(), i, count = 0;
	var selObj = $('main_rubr');
	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
			selectedArray[count] = selObj.options[i].value;
			count++;
		}
	}
	$('mrubr_array').value = selectedArray;
	for (i=1;i<16;i++) {
		if (i!=2&&i!=3) $('mrubr_'+i).style.display = 'none';
	}

	for (i=0;i<selectedArray.length;i++) {
		if (selectedArray[i]!=2&&selectedArray[i]!=3&&selectedArray[i]<=16) $('mrubr_'+selectedArray[i]).style.display = '';
	}
}

function pip_change_video(l) {
	so = lc.length;
	for (i=0;i<so;i++) {
		$('pip_vid_'+lc[i]).style.display = 'none';
	}
	$('pip_vid_'+l).style.display = '';
}

function change_color(id, color) {
	$(id).style.backgroundColor = color;
}

function popup(v,p) {
	winX = parseInt(window.innerWidth || document.documentElement.clientWidth)/2 - 200;
	winY = parseInt(window.innerHeight || document.documentElement.clientHeight)/2;
	left = 'left='+winX;
	top = 'top='+winY;
	window.open(_SITE+v+'.php?'+p,"popupwindow","width=500,height=300,status=0,toolbar=0,"+top+","+left); 
}

function change_pic(v) {
	$('mainpic').src = v;
}

function showhide(id) {
	if ($(id).style.display == "block") {
		$(id).style.display = "none";
	}
	else {
		$(id).style.display = "block";
	}
}

function set_citys() {
	so = citys_ml.length;
	id = $('countrys').value;
	$('citys_0').style.display = 'none';
	for(i=0;i<so;i++) {
		if ($('citys_'+citys_ml[i]) != null)
			$('citys_'+citys_ml[i]).style.display = 'none';
	}
	$('citys_'+id).style.display = 'block';
}

function set_forms() {
	so = forms_ml.length;
	id = $('countrys').value;
	$('pforms_0').style.display = 'none';
	for(i=0;i<so;i++) {
		$('pforms_'+forms_ml[i]).style.display = 'none';
	}
	$('pforms_'+id).style.display = 'block';
}

function set_car_citys(v) {
	so = citys_ml.length;
	if (v == 'f_citys') {
		id = $('countrys_from').value;
		$('citys_f_0').style.display = 'none';
		for(i=0;i<so;i++) {
			$('citys_f_'+citys_ml[i]).style.display = 'none';
		}
		$('citys_f_'+id).style.display = 'block';
	}
	else if (v == 't_citys') {
		id = $('countrys_to').value;
		$('citys_t_0').style.display = 'none';
		for(i=0;i<so;i++) {
			$('citys_t_'+citys_ml[i]).style.display = 'none';
		}
		$('citys_t_'+id).style.display = 'block';
	}
}

function set_reg_blocks() {
	id = $('company_type').value;
	if (id == 1 || id == 2 || id == 3) {
		if (browserName == "Microsoft Internet Explorer") {
			$('transfer_type_block').style.display = 'block';
			$('transport_type_block').style.display = 'block';
			$('branch_block').style.display = 'none';
		}
		else {
			$('transfer_type_block').setAttribute("class", "show_block");
			$('transport_type_block').setAttribute("class", "show_block");
			$('branch_block').setAttribute("class", "hide_block");
		}
	}
	else {
		if (browserName == "Microsoft Internet Explorer") {
			$('transfer_type_block').style.display = 'none';
			$('transport_type_block').style.display = 'none';
			$('branch_block').style.display = 'block';
		}
		else {
			$('transfer_type_block').setAttribute("class", "hide_block");
			$('transport_type_block').setAttribute("class", "hide_block");
			$('branch_block').setAttribute("class", "show_block");
		}
	}
}

function links_td_out(id) {
	$('link_'+id).style.backgroundColor='#004D7E';
}

function links_td_over(id) {
	$('link_'+id).style.backgroundColor='#0069AC';
}

function submenu(id) {
	so = submenu_ml.length;
	for (i=0;i<so;i++) {
		if (browserName == "Microsoft Internet Explorer") {
			$('td_'+submenu_ml[i]).style.display = 'none';
		}
		else {
			$('td_'+submenu_ml[i]).setAttribute("class", "hide_submenu");
		}
	}
	if (browserName == "Microsoft Internet Explorer") {
		$('td_'+id).style.display = 'block';
	}
	else {
		if ($('td_'+id) != null)
		$('td_'+id).setAttribute("class", "show_submenu");
	}
}

function logout_form() {
	Delete_Cookie('AnimeShiRO3', '/', _SITE);
	reload('');
}

function set_language(lang) {
	Set_Cookie(COOKIELANG, lang, 60, '/', _CSITE);
	reload(_SITE);
}

function set_language2(lang) {
	Set_Cookie('pip_lang', lang, 60, '/', _CSITE);
	reload('');
}

function set_language3(lang, flag, str) {
	$('pip_flag').src = '/img/flags/'+flag+'.gif';
	$('pip_text').innerHTML = str;
	$('pip_lang').value = lang;
}

function capitalise(str) {
	if(typeof str != String) {
		return str;
	}
	var letter = str.substr(0,1);
	return letter.toUpperCase() + str.substr(1);
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
// don't use this, it's weak and does not handle some cases
// correctly, this is just to maintain legacy information
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function reload(l) {
	document.location=l;
}

function deletion(url, mes){
	if(confirm(mes))
		location.href = url;
}

function $$(id) {
	return document.getElementsByTagName(id);
}

function $(id) {
	return document.getElementById(id);
}
