﻿function check()
  {
     
      if ( window.event.keyCode == 13) {
			window.event.keyCode.returnValue=false;
            window.event.keyCode=true;
            redirect();

      }       
  }


	function SetToDefault ()
      {
     	var url = location.href;
		if (url.search(/English/)!=-1)
 		{
			if(document.getElementById('ctl00_InternalPages_Search').value=='')
      		{
               document.getElementById('ctl00_InternalPages_Search').value="Enter Keyword";
            }
         }
       	else
       	{
       	     if(document.getElementById('ctl00_InternalPages_Search').value=='')
      		{
               document.getElementById('ctl00_InternalPages_Search').value="أدخل كلمة البحث";
            }
       }
      }
     
      
      function ClearText()
      {
      	if((document.getElementById('ctl00_InternalPages_Search').value=='Enter Keyword') || (document.getElementById('ctl00_InternalPages_Search').value=='أدخل كلمة البحث'))
			{
				document.getElementById('ctl00_InternalPages_Search').value='';
			}
      }
      function URLEncode( )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
 
	var plaintext;
			var url = location.href;
		if (url.search(/English/)!=-1)
 	{
	plaintext = location.protocol+"//"+location.hostname+":"+location.port+"/English";
	}
	else
	{
	plaintext = location.protocol+"//"+location.hostname+":"+location.port+"/Arabic";
	}
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} 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);
			}
		}
	} // for


	return encoded;
}
     
function redirect(){

			var input = document.all["ctl00_InternalPages_Search"] ;
			var url = location.href;
			//alert(location.protocol+"//"+location.hostname+":"+location.port+"/English");
		    var str = input.value.replace(/ /g, "");
		    var len = str.length;	
			
			if (url.search(/English/)!=-1) 
			{
				if  ((input.value!='Enter Keyword') && (len!=0))
				{
		  
				window.location = "/English/Search/Pages/results.aspx?k="+input.value+"&s=All Sites";//+"&u="+URLEncode();
				}
				else
				{
				alert("Please enter keyword");
				}
			}
			else
			{
				if  ((input.value!='أدخل كلمة البحث') && (len!=0))
				{
				window.location = "/Arabic/Search/Pages/results.aspx?k="+input.value+"&s=All Sites";//+"&u="+URLEncode();
				}
				else
				{
				alert("فضلاً أدخل كلمة البحث");
				}
			}
		
}