
function URLEncode(url)
{
	var SAFECHARS = "0123456789" +	// Numeric
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
	"abcdefghijklmnopqrstuvwxyz" +
	"-_.!~*'()";
	var HEX = "0123456789ABCDEF";
	var plaintext = url;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ )
	{
		var ch = plaintext.charAt(i);
		if (ch == " ")
		{
			encoded += "+";
		}
		else if (SAFECHARS.indexOf(ch) != -1)
		{
			encoded += ch;
		}
		else
		{
			var charCode = ch.charCodeAt(0);
			if (charCode > 255)
			{
				alert( "Unicode Character '"
				+ ch
				+ "' cannot be encoded using standard URL encoding.\n" +
				"(URL encoding only supports 8-bit characters.)\n" +
				"A space (+) will be substituted." );
				encoded += "+";
			}
			else
			{
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
};

function checksynonyms()
{
	var nl = (screen.availWidth-725) / 2;
	var nh = (screen.availHeight-500) / 2;
	//val = document.getElementById('keyword').value;
	//if(val != '')
	//{
	//	val = URLEncode(val);
		searchwin = window.open("checksynonyms.rails" ,"searchwin", "height=500,resizable=0,width=750,statusbar=yes,scrollbars=yes,top="+nh+",left="+nl);
	//}
	//else
	//{
	//	alert('please, enter freetext search');
	//	return;
	//}
}

// if the country to region or country to world option is selected, then user should choose only one country
// The same condition is also applicable to region option


function CheckForCompare()
{
	searchform=document.frmsearch;
	if ((searchform.Country2Region.checked) || (searchform.Country2World.checked) || (searchform.country2itself.checked))
	{
		var icount=0;
		for (i=0;i<searchform.country.length;i++)
		{
			if (searchform.country.options[i].selected) icount++;
 			if (icount > 1) break;
		}
		if ((icount > 1) || (icount==0)) 
		{
			//alert ("Please select only one country.");
			alert( m.get("Select_Country") );
			searchform.rdcountry[0].checked=true;
			setCountry();
			searchform.country.focus();
			return 0;
		}
		else
			return 1;
	}
	if ((searchform.Region2RWorld.checked) || (searchform.Region2itself.checked))
	{
		var icount=0;
		for (i=0;i<searchform.region.length;i++)
		{
			if (searchform.region.options[i].selected) icount++;
 			if (icount > 1) break;
		}
		if ((icount > 1) || (icount==0)) 
		{
			//alert ("Please select only one region.");	
			alert( m.get("Select_Region") );
			searchform.rdcountry[1].checked=true;
			setRegion();
			searchform.region.focus();
			return 0;
		}
		else
			return 1;		
	}
}
// This is same as the above checkforcompare function but its for the search.asp page
function CheckForCompareinSearchPlus()
{
	searchform=document.frmsearch;
	if ((searchform.Country2Region.checked) || (searchform.Country2World.checked) || (searchform.country2itself.checked))
	{
		var icount=0;
		for (i=0;i<searchform.country.length;i++)
		{
			if (searchform.country.options[i].selected) icount++;
 			if (icount > 1) break;
		}
		if ((icount > 1) || (icount==0)) 
		{
			//alert ("Please select only one country.");
			alert( m.get("Select_Country") );
			searchform.country.focus();
			return 0;
		}
		else
			return 1;
	}
	if ((searchform.Region2RWorld.checked) || (searchform.Region2itself.checked))
	{
		var icount=0;
		for (i=0;i<searchform.region.length;i++)
		{
			if (searchform.region.options[i].selected) icount++;
 			if (icount > 1) break;
		}
		if ((icount > 1) || (icount==0)) 
		{
			//alert ("Please select only one region.");	
			alert( m.get("Select_Region") );
			searchform.region.focus();
			return 0;
		}
		else
			return 1;		
	}
}
function IgnoreSpace()
{
	if (event.keyCode != 32)
		 return true;
	else
		event.returnValue = false;
}
function RemoveSpaces(txtObj)
{
	var str = new String();
	var str1 = new String();
	str = txtObj.value;
		 		
	for (i=0;i<str.length;i++)
		if (str.substr(i,1) != ' ') str1 = str1 + str.substr(i,1)
	txtObj.value = str1;
//	alert (txtObj.value);
}
function trim(a)
{
	var retValue = a;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{ // Check for spaces at the beginning of the string
	   retValue = retValue.substring(1, retValue.length);
	   ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{ // Check for spaces at the end of the string
	   retValue = retValue.substring(0, retValue.length-1);
	   ch = retValue.substring(retValue.length-1, retValue.length);
	}
	return retValue
}
 
	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	function MM_findObj(n, d) { //v4.0
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
	function MM_swapImage() { //v3.0
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

//  updated by kasi on 25/9/04 to avoid the repetition of flavour by comparing the 
//  input controls "Flavour/Taste & List Existing/Other Flavors in the Range"  
function checkFlavour(text1,text2)
{
		var flag;
		flag=0;

		var txt1=text1
		var t1=txt1.split(",")
		
		var txt2=text2
		var t2=txt2.split(",")
		var msg="";
		var val1 = new String();
		var val2 = new String();
		
		for (i=0;i<t1.length;i++)
		{
			val1 = trim(t1[i]);
			val1 = val1.toLowerCase();
			for (j=0;j<t2.length;j++)
			{
				val2 = trim(t2[j])
				val2 = val2.toLowerCase();
//				alert ('|' + val1 + '|' + val2+'|');				
				if ((val1 != '') && (val2 != ''))
				{
					if (val1 == val2)
					{
						msg=msg + val1 + " "
						//alert ("Duplicate Entry in the Flavour Existing List : " + msg)
						alert(m.get("Flavour_Duplicate") + msg );
						flag=0;
						//break;
						return false;
					}
					else
						flag=1;
				}
			}
		}
		/*if (flag==0) 
		{
			alert ("Duplicate Entry in the Flavour Existing List : " + msg)
			return false
		}
		else*/
			return true
		
		
}
