// JavaScript Document
function c_popup()
{
	if(confirm('Sunteti sigur ca vreti sa stergeti aceasta categorie si toate subcategoriile acesteia si de asemenea toate produsele acesteia?')) return true;
	return false;
}
function p_popup()
{
	if(confirm('Sunteti sigur ca vreti sa stergeti acest produs?')) return true;
	return false;
}
function putImage(imgName,minWidth,minHeight)
{
	//tb sa verific extenise sau mime
	timg = new Image();
	timg.src = imgName;
	var max_width = minWidth;
	var max_height = minHeight;

	if(timg.width)
	{
		width = timg.width/2;
		height = timg.height/2;
		if(height > width)
		{
			width = (width*max_height)/height;
			height = max_height;
		}
		else
		{
			height = (height*max_width)/width;
			width = max_width;
		}
	}
	else
	{
		width = max_width;
		height = max_height;
	}
	
	document.getElementById('divPreview').innerHTML = '<img src="'+imgName+'" width="'+width+'" height="'+height+'"/>';
}

function show_picture(pic,width,height){
	var l,t,w,h;
	if(typeof(width) == 'undefined') width = 9999;
	if(typeof(height) == 'undefined') height = 9999;
	w = (width>(screen.availWidth-10))?(screen.availWidth-10):width;
	h = (height>(screen.availHeight-25))?(screen.availHeight-25):height;
	l = (width>(screen.availWidth-10))?0:((screen.availWidth - 10 - w)/2);
	t = (height>(screen.availHeight-25))?0:((screen.availHeight - 25 - h)/2);
	if(height+16>(screen.availHeight-25) && (width+16)<=(screen.availWidth-10)) w += 16;
	if(width+16>(screen.availWidth-10) && (height+16)<=(screen.availHeight-25)) h += 16;
	str_buffer = '<html>      \
									<head>    \
										<title>Galerie Poze : ' + pic + '</title>    \
										<link rel="stylesheet" type="text/css" href="style.css">  \
									</head>         \
									<body style="margin: 0px;">     \
									<div align="center" style="width: ' + w + '; height: ' + h + '; overflow: auto; padding: 0px;">   \
									<a href="javascript: window.close();"><img src="' + pic + '" alt="' + pic + '" border="0"></a></div>               \
									</body>              \
								</html>                \
							 ';
	var picWin = window.open("","bigpic","statusbar=no, toolbar=no, menubar=no, directories=no, scrollbars=no, resizable=no, top=" + t + ", left=" + l + ", width=" + w + ", height=" + h);
	var pic_doc = picWin.document;
	pic_doc.write (str_buffer);
	pic_doc.close();
}

function invertSelection(formId)
{
	form = document.getElementById(formId);
	if(typeof(form) == 'undefined')
	{
		alert('Eroare: nu am gasit form-ul'); 
		return;
	}
	
	for(var i = 0; i < form.elements.length; i++)
	{
		if(form.elements[i].type == 'checkbox')
			form.elements[i].checked = !form.elements[i].checked;
	}
}

function checkboxesState(formId,state)
{
	form = document.getElementById(formId);
	if(typeof(form) == 'undefined')
	{
		alert('Eroare: nu am gasit form-ul'); 
		return;
	}
	
	for(var i = 0; i < form.elements.length; i++)
	{
		if(form.elements[i].type == 'checkbox')
			form.elements[i].checked = state;
	}
}

function noEnter(numeButon) 
{
  if(window.event && window.event.keyCode == 13)
	{
		submit = document.getElementById(numeButon);
		if(typeof(submit) == 'undefined') return false;
		submit.click();
		return false;
	}
	return true;
}

function switchHelp(checkboxId)
{
	checkbox = document.getElementById(checkboxId);
	if(typeof(checkbox) == 'undefined')
	{
		alert('Eroare: nu am gasit casuta'); 
		return;
	}
	boxEnabled = checkbox.checked; 
	if(boxEnabled == true) setCookie('__help__','true'); 
	else setCookie('__help__','false')
	//alert(boxEnabled);
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}