var bCount = 0;

// Creates & returns an ajax object
function newAjaxObject()
{
	var xmlhttp = null;
	
	try
	{
		// Mozilla, Opera, Safari, Konqueror and everything else uses this method
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			// IE lower than 6 implements Msxml lib (only 5.xx versions,
			// versions below 5.0 does not support asynchronous queries
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				// For IE 6 and later
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				// No asynchronous support provided by this browser...
				alert("Your browser doesn't support Ajax Requests\n\nTherefore, certain features may not be available to you.")
			}
		}
	}
	return xmlhttp;
}

// Init some new ajax objects
var ajax = newAjaxObject(); // this is globally used
var ajaxBusy = false;

// Makes a query using the ajax object ajaxObj to the page serverPage
// using GET or POST (sendMethod) and puts the response into the div with the id divID
// If the POST method is prefered, the params to be sent must be given as a string of this form:
// field1=value1&field2=value2&field3=value3 (etc.)
function makequery( ajaxObj, serverPage, divID, sendMethod, params )
{
	// Get the container's handler
	var div = document.getElementById( divID );
	
	if( ajaxBusy )
	{
		ajaxObj.onreadystatechange = function() {}
		ajaxObj.abort();
	}
	
	if( ajaxObj )
	{
		if( sendMethod == "GET" )
		{
			ajaxObj.open( "GET", serverPage, true );
			ajaxBusy = true;
			ajaxObj.onreadystatechange = function()
			{
				if( ajaxObj.readyState == 4 && ajaxObj.status == 200 )
				{
					div.innerHTML = ajaxObj.responseText;
				}
				ajaxBusy = false;
			}
			ajax.send( null );
		}
		else if( sendMethod == "POST" )
		{
			ajaxObj.open( "POST", serverPage, true );
			ajaxBusy = true;
			ajaxObj.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );
			ajaxObj.onreadystatechange = function()
			{
				if( ajaxObj.readyState == 4 && ajaxObj.status == 200 )
				{
					div.innerHTML = ajaxObj.responseText;
				}
				ajaxBusy = false;
			}
			ajaxObj.send( params );
		}
		else
		{
			// No other valid known methods for passing the data...
			alert( "Invalid or no method passed to the function!" );
			return;
		}
	}
}

function showHide(divID) 
{
	document.getElementById(divID).style.display == 'none' ? document.getElementById(divID).style.display = 'block' : document.getElementById(divID).style.display = 'none';
}

function pop(src)
{
	window.open('<?php echo BASE_HREF; ?>custom_images/produse/full/'+stripPath(src),'popup' ,'resizable=1, status=0, toolbar=0, location=0, menubar=0, width=850, height=850');
}

function stripPath(loc)
{
	return loc.replace(/^(((.+)\/)+)?(([\w\-_]+\.)+\w{3})$/, '$4');
}

function changePic(newSrc,desc)
{
	document.getElementById('bigPic').src=mainWebsiteURL+'custom_images/restaurants/'+stripPath(newSrc);
	document.getElementById('bigPicDesc').innerHTML=desc;
}

function activate(objectName){
	document.getElementById(objectName).className='hover';
}

function deactivate(objectName){
	document.getElementById(objectName).className='';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=window.location;
	
	return;
}

function closeWindow(Id)
{
	document.getElementById(Id).style.display = "none";
}

// Checks if a field is empty, and if so, resets the input's content to the default value
function checkField( obj, value )
{
	// Match any amount of white spaces
	if( obj.value.match( " " ) || obj.value == "" )
	{
		obj.value = value;
	}
	
	return false;
}

// Clears an input's content
function clearField( obj, value )
{
	if( obj.value == value )
	{
		obj.value = "";
	}
	
	return false;
}

function selectCategory(obj)
{
	document.getElementById('category').innerHTML = '';
	document.getElementById('location').innerHTML = '';
	document.getElementById('details').innerHTML = '';
	var selected = obj.options[obj.selectedIndex].value;
	makequery( ajax, mainWebsiteURL+'pages/banners.php?case=category&s=' + selected, 'category', "GET" );
}

function selectLocation(obj, old)
{
	document.getElementById('location').innerHTML = '';
	document.getElementById('details').innerHTML = '';
	var selected = obj.options[obj.selectedIndex].value;
	var oldSelected = old.options[old.selectedIndex].value;
	makequery( ajax, mainWebsiteURL+'pages/banners.php?case=location&old='+oldSelected+'&s='+selected, 'location', "GET" );
}

function updateDetails(obj, oldP, oldC)
{
	var selected = obj.options[obj.selectedIndex].value;
	var oldP = oldP.options[oldP.selectedIndex].value;
	var oldC = oldC.options[oldC.selectedIndex].value;
	makequery( ajax, mainWebsiteURL+'pages/banners.php?case=details&oldP='+oldP+'&oldC='+oldC+'&s='+selected, 'details', "GET" );
}

/*pop image*/

PositionX = 10;
PositionY = 10;


defaultWidth  = '';
defaultHeight = '';


var AutoClose = true;

var opt='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(src,imageTitle){
imageURL=src;
imageTitle=((imageTitle!='') ? imageTitle : 'West Island Restaurants');
imgWin=window.open('about:blank','',opt);
with (imgWin.document){
writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
writeln('<html><head><title>Loading...</title><style type="text/css">body{margin:0; padding:0;}</style>');
writeln('<sc'+'ript type="text/javascript">');
writeln('function reSizeToImage(){');
writeln('window.resizeTo(100,100);');
writeln('width=100+document.images[0].width;');
writeln('height=100+document.images[0].height;');
writeln('window.resizeTo(width,height);}');
writeln('function doTitle(){document.title="'+imageTitle+'";document.getElementById(\'loading\').style.display="none";}');
writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor="#ffffff" onload="reSizeToImage();doTitle();self.focus()">');
writeln('<table width="100%"><tr><td align="center" valign="middle"><p id="loading">Loading...</p><img name="wir" sr' + 'c='+imageURL+' style="display:block" onclick="self.close()" /></td></tr></table></body></html>');
close();		
}}

/*end pop image*/

// Set nota
function setNota(nota)
{
	document.getElementById('nota').value=nota;
}