//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
function GoToForm( url )
{
	window.location	= url;
}

function makeFlash(swf,w,h,bg) {
	document.write("<center><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"" + w + "\" height=\"" + h + "\" id=\"pr\" align=\"middle\">")
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />")
	document.write("<param name=\"movie\" value=\"" + swf + "\" />")
	document.write("<param name=\"quality\" value=\"high\" />")
	document.write("<param name=\"bgcolor\" value=\"" + bg + "\" />")
	document.write("<embed src=\"" + swf + "\" quality=\"high\" bgcolor=\"" + bg + "\" width=\"" + w + "\" height=\"" + h + "\" name=\"pr\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />")
	document.write("</object></center>")
}



// browser compatibility
function compatibility(id)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		return document.getElementById(id)
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		return document.all[id]
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		return document.layers[id]
	}
}

// skipvid() is called by the ff and fr buttons in the video player
function skipvid(i)
{
	skip = nowplaying * 1 + i * 1;
	
	if (p_items[skip])
	{
		portfolio(skip)
	}
	else if (skip > 0)
	{
		portfolio(0)
	}
}


// portfolio() is called by the item thumbnail links
function portfolio(i,mute)
{
	// keep track of which is playing
	nowplaying = i;

	if (p_items[i])
	{

		if (mute == true)
		{
			doPortfolio(p_items[i][0],p_items[i][1],p_items[i][2],p_items[i][3],p_items[i][4],true)
		}
		else
		{
			doPortfolio(p_items[i][0],p_items[i][1],p_items[i][2],p_items[i][3],p_items[i][4],false)
		}
	}
	else
	{
		alert("item not found")
	}

}


// make all page changes from the file info
function doPortfolio(id,format,file,w,h,mute)
{
	// scale item to not break layout
	if (w && w>320)
	{
		r = 320/w
		w = 320
		h = Math.round( h * r )
	}

	// hide and show item info and thumbnail css class
	for (p_item in p_items)
	{
		var articleid = p_items[p_item][0]
		
		var info = compatibility('portfolio-item-info-' + articleid)
		var thumb = compatibility('thumb-' + articleid)

		// hide and show info
		if (info)
		{
			if (p_item == nowplaying)
			{
				info.style.display = "block"
			}
			else
			{
				info.style.display = "none"
			}
		}

		// change thumbnail class
		if (thumb)
		{
			if (p_item == nowplaying)
			{
				thumb.className = "active"
			}
			else
			{
				thumb.className = ""
			}
		}
	}
	// display item
	if (file!='')
	{
		if (format=='13')
		{
			
			// -=-=-=- swf -=-=-=-
			var so = new SWFObject(file,'portfolio-item',w,h,'6','')
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.addParam("scale", "noscale")
			so.write('portfolio-viewer')
		}
		else if (format!='')
		{
			// -=-=-=- image -=-=-=-
			var viewer = compatibility('portfolio-viewer')
			viewer.innerHTML = '<img id="viewer-img" src="' + file + '" width="' + w + '" height="' + h + '" >'
		}
		else
		{
			// -=-=-=- flv/mp3 -=-=-=-
			var so = new SWFObject('/video/player_320x240.swf?autoPlay=false&mute='+mute+'&content_path='+file,'portfolio-item','320','270','8','')			
			so.addParam("wmode", "transparent")
			so.addParam("allowScriptAccess", "sameDomain")
			so.addParam("menu", "false")
			so.addParam("quality", "high")
			so.addParam("scale", "noscale")
				

			
			so.write('portfolio-viewer')
		}
	}
	else
	{
		// -=-=-=- no file -=-=-=-
		//var viewer = compatibility('portfolio-viewer')
		//viewer.innerHTML = '&nbsp;'
	}
}


// make all page changes from the file info
function doPlayer(id,file,w,h,mute)
{
	// scale item to not break layout
	if (w && w>320)
	{
		r = 320/w
		w = 320
		h = Math.round( h * r )
	}
	
	// display item
	if (file!='')
	{
		// -=-=-=- flv/mp3 -=-=-=-
		var so = new SWFObject('/video/player_320x240.swf?mute='+mute+'&content_path='+file,'video_'+id,'320','270','8','')			
		so.addParam("wmode", "transparent")
		so.addParam("allowScriptAccess", "sameDomain")
		so.addParam("menu", "false")
		so.addParam("quality", "high")
		so.addParam("scale", "noscale")
		
		so.write(id)
	}
	else
	{
		// -=-=-=- no file -=-=-=-
		//var viewer = compatibility('portfolio-viewer')
		//viewer.innerHTML = '&nbsp;'
	}
}






/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

