var baseUrl = "http://www.travel-shot.com";

function setStartMouse(pRate)
{
	var Pcnt = Math.round(pRate);
	
	for (starsIndex = 0; starsIndex < 5; starsIndex = starsIndex + 1)
	{
		picName = "";
    	if (starsIndex * 2 < Pcnt)
    	{
    		picName = "star.gif";
    	}
    	else if(pRate - (Pcnt * 2) == 1)
    	{
    		picName = "half_star.gif";
    		pRate = 0;
    	}
    	else
	    {
	    	picName = "blank_star.gif";    
	    }
	    
		elementImg = document.getElementById("starts_pic_" + (starsIndex + 1) * 2);
		elementImg.src = baseUrl + "/images/" + picName;
	}
}

function getStarsRate(pRate)
{
	var rating = Math.round(pRate);
	if (rating < 1 && pRate > 0)
	{
		rating = 1;
	}
	var Pcnt = Math.floor(rating / 2);
	var returnValue = "";
	
	for (starsIndex = 0; starsIndex < 5; starsIndex = starsIndex + 1)
	{
		picName = "";
    	if (starsIndex < Pcnt)
    	{
    		picName = "star.gif";
    	}
    	else if(rating - (Pcnt * 2) == 1)
    	{
    		picName = "half_star.gif";
    		rating = 0;
    	}
    	else
	    {
	    	picName = "blank_star.gif";    
	    }
	    
	    returnValue = returnValue + "<img src='" + baseUrl + "/images/" + picName + "'>";
	}
	return returnValue;
}

function rate_to(pRate, pId, pJSFunction)
{
	var Pcnt = Math.round(pRate);
	var returnValue = "";
	
	for (starsIndex = 0; starsIndex < 5; starsIndex = starsIndex + 1)
	{
		picName = "";
    	if (starsIndex * 2 < Pcnt)
    	{
    		picName = "star.gif";
    	}
    	else if(pRate - (Pcnt * 2) == 1)
    	{
    		picName = "half_star.gif";
    		pRate = 0;
    	}
    	else
	    {
	    	picName = "blank_star.gif";    
	    }
	    
	    returnValue = returnValue + "<a href = \"javascript::\" onclick=\"" + pJSFunction + "('" + pId + "', '" + ((starsIndex + 1) * 2) + "'); return false;\"><img id = \"starts_pic_" + (starsIndex + 1) * 2 + "\" src='" + baseUrl + "/images/" + picName + "' onmouseover=\"setStartMouse('" + (starsIndex + 1) * 2 + "', '" + pId + "')\" onmouseout=\"setStartMouse('" + pRate +"', '" + pId + "')\" alt=\"\"></a>";
	}
	
	return returnValue;
}

function deleteMsg(pValue)
{
	if(confirm('Are you sure you want to delete this message?'))
	{
		var objText = document.createElement("input");
		objText.name = "id";
		objText.value = pValue;
		objText.type = "hidden";
		document.getElementById("delete_form").appendChild(objText);
		document.getElementById("delete_form").submit();
	}
}

function deleteSubscription(pValue)
{
	if(confirm('Are you sure you want to delete this subscription?'))
	{
		var objText = document.createElement("input");
		objText.name = "id";
		objText.value = pValue;
		objText.type = "hidden";
		document.getElementById("delete_form").appendChild(objText);
		document.getElementById("delete_form").submit();
	}
}

function deletePicture(pValue)
{
	if(confirm('Are you sure you want to delete this pictures?'))
	{
		var objText = document.createElement("input");
		objText.name = "pid";
		objText.value = pValue;
		objText.type = "hidden";
		document.getElementById("delete_form").appendChild(objText);
		document.getElementById("delete_form").submit();
	}
}

function email_option_check()
{
	document.getElementById('radio_opt_2').checked = true;
	document.getElementById('mail_opt_2').checked = false;
	document.getElementById('mail_opt_3').checked = false;
	document.getElementById('mail_opt_4').checked = false;
	document.getElementById('mail_opt_5').checked = false;
}

function checkAll(name)
{
	for (i = 0; i < forminputs.length; i++)
	{
	    // regex here to check name attribute
	    	    alert('1');
	    var regex = new RegExp(name, "i");
	    alert('2');
		if (regex.test(forminputs[i].getAttribute('name')))
		{
			forminputs[i].checked = true;
		}
	}
}

function uncheckAll(field)
{
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = false ;
	}
}