var blnSubmitted = false;

function openWin (page2Show, width, height)
{
	var avaliableHeight;
	var avaliableWidth;
	var scrnTop;
	var scrnLeft;
	
	avaliableHeight = window.screen.height;
	avaliableWidth = window.screen.width;

	scrnTop = (parseInt(avaliableHeight)/2) - (parseInt(height)/2);
	scrnLeft = (parseInt(avaliableWidth)/2) - (parseInt(width)/2);  
	
	if (width == "max" || height == "max")
	{
		scrnTop = parseInt(0); 
		scrnLeft = parseInt(0);
	}
	else
	{
		scrnTop = parseInt(scrnTop); 
		scrnLeft = parseInt(scrnLeft);
	}
	
	if (width == "max")
	{
		width = parseInt(window.screen.width) - 10;     
	}
	
	if (height == "max")
	{
		height = parseInt( window.screen.height) - 20;
	}
	
	aNewWindow = window.open(page2Show, "sub", "status,scrollbars,resizable,height=" + height + ",width=" + width + ", left=" + scrnLeft + ", top=" + scrnTop)
} 

function doSearch(query)
{		
	if (query != "Search")
	{			
		//window.location.href = "http://localhost:8080/search/search.php?tag=" + query;
		//window.location.href = "http://bdpstaging.co.uk/gold_dust/search/search.php?tag=" + query;
		window.location.href = "http://golddust.bdplearning.com/search/search.php?tag=" + query;
	}
}

function checkrate(action) 
{    
    var strErr = "";

    if (blnSubmitted) 
    {
	    alert("Please be patient while we save the resource rating...");
    }
    else 
    {		        			
		var rad_val = get_radio_value_rate()
		//alert(rad_val)
		if (rad_val == 0)		 
		{ 
			strErr += "Please select a rating for this resource...\n";
		}
		
		var strEmail = document.frm.txtuseremail;		
		if (validate_email(strEmail)==false)		  
		{
			strErr += "Please enter a valid email...\n";
		}		
		
		// Error check
		if (strErr.length > 0) 
		{
			alert(strErr)
		}
		else 
		{
			var strMsgConfirm = "Are you sure you want to save this resource rating?";					
			
			if (confirm(strMsgConfirm)) 
			{
				blnSubmitted = true;
				document.frm.txtAction.value = action;
				document.frm.submit();				
			}
		}
	}
}

function get_radio_value_rate()
{
    var rad_val = 0
    for (var i=0; i < document.frm.group1.length; i++)
   {
      if (document.frm.group1[i].checked)
      {
        rad_val = document.frm.group1[i].value;
      }
   }
   return rad_val;
}

function validate_email(field)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
			{return false;}
		else 
			{return true;}
	}
}

