﻿//Initialization-----------------------------------------------------------------------
Event.observe(window,'load',init,false);
function init() { 
	$$('table.stripe tr:nth-child(odd)').invoke('addClassName','stripe');
	if($('aspForm')) {
		var valid = new Validation('aspForm', {immediate : true, useTitles: true, 
															 onFormValidate: submitForm});
	}
}

//Form Submit Button Handling-----------------------------------------------------------
function submitForm(result,form) {
	if(result) {
		var submitBtn = $(form).down('input[type=submit]');
		submitBtn.value = "Loading...";
		submitBtn.disabled = true;
	}
}

//Check Function------------------------------------------------------------------------
function checkGroup(className, checked) {
	$$('.'+className+' input[type="checkbox"]').each(function(n) { n.checked = checked; });
}


//Tell Friend Validate-------------------------------------------------------------------
function tellFriendValidate() {
  new Validation('aspnetForm', {immediate : true});
}

//Javascript Confirm Delete--------------------------------------------------------------
function linkTo(ref,conf,url) {
	if(!conf)
		window.location = url;
	if(conf && confirm(conf))
		window.location = url;
	ref.blur();
	return false;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function getCookie( 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 setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	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() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

Event.observe(window,'load',automateSWF,false);
function automateSWF() { 
  if(navigator.appVersion.match(/\bMSIE\b/) && $$('embed').length > 0) {
    var i = 0;
    $$('embed').each(function(n) {
      var n = $(n);
      source = n.src;
      height = !n.height ? n.getHeight() : n.height;
      width = !n.width ? n.getWidth() : n.width;
      var id = n.src.replace(" ","").replace(".","-") + "-" + i;
      new Insertion.After(n,'<span id="' + id + '">...</span>');
      Element.remove(n);
      so = new FlashObject(source, id, width, height,"6");
      so.write(id);
      i++;
    });
  }
}