jQuery(function() {	
	jQuery('#validationDialog').dialog({
			autoOpen: false,
			modal: true,
			width: 480,
			height: 140,
			resizable: false,
			buttons: {
						Ok: function() {
						
							jQuery(this).dialog('close');
							
						}
					}
	});
	
	jQuery(document).ready(function() {
		 jQuery('#news_carousel').jcarousel({
	        auto: 2,
	       wrap: 'circular',
	        initCallback: mycarousel_initCallback,
	        vertical: true,
	        scroll: 1
    	});
	});
	
	jQuery(document).ready(function() {
			/*
			*   Examples - images
			*/

			jQuery("a[rel=example_group_0]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
			jQuery("a[rel=example_group_1]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
			jQuery("a[rel=example_group_2]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		});
	
});

function checkSearch()
{
if (document.getElementById('q').value.length<=2)
	{
		jQuery('#validationContent').html('<b>Termenul cautat trebuie sa aiba cel putin 3 caractere!</b>');
	 	jQuery('#validationDialog').dialog('open');	

				return false;
	}
	return true;
}


function checkInput()
{
	
if (document.getElementById('victime').value.length<=2)
	{
		jQuery('#validationContent').html('<b>Numele cautat trebuie sa aiba cel putin 3 caractere!</b>');
	 	jQuery('#validationDialog').dialog('open');	

				return false;
	}
	return true;
}


function checkSearch2()
{
if (document.getElementById('c').value.length<=2)
	{
		jQuery('#validationContent').html('<b>Termenul cautat trebuie sa aiba cel putin 3 caractere!</b>');
	 	jQuery('#validationDialog').dialog('open');	

				return false;
	}
	return true;
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function ajax_check_captcha()
{
	
	var resp = makePOSTRequestCallback('_captcha_ajax.php', 'contact', null, null, true);
	
	if (resp == 'true')
		return true;
	else
		return false;
}

function check_email(email)
{
	errors = 0;
	var ero="`=[];\',/\\#$%^&*()+{}:\"<>?| ";
	var ned="@.";
	var er=0;

	var a = email;
	if (a.length==0)
		errors = 1;
	else
		if (a.length<4)
			errors = 2;
		else
		{
			for (j=0; j<=ero.length-1; j++)
				if (a.indexOf(ero.substring(j,j+1))!=-1)
					er=1;
			for (j=0; j<=ned.length-1; j++)
			{
				aos = a.split(ned.substring(j,j+1));
				for (var i=0; i < aos.length-1; i++)
					if (aos[i]<1)
						er=1;
				if (a.indexOf(ned.substring(j,j+1))==-1)
					er=1;
			}
			if (er==1)
			errors = 2;
		}

	if (errors != 0)
	 return false
	 else
	 return true;
}



function get_form_input(form, input_name)
{
	var obj_frm = form;
	var len_inp = obj_frm.elements.length;
	var set_input = null;
	for (var k = 0; k < len_inp; k++)
		if (obj_frm.elements[k].getAttribute("name") == input_name)
		{
			set_input = obj_frm[obj_frm.elements[k].getAttribute("name")];
			break;
		}
	return set_input;
}


function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function PassAjaxResponseToFunction(url, callbackFunction, params)
{
	var xmlhttp = new GetXmlHttp();
	//now we got the XmlHttpRequest object, send the request.

	if (xmlhttp)
	{
		xmlhttp.onreadystatechange =
		function ()
		{
			if (xmlhttp && xmlhttp.readyState==4)
			{//we got something back..

				if (xmlhttp.status==200)
				{
					var response = xmlhttp.responseText;
					var functionToCall = callbackFunction +
					'(response,'+params+')';
					if(debug)
					{
						// alert(response);
						// alert(functionToCall);
					}
					eval(functionToCall);
				} else if(debug){
					document.write(xmlhttp.responseText);
				}
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function SetInnerHTMLFromAjaxResponseJSON(url, obj_id)
{
	var xmlhttp = new GetXmlHttp();
	//now we got the XmlHttpRequest object, send the request.

	if (xmlhttp)
	{
		xmlhttp.onreadystatechange =
		function ()
		{
			if (xmlhttp && xmlhttp.readyState==4)
			{//we got something back..

				if (xmlhttp.status==200)
				{
					if(debug)
					{
						// alert(xmlhttp.responseText);
					}
					/*
					if(typeof obj_id == 'object')
					{
						obj_id.innerHTML = xmlhttp.responseText;
						obj_id.focus();
					}
					else
					{
						document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
						document.getElementById(obj_id).focus();
					}
					*/
					var obj_var = null;
					if(typeof obj_id == 'object')
					{
						obj_var = obj_id;
						// obj_id.innerHTML = xmlhttp.responseText;
						// obj_id.focus();
					}
					else
					{
						obj_var = document.getElementById(obj_id);
						// document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
						// document.getElementById(obj_id).focus();
					}
					
					if (obj_var)
					{
						obj_var = obj_var.getElementsByTagName("SELECT")[0];
			
						var za_data = eval(xmlhttp.responseText);
						obj_var.options.length = 0;
						for (var i = 0; i < za_data.length; i++)
							obj_var.options[i] = new Option(za_data[i][1], za_data[i][0]);
					}
				}
				else if(debug)
				{
					document.Write(xmlhttp.responseText);
				}
			}
		}
		xmlhttp.open("GET", url, false);
		xmlhttp.send(null);
		
		if (xmlhttp.responseText)
		{
			var obj_var = null;
			if(typeof obj_id == 'object')
			{
				obj_var = obj_id;
				// obj_id.innerHTML = xmlhttp.responseText;
				// obj_id.focus();
			}
			else
			{
				obj_var = document.getElementById(obj_id);
				// document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
				// document.getElementById(obj_id).focus();
			}
			
			if (obj_var)
			{
				obj_var = obj_var.getElementsByTagName("SELECT")[0];
	
				var za_data = eval(xmlhttp.responseText);
				obj_var.options.length = 0;
				for (var i = 0; i < za_data.length; i++)
					obj_var.options[i] = new Option(za_data[i][1], za_data[i][0]);
			}
		}
	}
}

function SetInnerHTMLFromAjaxResponse(url, obj_id)
{
	// alert(url);
	// alert(obj_id);
	
	var xmlhttp = new GetXmlHttp();
	//now we got the XmlHttpRequest object, send the request.

	if (xmlhttp)
	{
		xmlhttp.onreadystatechange =
			function ()
			{
				if (xmlhttp && xmlhttp.readyState==4)
				{//we got something back..
	
					if (xmlhttp.status==200)
					{
						// alert(xmlhttp.responseText);
						
						if(debug)
						{
							// alert(xmlhttp.responseText);
						}
						
						if (obj_id)
						{
							if(typeof obj_id == 'object')
							{
								obj_id.innerHTML = xmlhttp.responseText;
								//obj_id.focus();
							}
							else
							{
								// alert(xmlhttp.responseText);
								var za_object = document.getElementById(obj_id);
								
								var d = document.createElement('DIV');
								d.innerHTML = xmlhttp.responseText;
								
								while (za_object.childNodes.length > 0)
									za_object.removeChild(za_object.childNodes[0]);
								
								za_object.appendChild(d);
								// IE fix
								// document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
								// document.getElementById(obj_id).focus();
							}
						}
					}
					else if(debug)
					{
						document.Write(xmlhttp.responseText);
					}
				}
			}
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
		
		/*
		if (xmlhttp.responseText)
		{
			if(typeof obj_id == 'object')
			{
				obj_id.innerHTML = xmlhttp.responseText;
				// obj_id.focus();
			}
			else
			{
				document.getElementById(obj_id).innerHTML = xmlhttp.responseText;
				// document.getElementById(obj_id).focus();
			}
		}
		*/
	}
}

function makePOSTRequestCallback(url, form_name, callbackFunction, params, sync)
{
	var parameters = getFormParams(form_name);
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
	 	// set type accordingly to anticipated content type
	    //http_request.overrideMimeType('text/xml');
	    http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	    try {
	       http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	 }
	}
	if (!http_request)
	{
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	
	if (!sync)
	{
		http_request.onreadystatechange = function ()
		{
			 if (http_request.readyState == 4)
	      {
	         if (http_request.status == 200)
	         {
	            var response = http_request.responseText;
					var functionToCall = callbackFunction +
					'(response,'+params+')';
					if(debug)
					{
						// alert(response);
						// alert(functionToCall);
					}
					eval(functionToCall);
	         }
	         else
	         {
	            alert('There was a problem with the request.');
	         }
	      }
		};
	}
		
	if (sync)
	{
		http_request.open('POST', url, false);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		
		//alert(parameters['captcha_check']);
		
		http_request.send(parameters);
		
		if (http_request.status == 200)
			return http_request.responseText;
		else
			alert('There was a problem with the request.');
	}
	else
	{
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
}

function makePOSTRequest(url, form_name, div_id)
{
	var parameters = getFormParams(form_name);
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
	 	// set type accordingly to anticipated content type
	    //http_request.overrideMimeType('text/xml');
	    http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	    try {
	       http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	 }
	}
	if (!http_request)
	{
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	
	http_request.onreadystatechange = function ()
		{
			 if (http_request.readyState == 4)
	      {
	         if (http_request.status == 200)
	         {
	            if (div_id && document.getElementById(div_id))
	            {
	            	document.getElementById(div_id).innerHTML = http_request.responseText;
	            }
	            else
	            {
	            	alert(http_request.responseText);
	            }
	         }
	         else
	         {
	            alert('There was a problem with the request.');
	         }
	      }
		};
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function getFormParams(form_name)
{
	var inps = document.forms[form_name].getElementsByTagName("input");
	var sels = document.forms[form_name].getElementsByTagName("select");
	var texts = document.forms[form_name].getElementsByTagName("textarea");
	
	var all = {};
	
	for (var x=0; x<inps.length; x++) all[inps[x].name] = inps[x].value;
	for (var x=0; x<sels.length; x++) all[sels[x].name] = sels[x].value;
	for (var x=0; x<texts.length; x++) all[texts[x].name] = texts[x].value;
	
	var str = "";
	for (var k in all)
	{
		str += k + "=" + encodeURI(all[k]) + "&";
	}
	
	return str;
}
