var coding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm';
var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));
var expired = new Date(today.getTime() - (56 * 86400000));

function rot13(input) {
    if (!input) return '';
    for (var output = '',i=0;i<input.length;i++) {
        character = input.charAt(i);
        position = coding.indexOf(character);
        if (position > -1)
            character = coding.charAt(position + 13);
        output += character;
    }
    return output;
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}
 
function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}


//PAGE COOKIE FUNCTIONS
function setLoginCookie(bool) {
	if(document.forms[0].txtUserName.value == "") {
		alert("Nothing was entered!")
		document.forms[0].txtUserName.focus(); 
		document.forms[0].chkCookie.checked = false;
	}
	if(bool)
		Set_Cookie("UserName",rot13(document.forms[0].txtUserName.value),expires);
	else
		Set_Cookie("UserName","",expired);
}

function getLoginCookie() {
	if(rot13(Get_Cookie("UserName")).length > 0) {
		document.forms[0].txtUserName.value = rot13(Get_Cookie("UserName"));
		document.forms[0].chkCookie.checked = true;
	}
}

function setSearchCookie() {
	theForm = document.forms[0];
	Set_Cookie("Seeking",rot13(theForm.ddlSeekingGender.options[theForm.ddlSeekingGender.selectedIndex].value),expires);
	Set_Cookie("Start",rot13(theForm.ddlSeekingStartage.options[theForm.ddlSeekingStartage.selectedIndex].value),expires);
	Set_Cookie("End",rot13(theForm.ddlSeekingEndAge.options[theForm.ddlSeekingEndAge.selectedIndex].value),expires);
	Set_Cookie("Country",rot13(theForm.ddlSeekingCountry.options[theForm.ddlSeekingCountry.selectedIndex].value),expires);
}

function getSearchCookie() {
	theForm = document.forms[0];
	if(rot13(Get_Cookie("Seeking")).length > 0) {
		for(i=0;i<theForm.ddlSeekingGender.length;i++){
			if(theForm.ddlSeekingGender.options[i].value == rot13(Get_Cookie("Seeking"))){
				theForm.ddlSeekingGender.options[i].selected = true;
			}
		}
		i = 0;
	}
	if(rot13(Get_Cookie("Start")).length > 0) {
		for(i=0;i<theForm.ddlSeekingStartage.length;i++){
			if(theForm.ddlSeekingStartage.options[i].value == rot13(Get_Cookie("Start"))){
				theForm.ddlSeekingStartage.options[i].selected = true;
			}
		}
		i = 0;
	}
	if(rot13(Get_Cookie("End")).length > 0) {
		for(i=0;i<theForm.ddlSeekingEndAge.length;i++){
			if(theForm.ddlSeekingEndAge.options[i].value == rot13(Get_Cookie("End"))){
				theForm.ddlSeekingEndAge.options[i].selected = true;
			}
		}
		i = 0;
	}
	if(rot13(Get_Cookie("Country")).length > 0) {
		for(i=0;i<theForm.ddlSeekingCountry.length;i++){
			if(theForm.ddlSeekingCountry.options[i].value == rot13(Get_Cookie("Country"))){
				theForm.ddlSeekingCountry.options[i].selected = true;
			}
		}
		i = 0;
	}
}
