/*
function setCookie(c_name, value, expiredays){
	var str = 'cookie: '+ c_name +' / '+ value + ' - previously: '+ getCookie(c_name) +"\n";
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	str += 'cookie is now: '+ getCookie(c_name);
	alert(str);
}
*/
function set_cookie( name, value, expires, path, domain, secure ){
	var str = 'setting cookie: '+ name +' / '+ value +"\n";
	//str += 'previously: '+ getCookie(name) +"\n";
	
	del_cookie(name);
	
	// 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" : "" );
	
	str += 'cookie is now: '+ get_cookie(name);
	//alert(str);
}

function get_cookie(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 del_cookie( name ) {
	if ( get_cookie( name ) ) document.cookie = name + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function check_cookie(){
	var curtab = get_cookie('ct');
	if (curtab!=null && curtab!=""){
		alert('Current tab is '+curtab+'!');
	}
	else{
		alert('No current tab');
	}
}

function get_redirect_url(current_url){
	if (current_url == ''){
		current_url = window.top.location.href.substring(9);
		next_slash = current_url.indexOf('/');
		current_url = current_url.substring(next_slash);
		//alert(current_url);
	}
	current_url = current_url.toLowerCase();
	//alert(current_url);
	//if you're on a profile, get the username and cookie for current tab
	if (current_url.substring(0, 9) == '/profile/'){
		if (current_url.indexOf('/', 10) > 0) var username = current_url.substring(9, current_url.indexOf('/', 10));
		else var username = current_url.substring(9);
		var cookie = get_cookie('ct');
		//alert(cookie);
		var new_url = '/profile/'+ username;
		if (cookie != '') new_url += '/'+ cookie;
		else new_url += '/wishes';
		return new_url;
	}
	else return current_url;
}

function drop_go(id){
	var url = $("#"+ id).val();
	if (url != '') location.href = url;
}

//jquery form submission
// prepare the form when the DOM is ready 
/*
$(document).ready(function() { 
    // bind to the form's submit event 
    $('#colorform').submit(function() { 
        $(this).ajaxSubmit({target: '#colors', beforeSubmit: showRequest, success: showResponse, resetForm: true}); 
        return false; 
    }); 
    $('#interestlistform').submit(function() { 
        $(this).ajaxSubmit({target: '#interests', beforeSubmit: showRequest, success: showResponse, resetForm: true}); 
        return false; 
    }); 
    $('#interestform').submit(function() { 
        $(this).ajaxSubmit({target: '#interests', beforeSubmit: showRequest, success: showResponse, resetForm: true}); 
        return false; 
    }); 
    $('#wishlistform').submit(function() { 
        $(this).ajaxSubmit({target: '#wishes', beforeSubmit: showRequest, success: showResponse, resetForm: true}); 
        return false; 
    }); 
    $('#wishform').submit(function() { 
        $(this).ajaxSubmit({target: '#wishes', beforeSubmit: showRequest, success: showResponse, resetForm: true}); 
        return false; 
    }); 
}); 
*/
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    var queryString = $.param(formData); 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	//
} 


function disableEnterKey(e){
	var key;     
	if(window.event)
		key = window.event.keyCode; //IE
	else
		key = e.which; //firefox     
	
	return (key != 13);
}
