doEdit=1;

function changeSexType(sexType){
		setCookie("sexType", sexType);  		
  		window.location.reload();  		
  		
//  		document.argumentKeeper.sexType.value = sexType;  		 		
// 		document.argumentKeeper.submit();
}

function changeCityOld(city){
  		setCookie("city", city);  		
  		window.location.reload();
//  		document.argumentKeeper.city.value = city;  		 		
// 		document.argumentKeeper.submit();
}


function gotoPage(page){
  		document.lang.companyPage.value = page;
 		document.lang.submit();
}


function changeCity(city){
  		location = "command-ShowCategory-city-" + city + ".html";  		
  		gotoPage(location);
//  		document.argumentKeeper.city.value = city;  		 		
// 		document.argumentKeeper.submit();
}



function selectShop(id) {
	divID = "shop_" + id;
	(document.getElementById(divID)).style.backgroundColor = '#e2aae4';
	document.body.style.cursor='pointer';
}

function unselectShop(id) {
	divID = "shop_" + id;
	(document.getElementById(divID)).style.backgroundColor = 'white';
	
	document.body.style.cursor='';

}




function select(id) {
	topGifID = "topGif_" + id;
	mainID = "box_" + id;	
	bottomGifID = "bottomGif_" + id;
	rightGifID = "rightGif_" + id;
	
	(document.getElementById(mainID)).style.backgroundColor = "#eeeeee";
	document.body.style.cursor='pointer';
}

function selectAdmin(id) {
	topGifID = "topGif_" + id;
	mainID = "box_" + id;	
	bottomGifID = "bottomGif_" + id;
	rightGifID = "rightGif_" + id;
	
	(document.getElementById(topGifID)).style.background='url(ui/img/top_gray.gif)';
	(document.getElementById(rightGifID)).style.background='url(ui/img/right_gray.gif)';
	(document.getElementById(bottomGifID)).style.background='url(ui/img/bottom_gray.gif)';
	(document.getElementById(mainID)).style.backgroundColor = "#eeeeee";
	
}

function unselect(id) {
	topGifID = "topGif_" + id;
	mainID = "box_" + id;	
	bottomGifID = "bottomGif_" + id;
	rightGifID = "rightGif_" + id;
	
	(document.getElementById(mainID)).style.backgroundColor = "white";
	document.body.style.cursor='';
}



function choice(id, type, sexType, city, shopID, fromSearch){
	
	//window.location="index.php?command=ShowDetails1&id=" + id + "&type=" + type + "&sexType=" + sexType + "&city=" + city + "&shopID=" + shopID + "&fromSearch=" + fromSearch;
	url = "index.php?command=ShowDetails1&id=" + id + "&type=" + type + "&sexType=" + sexType + "&city=" + city + "&shopID=" + shopID + "&fromSearch=" + fromSearch;
	 //window.open (url, "a" + id, 'width=1000,height=600');
	 
	 wopen(url, "a" + id, 900, 570);
	 
	//alert(id);
}

function edit(id, sid){	
	if(doEdit == 1){
		window.location="index.php?command=EditProductForm&id=" + id + "&SID=" + sid;
		
	}else {
		doEdit = 1;
	}
	
	//alert(doEdit);
	
	
}


function setCookie( 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" : "" );
}


function showMenu(id) {	
	
	for (var i = 0; i<=15; i++) {
		if (document.getElementById('sexType_'+i)) {document.getElementById('sexType_'+i).style.display='none';}
	}	
	
	
	var d = document.getElementById(id);
	if (d) {
		d.style.display='block';
	}
}


function showLargeImage(pathToImage, title) {
	w= window.open(pathToImage,'_blank','width=1000, height=700, scrollbars=yes, top=0,left=0, resizable=yes');
	
	content = "<html><head><title>" + title + "</title></head><body style='text-align: center'><img src='" + pathToImage + "'></body></html>";
	w.document.write(content);
	w.document.close();
}


function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url, name,'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=yes');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}


function proba(sid, id) {
//	fr = document.getElementById( "experiment")
	//fr.src = "?command=EditProductForm&id=" + id + "sid" + sid;
//	fr.style.visibility="visible";
//	fr.style.height="400px";
	
}


function order(planNumber) {
	showHide("plans");
	showHide("order");	
	alert(planNumber);
}


function showHide(id) {	
	div = document.getElementById(id);
	if(div.style.display == "none"){
		div.style.display="block";
	}else {
		div.style.display="none";
	}
	
}
_numCity = 0;
_topPage = 0;
_firstPage = 0;
_nextPage = 0;

function calculatePrice(name, value) {

	if(name == "numCity"){
		_numCity = value;
	}
	if(name == "topPage"){
		_topPage = value;
	}
	if(name == "firstPage"){
		_firstPage = value;	
	}
	if(name == "nextPage"){
		_nextPage = value;
	}
	
	topPriceOneCity = _topPage * 30;
	firstPriceOneCity = _firstPage * 20; 
	nextPriceOneCity = _nextPage * 10;
	
	
	numCityWithKoef = _numCity;
	if(_numCity > 1){
		numCityWithKoef = (_numCity  - 1) * 0.3 + 1;
	}
	
	
	
	price_ = _numCity * (topPriceOneCity +  firstPriceOneCity +  nextPriceOneCity);
	

	
	priceWithDiscount_ = Math.round(numCityWithKoef * (topPriceOneCity +  firstPriceOneCity +  nextPriceOneCity));

	//Standard plans
	if(_numCity == 1){
		if(_nextPage == 3 && _firstPage == 0 && _topPage == 0){
			priceWithDiscount_ = 20;
		}
		if(_nextPage == 3 && _firstPage == 1 && _topPage == 0){
			priceWithDiscount_ = 34;
		}
		
		if(_nextPage == 4 && _firstPage == 2 && _topPage == 1){
			priceWithDiscount_ = 79;
		}
		
	}


	
	div = document.getElementById("price");
	divOld = document.getElementById("oldPrice");
	div.innerHTML = priceWithDiscount_; 

	if(price_ != priceWithDiscount_){
		divOld.innerHTML = "<div style='text-align: center; width: 50px; background: url(ui/img/expunge4.gif);background-position: center center; background-repeat: no-repeat;'>" + price_ + "</div>";
	}else {
		divOld.innerHTML = "";
	}
	
	form =  document.getElementById("order");
	form.price_.value=priceWithDiscount_;
	
	
	
	
}


	function openPresentation() {
		window.open('./present/start.html','_blank','width=800,height=600, resizable=yes,scrollbars=yes,toolbar=yes');
		//window.open('./present/start.html','_blank','width=800,height=600');
	}