function GetQueryString(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
 // UTF-8 data encode / decode
 // http://www.webtoolkit.info/javascript-utf8.html
 // http://www.webtoolkit.info/demo/javascript/utf8/demo.html
 function decode(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
 
 // this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function GetCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	//debugger;
	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 (var i = 0; i < a_all_cookies.length; i++ )
	{	    	
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].substring(a_all_cookies[i].indexOf('=')+1, a_all_cookies[i].length);
				
		// and trim left/right whitespace while we're at it
		cookie_name = a_all_cookies[i].substring(0, a_all_cookies[i].indexOf('=')).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 != null )
			{
				cookie_value = unescape( a_temp_cookie.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;
	}
	else
	{
	    return cookie_value;
	}
}		
 
//function GetCookie(c_name)//not working
//{
////alert('GetCarModelCookie ' + c_name );
//if (document.cookie.length>0)
//  {
//  c_start=document.cookie.indexOf(c_name + "=");
//  if (c_start!=-1)
//    { 
//    c_start=c_start + c_name.length+1; 
//    c_end=document.cookie.indexOf(";",c_start);
//    if (c_end==-1) 
//    {
//        c_end=document.cookie.length;
//    }
//    return unescape(document.cookie.substring(c_start,c_end));
//    } 
//  }
//return "";
//}

function SetCookie(cookieName,cookieValue)
{     
      //alert('SetCarModelCookie ' + cookieName + ' ' + cookieValue);
      document.cookie = cookieName + "=" + cookieValue + ";path=/;";
}
//it doesn't work
function GetParameterFromQueryString(key) { 
	var params;
	var qs;
	
	qs=location.search.substring(1,location.search.length);
	
	if (qs.length == 0) 
	{
	    return;
	}
    
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); 
    
	for (var i=0; i<args.length; i++) 
	{
		var value;
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		params[name] = value;
	}
	
	return params[key];
}

function ChangeCss(tag)
{   
    //debugger;
    var tagId = tag + "";
    
	var liId = GetQueryString(tagId);
	
    if(liId != null && liId != "")
	{
	    var tagPrefix;
	    
	    if(tagId == "tabId")
	    {
	        tagPrefix = "a";
	    }
	    else
	    {
	        tagPrefix = tagId;
	    }
	    
	    var liElement = document.getElementById(tagPrefix + liId);

	    if(liElement != null)
	    {
            //liElement.style.setAttribute("class","selected");
            //liElement.style.setAttribute("style","color:#003E7D;");
            liElement.style.color = "#003E7D";
	    }
	}
}

function invalidateDisclaimer(){
    var disclaimer = document.getElementById('disclaimer');
    document.getElementById('globalWrapper').removeChild(disclaimer);
    document.getElementById('globalWrapper').appendChild(disclaimer);
}

