var colors=new Array();
colors[0]="brown";
colors[1]="blue";
colors[2]="black";

function checkArray(colr){	
	for(i=0; i< colors.length;i++){		
		if(colors[i] == colr){
			return true;
		}	
	}
	return false;
}

function getURL(){
	  var url = window.location.href;
	   return url;	 
	}
	
function getColor(varname){
	  //var url = window.location.href;
	  var url =getURL()
	  var qparts = url.split("?");
	  if (qparts.length == 0){
		return "";
	  }
	  var query = qparts[1];
	  var vars = query.split("&");
	  var value = "";
	  for (i=0;i<vars.length;i++){			
		var parts = vars[i].split("=");	
		if (parts[0] == varname){			  
		  value = parts[1];					 
		  break;
		}
	  }
	  value = unescape(value);	
	  value.replace(/\+/g," ");
	  return value;
	}
//document.getElementById('FeedBacks').innerHTML = getValue('fBack');
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "": ";expires=" + exdate.toGMTString());
}

function getCookie(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 checkCookie() {
    username = getCookie('username');
  	//if (username != null && username != "") {
        //return;
  // }
  // {
        //username = prompt('Please enter your name:', "");		
		var url =getURL();
		var qpart = url.split("?");		
		if (qpart.length == 1){
			username = username;
			if (username != null && username != "") {
				setCookie('username', username, 365);
			}
			
		}else{
			username = getColor('color');
			checkArray(getCookie('username'))
			if (checkArray(username)) {
				setCookie('username', username, 365);
			}
		}	
	//}	
	
}
checkCookie();

var url =getURL();
var qpart = url.split("?");		
if (qpart.length > 1){
	if(checkArray(getCookie('username'))){
		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"portal/"+ getCookie('username') +".css\" />");	
		}else{
			alert("Sorry Entered " + getCookie('username') +" Theme is not found in Library")
			document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"portal/"+ getCookie('username') +".css\" />");	
		}
	}else{
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"portal/"+ getCookie('username') +".css\" />");	
}


	
//alert(colors.indexOf("green")); //alerts 2