function getFlashVersion(){
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { 
				axo.AllowScriptAccess = 'always';
			} catch(e) { return '6,0,0'; }
		} catch(e) {}
		
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
		// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}
	}
	
	return '0,0,0';
}
function setCookie( name, value, expires, path, domain, secure ) {
	// 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" : "" );
}
function getCookie( c_name ) {
	var i,x,y,ARRcookies=document.cookie.split(";");

	for (i=0;i<ARRcookies.length;i++) {
  		x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  		x = x.replace(/^\s+|\s+$/g,"");
	
		if (x == c_name) {
    		return unescape(y);
    	}
  	}
  	
  	return false;
}
function storeTimezone() {
	var now = new Date();		
	
	// Set cookie (in days) for the time zone offset in minutes
	setCookie("time_zone_offset", now.getTimezoneOffset(), 365, "/", "reshapethenation.com"); 
	
	// Create two new dates
	var d1 = new Date();
	var d2 = new Date(); 

	// Date one is set to January 1st of this year
	// Guaranteed not to be in DST for northern hemisphere,
	// and guaranteed to be in DST for southern hemisphere
	// (If DST exists on client PC)
	d1.setDate(1);
	d1.setMonth(1); 
	
	// Date two is set to July 1st of this year
	// Guaranteed to be in DST for northern hemisphere,
	// and guaranteed not to be in DST for southern hemisphere
	// (If DST exists on client PC)
	d2.setDate(1);
	d2.setMonth(7); 
	
	// If time zone offsets match, no DST exists for this time zone
	if (parseInt(d1.getTimezoneOffset(), 10) == parseInt(d2.getTimezoneOffset(), 10)) {
		setCookie("time_zone_dst", "0", 365, "/");
	} else { // DST exists for this time zone, check if it is currently active
		// Find out if we are on northern or southern hemisphere
		// Hemisphere is positive for northern, and negative for southern
		var hemisphere = parseInt(d1.getTimezoneOffset(), 10) - parseInt(d2.getTimezoneOffset(), 10); 
		
		// Current date is still before or after DST, not containing DST
		if ((hemisphere > 0 && parseInt(d1.getTimezoneOffset(), 10) == parseInt(now.getTimezoneOffset(), 10)) || (hemisphere < 0 && parseInt(d2.getTimezoneOffset(), 10) == parseInt(now.getTimezoneOffset(), 10))) {
			setCookie("time_zone_dst", "0", 365, "/");
		} else { // DST is active right now with the current date 
		 	setCookie("time_zone_dst", "1", 365, "/"); 
		} 
	}
}
function isUrl(s) {
	var regexp = (/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);
	return regexp.test(s);
}
function placeholder() {
	if (!Modernizr.input.placeholder) {
		$('[placeholder]').focus(function () {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
		}).blur(function () {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur();
		$('[placeholder]').parents('form').submit(function () {
			$(this).find('[placeholder]').each(function () {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			});
		});
	}
}	
function popBox(URL, width, height, title) {
	Shadowbox.open({
		player: 'iframe',
		content: URL,
		title: title,
		height: height,
		width: width,
		options: {
    		onOpen: function() {
    			$("#sb-body-inner iframe").attr("scrolling", "no");
    			if (typeof title !== "undefined") {
    				$("#sb-wrapper").attr('class', title.toLowerCase().replace(" ", "-"));
    			}	
			}
    	}
	});
}
function pop(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + "');");
}
/*
function popUPBlog(URL) {
	day = new Date();
	id = day.getTime();
	window.open(URL, "myWindow", "status = 1, height = 950, width = 600, resizable = 1,scrollbars=1");
}
*/
function isBox() {
	return (window.location != window.parent.location) ? true : false;
}

$(document).ready(function () {
	placeholder();
	if (typeof Shadowbox == 'object') {
		Shadowbox.init({
			overlayColor: '#FFF',
			language: 'en',
			players: ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'],
			width: 600,
			height: 260
		});
	}
	//classes used to close overlays or external window
	$('.close-btn, .close-sb, .close').click(function(e) {
		e.preventDefault();
		
		if (isBox() === true) {
			window.parent.Shadowbox.close();
		} else {
			window.close();
		}	
	});
	
	/*
$('a[rel=legal], a[rel=contact], a[rel=youtube]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 535, 640, $(this).attr('title'));
	});
*/

	$('a[rel=site]').click(function (e) {
		e.preventDefault();
		pop($(this).attr('href'), 510, 600);
	});
	$('a[rel=contact]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 508, 600, $(this).attr('title'));
	});
	$('a[rel=legal]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 535, 640, $(this).attr('title'));
	});
	$('a[rel="cs"]').click(function (e) {
		e.preventDefault();
		pop($(this).attr('href'), 650, 950);
	});
	$('a[rel="refer"]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 515, 450, $(this).attr('title'));
	});
	$('a[rel="faq"]').click(function (e) {
		e.preventDefault();
		pop($(this).attr('href'), 510, 650);
	});
	$('a[rel="stax"]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 775, 750, $(this).attr('title'));
	});
	$('a[rel="wrist-test"]').click(function (e) {
		e.preventDefault();
		popBox($(this).attr('href'), 620, 650, $(this).attr('title'));
	});
	
	$('#CountryCode').change(function() {
		$.post("/ajax/state-dropdown", {'type':$(this).val()}, function(data) {
			$('#StateCode').html(data);
		});
	});
	
	storeTimezone();
});
