/*
Some functions that are common between CRM and OSC
*/

function drawDiv( options ) {		
	try {		
		if( options['mode'] == "create" ) {
			try {
				document.body.removeChild( document.getElementById( options['id'] ) );
			}
			catch ( e ) {
			
			}
		
			// February 17, 2009 WSH // GREENWICH // FIRST CREATE A NEW DIV WITH THE SPECIFIED ID
			var tempDiv = document.createElement( "div" );
			tempDiv.setAttribute( "id", options['id'] );				
			document.body.appendChild( tempDiv );		
		}
		else if( options['mode'] == "update" ) {
			// Ferbruary 17, 2009 WSH // GREENWICH // IF NOT CREATING DIV, THEN DIV SHOULD ALREADY EXIST
		}			
		var tempContent = "";
		
		if( options['content'] ) {
			tempContent = options['content'];
			
			$( "#" + options['id'] ).html( tempContent );
			
			if( options['draw_close_button'] ) {
				var closeOutput = "";
				closeOutput += "<div style='width: 100%; text-align: right;'><img src='images_new/button_close.gif' id='close_" + options['id'] +"' style='cursor: pointer; float: right;'></div><br clear='all' />";
				
				var existingOutput = $( "#" + options['id'] ).html();
	
				$( "#" + options['id'] ).html( closeOutput + existingOutput );
				
				$( "#close_" + options['id'] ).click( function() {
					$( "#" + options['id'] ).hide();
				} );
			}
		}
		else if( options['content_url'] ) {
			$.get( options['content_url'], { name: "John", time: "2pm" }, 
				function( data ) { 
					var tempContent = data;
					var existingOutput = tempContent;
			
					$( "#" + options['id'] ).html( tempContent ); 

					// March 5, 2009 WSH // GREENWICH // ADDED ABILITY TO ONLY GRAB A SPECIFIC ELEMENT					
					if( options['element_id'] ) {
						$( "#" + options['id'] ).html( $( "#" + options['element_id'] ).html() );																			
						existingOutput = $( "#" + options['id'] ).html();
					}
					
					if( options['draw_close_button'] ) {
						var closeOutput = "";
						closeOutput += "<div style='width: 100%; text-align: right;'><img src='images_new/button_close.gif' id='close_" + options['id'] +"' style='cursor: pointer; float: right;'></div><br clear='all' />";												
			
						$( "#" + options['id'] ).html( closeOutput + existingOutput );
						
						$( "#close_" + options['id'] ).click( function() {
							$( "#" + options['id'] ).hide();
						} );
					}
				} 
			);
		}
		else {
			tempContent = "";
		}		
	
		if( options['class'] ) {
			$( "#" + options['id'] ).addClass( options['class'] );
		}
		
		
		if( options['width'] ) {
			$( "#" + options['id'] ).css( "width", options['width'] );
		}
		
		if( options['height'] ) {
			$( "#" + options['id'] ).css( "height", options['height'] );
		}
		
		if( options['x'] && options['y'] ) {
			$( "#" + options['id'] ).css( "position", "absolute" );
			$( "#" + options['id'] ).css( "top", options['y'] );
			$( "#" + options['id'] ).css( "left", options['x'] );
		}		
		
		// June 9, 2009 WSH // FOOPLUS // ADDED ABILITY TO SPECIFY REL FOR JQUERY LIGHTBOX
		if( options['rel'] ) {
			$( "#" + options['rel'] ).attr( "rel", options['rel'] );
		}											
	}
	catch ( e ) {
		alert( "drawDiv Exception" + e );
	}
}

// GET WIDTH AND HEIGHT OF WINDOW, ALL BROWSERS - http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var toReturn = new Array();
  
	toReturn['width'] = myWidth
	toReturn['height'] = myHeight  
  
	return toReturn;
}

function hideDiv( id ) {
	$('#' + id).hide();
}

var passcodes = new Array()
passcodes[0] = 'sohdy'
passcodes[1] = 'jvpiaaqn'
passcodes[2] = 'nokqrp'
passcodes[3] = 'wcjlc'
passcodes[4] = 'iaezzvq'
passcodes[5] = 'ypucqod'
passcodes[6] = 'iopcc'

function swapPass(theType) {
	
	var passcode = passcodes[Math.floor(Math.random()*passcodes.length)]

	//alert('Type of passcode is ' + theType + ' and passcode selected is ' + passcode);

	document.getElementById('passcode_img_' + theType).src = 'images_new/passcodes/' + passcode + '.jpg'

	document.getElementById('pc_valid_' + theType).value = passcode
	
	//alert('Value of pc_valid_' + theType + ' is set to ' + document.getElementById('pc_valid_' + theType).value)

}


