jQuery(document).ready(function($){
	
	/* tipsy
		------------------------------------------------------------------------- */
 	$('.companies-photos img').tipsy();
	
	/* textarea
		------------------------------------------------------------------------- */
	$(pageInit);
	function pageInit()
	{
		$('.questions-answers-textarea').xheditor({tools:'Bold,Italic,Underline,Strikethrough,Link',skin:'default'});
		$('.account-textarea').xheditor({tools:'Bold,Italic,Underline,Strikethrough,Link',skin:'default'});
		$('.account-textarea-edit').xheditor({tools:'Bold,Italic,Underline,Strikethrough,Link',skin:'default'});
	}
	
	/* kwicks begin
		------------------------------------------------------------------------- */
	$('.kwicks').kwicks({
		max : 450,
		spacing : 0,
		sticky : false,
		event : 'mouseover'
	});
	
	/* sortable photos
		------------------------------------------------------------------------- */
	$('ul.sortable').sortable({
		placeholder: 'ui-state-highlight',
		forcePlaceholderSize: true
	});
	
	
	/* network websites
		------------------------------------------------------------------------- */
	if(document.all) {
		$('div.network-websites-button').hover(function() {
			$(this).addClass('hover');
			return false;
		},
		function() {
			$(this).removeClass('hover');
		});
	}
	
})


/* reset password
	------------------------------------------------------------------------- */
function reset_password(id,type)
{
	if(type=='focus')
	{
		$('#'+id+'_rm').hide();
		$('#'+id).removeClass('hidden');
		$('#'+id).focus();
	}
	
	if(type=='blur')
	{
		if($('#'+id).val()==''
		)
		{
			$('#'+id+'_rm').show();
			$('#'+id).addClass('hidden');
		}
	}
}


/* shadowbox
	------------------------------------------------------------------------- */
Shadowbox.init();

/* confirmation */

function confirmation(adress, str)
{
	if (confirm(""+str))
		document.location=adress;
}


/* ads
	------------------------------------------------------------------------- */
function ads(cat, id, url)
{
	$.ajax({
		type: "POST",
		url: url,
		data: "cat=" + cat + "&id=" + id
	});
}


/* search results
	------------------------------------------------------------------------- */
function search_results(str)
{
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
			bind_event();
		}
	}
	
	var str_encode= encodeURIComponent(str);
	
	xmlhttp.open("GET", basepath+"livesearch.php?page=search"+"&search="+str_encode, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

	xmlhttp.send();
}


/* bind event
	------------------------------------------------------------------------- */
function bind_event()
{ 
	jQuery(document).ready(function($){
		$('.companies-photos img').tipsy();
	})
}
	
	
/* show / hide
------------------------------------------------------------------------- */	
function show_hide(elementid){
	if(document.getElementById(elementid).style.display=='none'){
		document.getElementById(elementid).style.display=''
	}else{
		document.getElementById(elementid).style.display='none'}
}


/* vote company
	------------------------------------------------------------------------- */
function vote_company(sense, id, url, cat)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("side-company-score-content").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("POST", url, true);
	xmlhttp.send();
}



/* vote review
	------------------------------------------------------------------------- */
function vote_review(sense, id, url, cat)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("reviews-comments-score-"+id).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("POST", url, true);
	xmlhttp.send();
}



/* vote review
	------------------------------------------------------------------------- */
function vote_answer(sense, id, url, cat)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("questions-answers-vote-"+id).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("POST", url, true);
	xmlhttp.send();
}




/* delete image
	------------------------------------------------------------------------- */
function delete_image(id, url, cat, lang, str)
{
	if(confirm(""+str))
	{
		$('#photo-'+cat).load(url, {'id':id, 'url':url, 'cat':cat, 'lang':lang, 'str':str});
	}
}



/* delete gallery
	------------------------------------------------------------------------- */
function delete_gallery(id, id_com, url, cat, lang, str)
{
	if(confirm(""+str))
	{
		$('#photo-'+cat).load(url, {'id':id, 'id_com':id_com, 'url':url, 'cat':cat, 'lang':lang, 'str':str});
	}
}



/* login error
	------------------------------------------------------------------------- */
