/* @author http://www.brutka.com/ */

function onShow( name )
{
	var e = document.getElementById(name);
	e.className = ( e.className == 'none' )? 'block':'none';
}

function loadparams(page, my_function, p)
{
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	req.onreadystatechange = function(){ if(req.readyState == 4){ page.innerHTML = req.responseText; }}
	req.open("GET", '../js/server.php?'+my_function+'&params='+p, true);
	req.send(null);
}

function change_load_format(i)
{
	var f = document.getElementById('format-'+i).value;
	loadparams(document.getElementById('type-list-'+i), 'change_load_format', f+'-'+i);
}

function change_col_vo(id)
{
	var n = document.getElementById('col-vo-'+id).value;
	loadparams(document.getElementById('errore'), 'change_col_vo', id+'-'+n);
	change_count_photo(id);
	change_price_photo(id);
}

function change_CSP( id ){
	var n = document.getElementById('col-vo-'+id).value;
	loadparams(window.parent.document.getElementById('price_photo'), 'change_CSP', id+'-'+n);
	loadparams(window.parent.document.getElementById('count_photo'), 'get_CSP', id);
}

function change_SF( id ){
	var s = document.getElementById('format-'+id);
	var v = s.options[s.selectedIndex].value;
	loadparams(document.getElementById('errore'), 'change_SF', id+'-'+v);
	
	//var n = document.getElementById('col-vo-'+id).value;
	//loadparams(window.parent.document.getElementById('price_photo'), 'change_CSP', id+'-'+n);
}

function change_count_photo(id)
{
	var p = window.parent.document.getElementById('count_photo');
	loadparams(p, 'change_count_photo', id);
}

function change_picture_format(id)
{
	var elem = document.getElementById('format-'+id).value;
	loadparams(document.getElementById('errore'), 'change_picture_format', id+'-'+elem);
	change_price_photo(id);
}

function change_price_photo(id_price_photo)
{
	var p = window.parent.document.getElementById('price_photo');
	loadparams(p, 'change_price_photo', id_price_photo);
}

function on_click_check_img(elm)
{
	var img = elm.src.split('/');
	if(img[img.length-1] == 'on.png') elm.src = '../img/off.png';
	else elm.src = '../img/on.png';
}

function check_kadr(id)
{
	var elm = document.getElementById('kadr-'+id);
	on_click_check_img(elm);
	loadparams(document.getElementById('errore'), 'check_kadr', id);
	change_price_photo(id);
}

function check_red_eys(id)
{
	var elm = document.getElementById('red-eys-'+id);
	on_click_check_img(elm);
	loadparams(document.getElementById('errore'), 'check_red_eys', id);
	change_price_photo(id);
}

function check_polya(id)
{
	var elm = document.getElementById('polya-'+id);
	on_click_check_img(elm);
	loadparams(document.getElementById('errore'), 'check_polya', id);
	change_price_photo(id);
}

function show_hide_pay_type(e)
{
	var index=1;
	while(true)
	{
		var other = document.getElementById('payment_type_id_'+index);
		if(other) other.className = "none"; else break;
		index++;
	}
	
	var elem = document.getElementById('payment_type_id_'+e.value);
	elem.className = 'block';
}

function show_hide_delivery_type(e)
{
	var index=1;
	while(true)
	{
		var other = document.getElementById('delivery_type_id_'+index);
		if(other) other.className = "none"; else break;
		index++;
	}
	
	var elem = document.getElementById('delivery_type_id_'+e.value);
	elem.className = 'block';
}



// GOOGLE SEARCH 
try { google.load('search', '1'); } catch (exc) {  }
var searchControl;
var previousText = '';
OnSearchComplete = function(sc, searcher) {
	if ( searcher.results && searcher.results.length > 0) {
		if (previousText == '') previousText = document.getElementById("psr").innerHTML;
		document.getElementById("psr").innerHTML = '';
	} else if (searcher.results && searcher.results.length == 0 && previousText != '') {
		document.getElementById("psr").innerHTML = previousText;
	}
}
function OnLoad() {
	try {
// Create a search control

searchControl = new google.search.SearchControl();
searchControl.setSearchCompleteCallback(this, OnSearchComplete);
searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);

var siteSearch = new GwebSearch();
siteSearch.setSiteRestriction("migphoto.net");

var options = new GsearcherOptions();
options.setRoot(document.getElementById("sr"));
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
options.setNoResultsString('Поиск по сайту MigPhoto.net не дал результатов');

searchControl.addSearcher(siteSearch, options ); 

var drawopt = new GdrawOptions();
drawopt.setInput (document.getElementById("inputsm") );
searchControl.draw(document.getElementById("samcontrol"), drawopt); 
	}
	catch (exc) {  }
// Execute an inital search
//searchControl.execute("Google");
}
try {google.setOnLoadCallback(OnLoad); } catch (exc) {  }

function runSearch() {
	try {
		searchControl.execute( document.getElementById("inputsm").value );
	} catch (e) {
		
	}
	return false;
}