//*********************************************************************************************************
//	Function: openPopup()
//
//*********************************************************************************************************
function openPopupWindow(content,target,sizeX,sizeY)
{
	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

	//	Define the window size
	widthVar  = 'width=' + sizeX + ',';
	heightVar = 'height=' + sizeY + ',';
	
	//	Open the window
	winobject				= window.open(content,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0," + widthVar + heightVar + "left=" + leftpos + ",top=" + toppos + ",resizable=1" );
	winobject.focus();
}

//*********************************************************************************************************
//	Functions for image gallery
//*********************************************************************************************************
function next_image()
{
	if(current_img >= total_images )
	{
		current_img	= 	1;	
	}
	else
	{
		current_img	++;
	}

	img		=	'image_' + current_img;

	show_image(img);

}

function prev_image()
{
	


	if(current_img == 1)
	{
		current_img	= 	total_images ;	
	}
	else
	{
		current_img	--;
	}

	img		=	'image_' + current_img;

	show_image(img);
}
//*********************************************************************************************************
//	End Functions for image gallery
//*********************************************************************************************************

function check_payment_type()
{

	form = document.details;

	var m = form["fields[Check or Money Order]"]
	var p = form["fields[Paypal]"];
	if( m.checked || p.checked )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function check_registration_payment_type()
{

	form = document.details;
	rb = form["fields[Payment Type]"];
	rbc = 0;
	for (var i=0; i<rb.length; i++)
	{
		if ( rb[i].checked )
		{
			rbc++;
		}
	}
	var s = form["fields[Will Send Proof Of Military Disability]"];

	if( s.checked)
	{
		rbc++;
		//var pa  = form["fields[Payment Type]"];
		
	}

	if ( rbc == 0 )
	{
		alert("Payment Type is required.");
		return false;
	}
	else
	{
		return true;
	}


}

function add_war_dog_relation()
{
	war_dog_table =  document.getElementById('war_dog_relations');
	
	war_dog_table.append();
}

function add_upload_row()
{
	if(current_img_row_value >= 10)
	{
		alert('Limit Exceeded');
		return;
	}
	
	document.getElementById('image_row_'+current_img_row_value).style.display = '';
	current_img_row_value++;
}


function fadetext(){ 
	if( b > 19 ) 
	{	//If color is not dark brown yet
		var add = 5; 
		r -= add;
		g -= add;
		b -= add;
		
		hex-=11; // increase color darkness
		document.getElementById("rotating_quote").style.color="rgb("+r+","+g+","+b+")";
		setTimeout("fadetext()",350); 
		
	}
	else
	{
		r     = 236; 
		g     = 197; 
		b     = 159;

		current += 1; 
		if( current > total)
		{
			current = 1;
		}

		document.getElementById("rotating_quote").innerHTML = unescape(fadetext_array[current]);
		fadetext(); 

	}
}

// debug func to show props of obj
function  printProps(obj, objName) {
  var output = "" ;
  for (var prop in obj) {
    output += objName + "." + prop + " = " + obj[prop] + "\n" ;
  }
  return output ;
}

// func to show / hide obj
function expand(param)
{
		param.style.display=(param.style.display=="none")?"block":"none";
}

function expand_by_id(id)
{
	expand(document.getElementById(id));
}

//#########################################################################################################
//
//	Public AJAX functions
//
//#########################################################################################################

//---------------------------------------------------------------------------------------------------------
//	Load an object dynamiclly with a source page
//---------------------------------------------------------------------------------------------------------
function loadDivContents( url, div )
{
	objNumber = 0;

	//	Have we used the div object before?
	for( i=1; i<= HTTPObjects.length; i++ )
	{
		if (HTTPObjects[i] == div)
		{
			objNumber = i
		}
	}

	//	Not found?
	if(!objNumber)
	{
		objNumber				= HTTPObjects.length;
		HTTPObjects[objNumber]	= div;
	}

	//	Generate the div object pointer
	var divObj = eval( 'document.getElementById("' + div + '");' );

	eval( 'http' + objNumber + ' = initHTTPObject();' );
	eval( 'if (!http' + objNumber + '){window.location=\'/site/compatability.php\';}' );
	eval( 'http' + objNumber + '.open("GET", url, true );');
	eval( 'http' + objNumber + '.onreadystatechange = function() { if (http' + objNumber + '.readyState == 4) {divObj.innerHTML = http' + objNumber + '.responseText;}};');
	eval( 'http' + objNumber + '.send(null);');
}

//#########################################################################################################
//
//	Private AJAX functions
//
//#########################################################################################################

//--------------------------------------------------------------------------------------------------------
//	Define the elements
//---------------------------------------------------------------------------------------------------------
var HTTPObjects = Array();	//	Track all the used HTTP objects on the page
var objNumber   = null;

//---------------------------------------------------------------------------------------------------------
//	Initialize a new HTTP object
//	PRIVATE
//---------------------------------------------------------------------------------------------------------

function initHTTPObject() 
{
	var xmlhttp;
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
 	 	try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
			xmlhttp = false;
 		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
  			xmlhttp = new XMLHttpRequest();
		} catch (e) {
  			xmlhttp = false;
		}
	}
	return xmlhttp;
}


// init stuff...
img_array = new Array();

function check_payment()
{
	form = document.contactus;

	if(form["fields[act]"].value == 'cant_renew')
	{
		rb = form["fields[Payment Type]"];
		rbc = 0;
		for (var i=0; i<rb.length; i++)
		{
			if ( rb[i].checked )
			{
				rbc++;
			}
		}

		if ( rbc == 0 )
		{
			alert("Payment Type is required.");
			return false;
		}
	}
	else
	{
		control = form["fields[Contact]"];
		dropdown = control.options;
		dropdown_value	= dropdown[dropdown.selectedIndex].value;
		if ( dropdown_value == "" )
		{
			alert("Contact is required.");
			control.focus();
			return false;
		}
	}

	return true;

}