« April 2009 | Main | June 2009 »

May 29, 2009

Getting GET parameters with JavaScript and setting them in a cookie

var queryString = window.top.location.search.substring(1);

function getParameter ( queryString, parameterName ) {

	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";

	if ( queryString.length > 0 ) {

		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );

		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {

			// Add the length (integer) to the beginning
			begin += parameterName.length;

			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );

			if ( end == -1 ) {

				end = queryString.length

				}

			// Return the string
			return unescape ( queryString.substring ( begin, end ) );

			}

		// Return "null" if no parameter has been found
		return false;
		
		}
	}

function get_start_date(queryString){

	var start_date = getParameter(queryString, 'SQ_CALENDAR_DATE')

	if(start_date){ return start_date; }

	return false;

	}


function get_view(queryString){

	var view = getParameter(queryString, 'SQ_CALENDAR_VIEW')

	if(view){ return view; }

	return false;

	}

function create_cookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
        
        }

function read_cookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){   
                
                    //alert(c.substring(nameEQ.length,c.length));
                
                    return c.substring(nameEQ.length,c.length);
	
                    }
        
        }
	return false;
        }


//If we don't have a start date in the URL, try getting the cookie and if we have one redirect back to ourselves including the start_date in the URL

if(get_start_date(queryString) == false){

        var bicky = read_cookie('start_date');

        if(bicky != false){ document.location.href = document.location.href + '?SQ_CALENDAR_DATE=' + bicky; }

        }

//Otherwise we have a start date in the URL query so grab it and slot it into a cookie

else{ create_cookie('start_date', get_start_date(queryString), 1); }

//If we have called a day view then redirect us to the day view asset

if(get_view(queryString) == 'day'){ document.location = 'day'; }

if(get_view(queryString) == 'week'){ document.location = 'week'; }

if(get_view(queryString) == 'month'){ document.location = 'month'; }

//alert(read_cookie('start_date'));

Posted by pj at 09:54 PM | Comments (0)

Get query string with JS

Using JavaScript to get the Query_String from a frameset (Page 2)

Posted by pj at 12:47 PM | Comments (0)

Speed Test

Broadband Speed test

Posted by pj at 08:31 AM | Comments (0)

May 26, 2009

MySource Matrix Keywords

Matrix Secrets - Keywords

Posted by pj at 09:38 AM | Comments (0)

May 21, 2009

Create a new asset in MySource Matrix

MySource Matrix Open Source CMS - Introduction

Posted by pj at 04:29 PM | Comments (0)

Example: Loading binary image files into a PostgreSQL OID (blob)

Large Objects (BLOBs)

Posted by pj at 02:22 PM | Comments (0)

Adding MySQL-like date functions with custom functions in PostgreSQL

How to add unix_timestamp() and from_unixtime() to PostgreSQL?

Posted by pj at 10:17 AM | Comments (0)

May 17, 2009

Cycle routes in Edinburgh

Cycling Routes and Cycle Trails in Edinburgh & The Lothians - Cycling Scotland

Posted by pj at 01:17 PM | Comments (0)

May 16, 2009

Mac PHP Postgres Bundle

BitNami :: MAPPStack

Posted by pj at 10:36 PM | Comments (0)

May 12, 2009

Mac Cufflinks

Handmade Geekery on Etsy - mac daddy cufflinks by pixelparty

Posted by pj at 12:25 AM | Comments (0)