var star = new Image();
var star_o = new Image();
star.src = "images/star.gif";
star_o.src = "images/star_o.gif";
function changeImage(id, opt)
{
	for(var i = 1; i <= id; i++)
		document.getElementById("star_" + i).src = (opt == 0)? star.src : star_o.src;
}
//Post the Company rating
function postRating(rank, companyID)
{
	 $.ajax({
	   type: "GET",
	   data: "rank="+rank+'&company_id='+companyID,
	   url: "post_rank.php",
	   success: function(retVal){
			document.getElementById('rank').innerHTML = retVal;
		}
	   });
}
function validateSubmit()
{
	obj = document.frmComment;
	trimFields();
	if(obj.full_name.value == '')
	{
		alert("Please enter your Full Name.");
		obj.full_name.focus();
		return;
	}
	if(obj.email.value == '')
	{
		alert("Please enter your Email Address.");
		obj.email.focus();
		return;
	}
	if(!chkEmail(obj.email.value))
	{
		alert("Please enter a valid Email Address.");
		obj.email.focus();
		obj.email.select();
		return;
	}
	if(obj.location.value == '')
	{
		alert("Please enter your Location.");
		obj.location.focus();
		return;
	}
	if(obj.website.value != '' && !chkURL(obj.website.value))
	{
		alert("Please enter a valid Website.");
		obj.website.focus();
		obj.website.select();
		return;
	}
	if(obj.comment.value == '')
	{
		alert("Please enter your Comment.");
		obj.comment.focus();
		return;
	}
	if(obj.captcha_comment.value == '')
	{
		alert("Please enter the Security Code.");
		obj.captcha_comment.focus();
		return;
	}
	$('#btn_submit').css('display', 'none');
	$('#loader_blk').css('display', 'block');
	 $.ajax({
	   type: "POST",
	   data: "full_name="+obj.full_name.value+'&email='+obj.email.value+'&location='+obj.location.value+'&website='+obj.website.value+'&comment='+obj.comment.value+'&captcha='+obj.captcha_comment.value+'&company_id='+obj.company_id.value,
	   url: "post_comment.php",
	   success: function(retVal){
			if(retVal == 'SUCCESS')
				self.location = returnURL;
			else
				alert(retVal);
			$('#btn_submit').css('display', 'block');
			$('#loader_blk').css('display', 'none');
		}
	   });

}

function validateContact()
{
	obj = document.frmContact;
	trimFields();
	if(obj.c_full_name.value == '')
	{
		alert("Please enter your Full Name.");
		obj.c_full_name.focus();
		return;
	}
	if(obj.c_email.value == '')
	{
		alert("Please enter your Email Address.");
		obj.c_email.focus();
		return;
	}
	if(!chkEmail(obj.c_email.value))
	{
		alert("Please enter a valid Email Address.");
		obj.c_email.focus();
		obj.c_email.select();
		return;
	}
	if(obj.c_country.selectedIndex == 0)
	{
		alert("Please select your Country.");
		obj.c_country.focus();
		return;
	}
	if(obj.captcha_contact.value == '')
	{
		alert("Please enter the Security Code.");
		obj.captcha_contact.focus();
		return;
	}
	$('#btn_submit1').css('display', 'none');
	$('#loader_blk1').css('display', 'block');
	 $.ajax({
	   type: "POST",
	   data: "full_name="+obj.c_full_name.value+'&email='+obj.c_email.value+'&city='+obj.c_city.value+'&country='+obj.c_country.options[obj.c_country.selectedIndex].value+'&phone='+obj.c_phone.value+'&best_time_to_call='+obj.best_time_to_call.value+'&captcha='+obj.captcha_contact.value+'&company_id='+document.frmComment.company_id.value+'&message='+obj.message.value,
	   url: "post_contact.php",
	   success: function(retVal){
			if(retVal == 'SUCCESS')
			{
				$('#msg_blk').fadeIn();
				obj.c_full_name.value = '';
				obj.c_email.value = '';
				obj.c_country.selectedIndex = 0;
				obj.captcha_contact.value = '';
				obj.c_phone.value = '';
				obj.c_city.value = '';
				obj.message.value = '';
				obj.best_time_to_call.value = '';
			}
			else
			{
				alert(retVal);
			}
			$('#btn_submit1').css('display', 'block');
			$('#loader_blk1').css('display', 'none');
		}
	   });

}
