var orgTypeIndex="";
var orgTypeName="";
var orgIndex="";
var orgName="";
var CheckBoxIndex="";
var selChildIndex="";
var selChildText="";


/// the value url will fetch from corresponding pages
function setCheckBoxCookie(selectedChildIndex,selectedChildText)
{ 
 cookieValue="CheckBoxIndex=IDLIKE 'PERCEN" + selectedChildIndex + "PERCEN'!" + selectedChildText + ",";     
 var commonServices = new CommonServices();
 commonServices.post(url, cookieValue,'hiddenPolicyPostValue'); 
 return false;
}

function setListboxCookie(selectedChildIndex,selectedChildText)
{       
    cookieValue="listBoxIndex= IDLIKE 'PERCEN" + selectedChildIndex + "PERCEN'!" + selectedChildText + ",";
    var commonServices = new CommonServices();
    commonServices.post(url, cookieValue,'hiddenPolicyPostValue'); 
    return false;
}

function AddlIndexTerms(selectedChildIndex,selectedChildText)
{       
    cookieValue="AddlIndexTerms= IDLIKE 'PERCEN" + selectedChildIndex + "PERCEN'!" + selectedChildText + ",";
    var commonServices = new CommonServices();
    commonServices.post(url, cookieValue,'hiddenPolicyPostValue'); 
    return false;
}

function setCookieOnOrgTypeAttributes(TorgTypeIndex,TorgTypeName)
{ 
  cookieValue="orgTypeIndex="+TorgTypeIndex+","+TorgTypeName;
  var commonServices = new CommonServices();
  commonServices.post(url, cookieValue,'hiddenPolicyPostValue'); 
  return false;
}

function setCookieOnOrgAttributes(TorgIndex,TorgName)
{   
  // while clicking on organization always goes to organization search results    
  cookieValue="orgIndex="+TorgIndex+","+TorgName;      
  var commonServices = new CommonServices();
  commonServices.post(OrgSearchResultsurl, cookieValue,'hiddenPolicyPostValue'); 
  return false;
}



function setMediaCheckBoxCookie(MediaGuid,MediaText)
{ 
  cookieValue="MediaTypeGuid="+MediaGuid+"!"+MediaText; 
  var commonServices = new CommonServices();
  commonServices.post(url, cookieValue,'hiddenMediaPostValue'); 
  return false;
}

function setMediaListBoxCookie(TopicGuid,TopicText)
{  
  cookieValue="TopicsGuid="+TopicGuid+"!"+TopicText;
  var commonServices = new CommonServices();
  commonServices.post(url, cookieValue,'hiddenMediaPostValue'); 
  return false;
}



function CommonServices() 
{ 
	this.queryStrings = {};
	
	var queryString = location.search.substring(1, location.search.length);
	
	if (queryString.length > 0) 
	{
        queryString = queryString.replace(/\+/g, ' ');
	    var args = queryString.split('&'); 
    	
        
	    for (var i = 0; i < args.length; i++) 
	    {
		    var pair = args[i].split('=');
		    var name = decodeURIComponent(pair[0]);
    		
		    var value = (pair.length==2)
			    ? decodeURIComponent(pair[1])
			    : name;
    		
		    this.queryStrings[name] = value;
	    }
	}
	
	this.Cookies = document.cookie;
}

CommonServices.prototype.getQueryString = function(key) 
{
	var value = this.queryStrings[key];
	return value;
}

CommonServices.prototype.containsQueryString = function(key) 
{
	var value = this.queryStrings[key];
	return (value != null);
}

CommonServices.prototype.setCookie = function ( name, value, exp_y, exp_m, exp_d, path )
{
    var cookie_string = name + "=" + escape ( value );

    if ( exp_y && exp_m && exp_d)
    {
        var expires = new Date ( exp_y, exp_m, exp_d );
        cookie_string += "; expires=" + expires.toGMTString();
    }

    if ( path )
        cookie_string += "; path=" + escape ( path );

    document.cookie = cookie_string;
}

CommonServices.prototype.getCookie = function ( cookie_name )
{
    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

    if ( results )
        return ( unescape ( results[2] ) );
    else
        return null;
}

CommonServices.prototype.deleteCookie = function ( cookie_name )
{
    var cookie_date = new Date ( );  // current date & time
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

CommonServices.prototype.post = function(url, postValue, postName) 
{
      var temp = document.createElement("form");
      temp.action = url;
      temp.method = "POST";
      temp.style.display = "none";

      var opt = document.createElement("textarea");
      opt.name = postName;
      opt.value = postValue;
      temp.appendChild(opt);

      document.body.appendChild(temp);
      temp.submit();

      return temp;
}

