function blank() {
if(document.forms[0]) {
document.forms[0].reset();
$("input#b").attr("value", "");
}
}

function send(fo) {
$("div#results").html("<img src='/catalog/img/load.gif'>");
$.post("/catalog/search.php", $("#search_form").serialize(), function(data){

    $("div#results").html(data);
  });
}

function send3(fo) {
if(fo=="b") {
$("tr#c").html("");
}

$.post("/catalog/search3.php", $("#search_form").serialize(), function(data){
    $("div#results").html(data);
  });
}

function send2(fo,state) {
if(fo=="b") {
$("tr#c").html("");
}

if (fo=="IN_STOCK")
	$("input#IN_STOCK").attr("checked", state);

$.post("/catalog/search2.php", $("#search_form").serialize(), function(data){
    $("div#s_res").html(data);
  });
}

function search_ref() {
	$.post("/catalog/rule.php?act=search_ref", {watch_ref: $("#watch_ref").val()}, function(data){
    if(data == "nok") {
	alert('Артикул не найден!');
	}
	if(data >= 1) {
	window.location='/catalog/watch/'+data+'/';
	}
  });
}

function subm(b) {
$("input#b").attr("value", b);
document.forms.search_form.submit();
}

function chooseCity() {
$("div#ch_city").html("... загрузка ...");
$.get("/catalog/rule.php?act=getCity", function(data){
    $("div#ch_city").html(data);
  });
}

function newCity(city) {
$.post("/catalog/rule.php?act=newCity",{newCity:city}, function(data){
    $("div#ch_city").html(data);
	location.reload();
  });
}

function send_comment() {
$("div#SUBM_RES").html("... отправка ...");
$.post("/catalog/rule.php?act=addComm", $("#comment_sub").serialize(), function(data){
    $("div#SUBM_RES").html(data);
  });
}

function chPic(fname) {
$("#watch_photo").attr("src","/catalog/image.php?image=img/watch/"+fname);
}

function findObj(n) {
        var p, i, x;
        d=document;
        if ( (p=n.indexOf("?")) >0 && parent.frames.length ) {
                d=parent.frames[n.substring(p+1)].document;
                n=n.substring(0,p);
        }

        if  (!(x=d[n]) && d.all)  x=d.all[n];
        for (i=0;!x&&i<d.forms.length;i++)  x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++)  x=findObj(n,d.layers[i].document);
        if (!x && d.getElementById)  x=d.getElementById(n);
        return x;
}

function validate(n){
	x = findObj(n);
	t = x.value.replace(/(\D)*/g,'');
	x.value = t;
}

function show_shops(wid) {
$.get("/catalog/show_shops.php", {w_id: wid}, function(data){
    $("div#s_test").html(data);
  });
}

function show_articles(bid) {
$.get("/catalog/show_articles.php", {b_id: bid}, function(data){
    $("div#articles").html(data);
  });
}

function ClearForm(oForm){
  var elements = oForm.elements; 

  for(i=0; i<elements.length; i++) {
      
	field_type = elements[i].type.toLowerCase();
	
	switch(field_type) {
	
		case "text": 
		case "password": 
		case "textarea":
/*	        case "hidden":	*/
			
			elements[i].value = ""; 
			break;
        
		case "radio":
		case "checkbox":
  			if (elements[i].checked) {
   				elements[i].checked = false; 
			}
			break;

		case "select-one":
		case "select-multi":
            		elements[i].selectedIndex = -1;
			break;

		default: 
			break;
	}
    }
	return false;
}