function login_error()
{
	Shadowbox.open({
		content: '<div class="error-message">You are not logged in! <a class="error-message" href="'+basepath+'account/login.html" title="Click here for login!">Click here for login!</></div>',
		player: "html",
		title: "Error - Not logged in",
		height: 100,
		width: 320
	});
};



/* field message
	------------------------------------------------------------------------- */
function field_message(field, msg_type, msg_text)
{
	the_field=document.getElementById('msg-'+field);
	the_field.innerHTML=msg_text;
	
	if(msg_type == 'green')
	{
		the_field.className='field-green-msg';
	}
	else if(msg_type == 'yellow')
	{
		the_field.className='field-yellow-msg';
	}
	else if(msg_type == 'red')
	{
		the_field.className='field-red-msg';
	}
}



/* check field
	------------------------------------------------------------------------- */
function check_field(field, content, lang, pag)
{
	$('#msg-'+field).load(basepath+'check-fields.html', {'field':field, 'content':content, 'lang':lang, 'pag':pag});
}



/* check password field
	------------------------------------------------------------------------- */
function check_password_field(field, content, password_content, lang, pag)
{
	$('#msg-'+field).load(basepath+'check-fields.html', {'field':field, 'content':content, 'password_content':password_content, 'lang':lang, 'pag':pag});
}



/* check captcha field
	------------------------------------------------------------------------- */
function check_captcha_field(field, pag)
{
	challenge_field = $("input#recaptcha_challenge_field").val(); 
	response_field = $("input#recaptcha_response_field").val();
	
	$('#msg-'+field).load(basepath+'check-fields.html', {'field':field, 'challenge_field':challenge_field, 'response_field':response_field, 'pag':pag});
}



/* check terms field
	------------------------------------------------------------------------- */
function check_terms_field(field, checked, pag)
{
	$('#msg-'+field).load(basepath+'check-fields.html', {'field':field, 'checked':checked, 'pag':pag});
}



/* check form
	------------------------------------------------------------------------- */
function check_form(form, lang, pag)
{
	check_field('username', form.username.value, lang, pag);
	check_field('password', form.password.value, lang, pag);
	check_password_field('retype_password', form.retype_password.value, form.password.value, lang, pag);
	check_field('email', form.email.value, lang, pag);
	check_field('user_type', form.user_type.value, lang, pag);
	check_field('first_name', form.first_name.value, lang, pag);
	check_field('second_name', form.second_name.value, lang, pag);
	check_field('gender', form.gender.value, lang, pag);
	check_field('phone', form.phone.value, lang, pag);
	check_captcha_field('recaptcha', pag);
	check_terms_field('terms', form.terms.checked, pag);
	
	//empty fields
	if((form.username.value == '') || (form.password.value == '') || (form.retype_password.value == '') || (form.retype_password.value == '') || (form.email.value == '') || (form.user_type.value == '') || (form.first_name.value == '') || (form.second_name.value == '') || (form.gender.value == '') || (form.phone.value == '') || (form.recaptcha.value == '') || (form.terms.checked == false) )
	{
		return false;
	}
	//completed fields
	else
	{
		//validated
		if((status_username == 1) && (status_password == 1) && (status_retype_password == 1) && (status_email == 1) && (status_user_type == 1) && (status_first_name == 1) && (status_second_name == 1) && (status_gender == 1) && (status_phone == 1) && (status_recaptcha == 1) && (status_terms == 1))
		{
			alert('toate');
			return false;
		}
		//unvalidated
		else
		{
			alert('partial');			
			return false;
		}
	}
}



/* contact fields class
	------------------------------------------------------------------------- */

function contact_input(id) 
{ 
	document.getElementById(id).className = "contact-input";
}

function contact_textarea(id) 
{ 
	document.getElementById(id).className = "contact-textarea";
}



/* contact - succes
	------------------------------------------------------------------------- */
function contact_succes(message)
{
	window.onload = function()
	{
		Shadowbox.open({
			content: '<div class="contact-succes-message">'+message+'</div>',
			player: "html",
			title: "Contact",
			height: 100,
			width: 320
		});
	}
};


/* contact - error
	------------------------------------------------------------------------- */
function contact_error(message)
{
	window.onload = function()
	{
		// open a welcome message as soon as the window loads
		Shadowbox.open({
			content: '<div class="contact-error-message">'+message+'</div>',
			player: "html",
			title: "Contact",
			height: 100,
			width: 320
		});
	}
};
