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 = "index.php?command=Home&city=" + city;  		
  		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 findPos(id) {
	obj = document.getElementById(id);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);

	}
	return [curleft,curtop];
}

function showElement(id) {
	obj = document.getElementById(id);
	obj.style.display = 'block';
}

function hideElement(id) {	
	alert("hide");
	obj = document.getElementById(id);
	obj.style.display = 'none';
}

function moveObject(id, left, top) {
	obj = document.getElementById(id);
	obj.style.position = 'absolute';
	obj.style.left = left;
	obj.style.top = top;
}
var a = true;

var currentOpenDiv = "";

function showDetails(offerID) {	
		if(currentOpenDiv != ""){
			closeDetailsWindow(currentOpenDiv);
		}
		
		mainDivId = "box_" + offerID;
		detailsDivId = "details_" + offerID;
		currentOpenDiv = detailsDivId; 
		
//		showElement(detailsDivId);
//		positions = findPos(mainDivId);
//		x = positions[0];
//		y = positions[1];
//		x = (screen.width - 200) / 2;
//		y  =(screen.height -200) / 2;
//		
////		moveObject(detailsDivId, x + "px", y + "px");
//		moveObject(detailsDivId, x + "px", y + "px");
		
		
		showdeadcenterdiv(800, 500, detailsDivId);
	
	
	
}

function showdeadcenterdiv(Xwidth,Yheight,divid) {
	// First, determine how much the visitor has scrolled

	var scrolledX, scrolledY;
	if( self.pageYoffset ) {
	scrolledX = self.pageXoffset;
	scrolledY = self.pageYoffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	scrolledX = document.documentElement.scrollLeft;
	scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
	scrolledX = document.body.scrollLeft;
	scrolledY = document.body.scrollTop;
	}

	// Next, determine the coordinates of the center of browser's window

	var centerX, centerY;
	if( self.innerHeight ) {
	centerX = self.innerWidth;
	centerY = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
	centerX = document.documentElement.clientWidth;
	centerY = document.documentElement.clientHeight;
	} else if( document.body ) {
	centerX = document.body.clientWidth;
	centerY = document.body.clientHeight;
	}

	// Xwidth is the width of the div, Yheight is the height of the
	// div passed as arguments to the function:
	var leftoffset = scrolledX + (centerX - Xwidth) / 2;
	var topoffset = scrolledY + (centerY - Yheight) / 2;
	// The initial width and height of the div can be set in the
	// style sheet with display:none; divid is passed as an argument to // the function
	var o=document.getElementById(divid);
	var r=o.style;
	r.position='absolute';
	r.top = topoffset + 'px';
	r.left = leftoffset + 'px';
	r.display = "block";
	} 

	

function closeDetailsWindow(id) {
	obj = document.getElementById(id);
	obj.style.display = "none";
	
}
