var req="";
var content;
var gmapcoords="";
var page_num=0;
var search_by_name="";
var is_contact=0;
var is_car=0;
var is_slide=0;
var doc;
function empty() {}
function initialize() {	
	var x_coord=Number(gmapcoords.substr(0,9));
	var y_coord=Number(gmapcoords.substr(10,9));		
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("gugl_map"));		
		map.setCenter(new GLatLng(x_coord, y_coord), 15);
		var point = new GLatLng(x_coord, y_coord);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function() {			
			marker.openInfoWindowHtml("<p style='font-family:Arial; font-size:13px; padding-left:15px;'><b>улица Бадаева</b><br>Россия, Санкт-Петербург</p>");
		});
	}
	is_contact=0;	
}
var tahla=function(){	
	$('#car_smallpic').jcarousel({ scroll: 1 });
	$('#list_products').jcarousel({ scroll: 1 });
	is_car=0;
}
var slide=function() {
	$('.banners')
	.after('<div id="nav">')
	.cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause : 1,
		pager:  '#nav'
	});
	is_slide=0;
}
function yoz(elem_id){
	elem_id.value="Искать по имени или ID";
}
function tozala(elem_id){
	elem_id.value="";
}
function winload(action,prod_id,page_num,prod_name, cat_id){
	if (action==1) window.location = "?cat_id="+cat_id+"&page_num="+page_num+"&prod_id="+prod_id;
	if (action==2) window.location = "?prod_name="+prod_name+"&page_num="+page_num+"&prod_id="+prod_id;
}
function key_code(event,elem){
	if ((event.keyCode==13) && (elem!="")){		
		search_page(elem,0);
	}
}
function show_text(which_text){
	ajaxFunction("?action=1&which_text="+which_text);
	if (document.getElementById('site_body_index')!=null){document.getElementById('site_body_index').setAttribute("id", "site_body");}
}
function go_page(menu, cat_id, page_num,prod_id){
	if (menu==1){show_text(1); return;}		
	if (menu==4) {is_contact=1;}
	if (menu==5) {is_car=1;}
	if (menu==0) {is_car=1; is_slide=1}	
		ajaxFunction("?action="+menu+"&cat_id="+cat_id+"&page_num="+page_num+"&prod_id="+prod_id);
	if (menu==0) {document.getElementById('site_body').setAttribute("id", "site_body_index");}
	else {if (document.getElementById('site_body_index')!=null){document.getElementById('site_body_index').setAttribute("id", "site_body");}}	
}
function go_page2(prod_name, page_num, prod_id){
	is_car=1;
	ajaxFunction("?action=7&page_num="+page_num+"&prod_name="+prod_name+"&prod_id="+prod_id);	
}
function select_cat(action, selected_cat){
	ajaxFunction("?action=8&cat_id="+selected_cat, "combo_seri_name_div");
}
function select_prod_id(sel_prod_id){
	if (sel_prod_id!=-1){
		is_car=1;
		ajaxFunction("?action=9&sel_prod_id="+sel_prod_id);
		if (document.getElementById('site_body_index')!=null){document.getElementById('site_body_index').setAttribute("id", "site_body");}
	}
}
function hamma_belgilan(){
	var download_button=document.getElementById('download_button');	
	var com_file=document.getElementById('combo_file').value;	
	var com_opsys=document.getElementById('combo_operationsys').value;
	var com_cat=document.getElementById('combo_category').value;
	var com_prod=document.getElementById('combo_prodname').value;
	if (com_file==2){
		if ((com_cat==-1) || (com_prod==-1)) {
			download_button.setAttribute('class', 'download_button_not');
		}else{
			download_button.setAttribute('class', 'download_button');
			download_button.innerHTML="<a href=\"javascript:search_manual("+com_prod+")\">ИСКАТЬ</a><br clear=\"all\">";
			
		}
	}
	if (com_file==3){
		if ((com_cat==-1) || (com_prod==-1) || (com_opsys==-1)) {
			download_button.setAttribute('class', 'download_button_not');
		}else{
			download_button.setAttribute('class', 'download_button');
			download_button.innerHTML="<a href=\"javascript:search_driver("+com_prod+", '"+com_opsys+"' )\">ИСКАТЬ</a><br clear=\"all\">";
		}
	}
}
var cat_id_fordown;
var prod_id_fordown;
function opsysnikorsat(prod_id){
	prod_id_fordown=prod_id;
	ajaxFunction("?action=opsysnikorsat"+"&prod_id="+prod_id, 'choose_os');
}
function search_driver(prod_id,type_os){
	ajaxFunction("?action=search_driver"+"&prod_id="+prod_id+"&type_os="+type_os, 'download_button');
}
function skachatnikorsat(type_os, prod_id){
	if (type_os==-1){
		document.getElementById('skachat_os').innerHTML="";		
	} else	ajaxFunction("?action=search_driver"+"&prod_id="+prod_id+"&type_os="+type_os, 'skachat_os');
}
function search_manual(prod_id){
	ajaxFunction("?action=search_manual"+"&prod_id="+prod_id, 'download_button');
}
function select_typ_file(typ_value){
	hamma_belgilan();
	ajaxFunction("?action=11&typ_val="+typ_value, "convert_os");
}
function select_cat_download(cat_value){	
	text_area=document.getElementById('combo_name_download');	
	if (cat_value==-1){
		text_area.setAttribute("class","combo_show");
	}else{
		text_area.setAttribute("class","");
		ajaxFunction("?action=10&cat_id="+cat_value, "combo_name_download");
	}	
}
function search_page(elem,page_num){		
	ajaxFunction("?action=6"+"&prod_name="+elem+"&page_num="+page_num);
	if (document.getElementById('site_body_index')!=null){document.getElementById('site_body_index').setAttribute("id", "site_body");}
}
function replace_bigpic(pic_name){	
	document.getElementById("big_pic").innerHTML="<div class=\"prod_pic_over\"><div class=\"prod_pic\"><div class=\"tr\"><div class=\"td\"><img id=\"big_pic_img\" src=\""+pic_name+"\"></div></div></div></div>";
}
var product_hover=function(product){
	product.getElementsByTagName('div')[1].setAttribute("style", "background:url(images/img20.png) no-repeat; cursor:pointer;");
	product.getElementsByTagName('p')[0].setAttribute("style", "color:#f28126");
}
var product_blur=function(product){				
	product.getElementsByTagName('div')[1].setAttribute("style", "background:url(images/img19.png) no-repeat; cursor:pointer;");
	product.getElementsByTagName('p')[0].setAttribute("style", "color:#fff");
}
function ajaxFunction(send, show_id){		
	if (show_id==undefined) show_id="site_content";
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
			var ajaxDisplay = document.getElementById(show_id);
			ajaxDisplay.innerHTML = decodeURIComponent(ajaxRequest.responseText);
			if (is_contact==1) {ajaxforcoord("?action=get_coord");}
			if (is_car==1) {tahla();}
			if (is_slide==1) {slide();}
			if(show_id=='combo_name_download'){hamma_belgilan();};
			/*if (send=="?action=3"){
				document.getElementById('combo_name_download').setAttribute('class', "")
				document.getElementById('combo_category').value=cat_id_fordown;
				document.getElementById('combo_prodname').value=prod_id_fordown;
				document.getElementById('combo_file').value=3;
			};*/
		}
	}
	var queryString=encodeURI(send);
	ajaxRequest.open("POST", "action.php" + queryString, true);
	ajaxRequest.send(null);
}
function ajaxforcoord(send){
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
			gmapcoords= decodeURIComponent(ajaxRequest.responseText);
			initialize();
			//alert(gmapcoords);
		}
	}
	var queryString=encodeURI(send);
	ajaxRequest.open("POST", "action.php" + queryString, true);
	ajaxRequest.send(null);
}
