function getURL(lang)
    {
	     Delete_Cookie('flagcookie', '/', 'prefrd.com');
	
       Set_Cookie('flagcookie',lang, 30, '/', 'prefrd.com', '');
       // var URL = "http://translate.googleusercontent.com/translate_c?rurl=translate.google.com&sl=en&tl="+lang+"&u=";
       var URL = "http://translate.google.com/translate?hl=en&ie=UTF-8&sl=en&tl="+lang+"&u=";
        var currURL = window.location.href;
        var newURL = URL + currURL;
        var URLXX = "http://translate.google.com/translate?u="+currURL+"&langpair=en|"+lang;
		     // alert(lang);
		// var URLXX = "http://translate.googleusercontent.com/translate_c?langpair=en|"+lang+"&rurl=translate.google.com&twu=1&u="+currURL+"&usg=ALkJrhgOi9qUFApRBEDWDs7o3CohM9j50A";
        if(lang!="en")
	       top.location.href = URLXX;
	    
 }
 
function getEnglishUrl()
{
       Delete_Cookie('flagcookie', '/', 'prefrd.com');
	
       Set_Cookie('flagcookie','en', 30, '/', 'prefrd.com', '');
       top.location.href = "http://prefrd.com?lng=en"; 
} 
 
 function getanyURL(lang)
    {
       // var URL = "http://translate.googleusercontent.com/translate_c?rurl=translate.google.com&sl=en&tl="+lang+"&u=";
       var URL = "http://translate.google.com/translate?hl=en&ie=UTF-8&sl=en&tl="+lang+"&u=";
        var currURL = window.location.href;
        
        if(currURL.indexOf("?") > 0)
        {
          currURL = currURL.replace("?", "?any=t&")
        }
        else
        {
           currURL = currURL+"?any=t";
        }
        var newURL = URL + currURL;
        var URLXX = "http://translate.google.com/translate?u="+currURL+"&langpair=en|"+lang
        window.top.location = URLXX;



    }
	
function Set_Cookie(name, value, expires, path, domain, secure )
{

// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie(check_name) {
	
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function checkflag()
{
var lng=Get_Cookie('flagcookie');

if(window.location.indexOf("lng")>0)
  {
      Set_Cookie('flagcookie','en', 30, '/', 'prefrd.com', '');
  }


  if(lng!="en")
   {
      if(lng== null){
      	getURL('en');
      }else{
      	getURL(lng);
      }
  }	
}

  function getEnURL(sURL)
    {
        var sURL = sURL.toString();

		if (sURL.indexOf("?") > 0) {
			var arrParams = sURL.split("?");

			var arrURLParams = arrParams[1].split("&");

			//var arrParamNames = new Array(arrURLParams.length);
			//var arrParamValues = new Array(arrURLParams.length);

			var i = 0;
			for (i=0; i < arrURLParams.length; i++) {
				var sParam =  arrURLParams[i].split("=");
                                //arrParamNames[i] = sParam[0];
				if(sParam[0]=="u")
                                    {
                                        var arrParamValues = unescape(sParam[1]);
                                    }
                               /* if (sParam[1] != "")
					arrParamValues[i] = unescape(sParam[1]);
				else
					arrParamValues[i] = "";*/
			}
                        return arrParamValues;

			/*for (i=0; i < arrURLParams.length; i++) {
				return arrParamValues[i];
			}*/
		} else {
			return "http://www.prefrd.com";
	    }
    }
    function displayURL()
    {
        var varia = getEnURL(window.location.href);
         window.location = varia;
        //alert(varia);
    }

    function divDisplay()
    {
		// alert("AKhilesh");
        document.getElementById('allFlags').style.display="block";
    }
	
window.onload=checkflag();
