// JavaScript Document
			 var query ='';		
 			var endUserEmail = '';	
			var error='';
					 
					//show messages and processing to user
					function myAlert(show, heading, message, processing, disable) {
					 var curURL = window.location.hash;
						 document.getElementById("myAlertHead").innerHTML = heading;
						 document.getElementById("myAlertContent").innerHTML = message;
						 
						
						if(processing == 1){
							$("#proccessing_swf").css("visibility", "visible");
						 
						}else{
							$("#proccessing_swf").css("visibility", "hidden");
						} 
						 
						if (show == 1) {
						// Show popup
							document.getElementById('myAlertDiv').style.visibility = 'visible';
							document.getElementById('myAlertDiv').style.display = 'block';
							document.getElementById('closeMyAlert').style.visibility = 'visible';
							document.getElementById('closeMyAlert').style.display = 'block';
							document.getElementById('blackout').style.visibility = 'visible';
							document.getElementById('blackout').style.display = 'block';
							
						} else {
						// Hide popup
							document.getElementById('blackout').style.visibility = 'hidden';
							document.getElementById('myAlertDiv').style.visibility = 'hidden';
							document.getElementById('blackout').style.display = 'none';
							document.getElementById('myAlertDiv').style.display = 'none';
							document.getElementById('processingSwf').style.visibility = 'hidden';
							document.getElementById('processingSwf').style.display = 'none';
						}
						
						if(curURL.indexOf(".php") == -1){
							 
						}else{
							window.location.hash =curURL;
						}
						
						
						if(disable == "true"){
							
							$("#blackout").click(function(){
								//alert("yep");						  
							 return false;
							});
							
							$("#closeMyAlert").click(function(){
														  
							 return false;
							});
						}else{
							$("#blackout").click(function(){
								myAlert(0,0 ,0 ,0);	
							});
							
							$("#closeMyAlert").click(function(){
														  
							myAlert(0,0 ,0 ,0);	
							});
						
						}
					}
					 
					 
					 
					 
					function validateEmail(elementValue){  
    					var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
   						return emailPattern.test(elementValue);  
   					}  


					function setError(_error){
						 //alert("set Email :" + _error);
						 error=_error;
						 
					}
					function setEmail(_endUserEmail){	
						//	alert("set Email :" + _endUserEmail);
						 endUserEmail = _endUserEmail;	
					}
					
					function setQuery(_query, _endUserEmail){
						query = _query;	
						endUserEmail= _endUserEmail;
						//alert("query : " +query);
					}
					 function manualCheckout(){
						 document.getElementById('flashapp').manualCheckout(); 
					 }
					 
					 function openPaymentWin(){
						//alert('got here');
						 
						
							var width  = 800;
							var height = 650;
							 var left   = (screen.width  - width)/2;
							 var top    = (screen.height - height)/2;
							 var params = 'width='+width+', height='+height;
							 params += ', top='+top+', left='+left;
							 params += ', directories=no';
							 params += ', location=no';
							 params += ', menubar=no';
							 params += ', resizable=yes';
							 params += ', scrollbars=yes';
							 params += ', status=yes';
							params += ', toolbar=no'; 
							
								 
							if(!validateEmail(endUserEmail) ||  endUserEmail == ''){
								
								alert(error +  " : " + endUserEmail);
							}else{
								
								if(query != ''){
									paymentWin = open('php/PupCheckout.php'+query,'_payment_win', params);
									document.getElementById('flashapp').proceedingCheckout();
									disableFinishBtn();
								}else{
										alert("Sorry there was an error. Please try again or contact support at support@baktrack.com.");
								} 
								
							}
							
						} 
	
	
	function setCheckOutBtnPos(){
		 
		 $("#popUpContent").css('position', 'absolute'); 
                                var left = ($(window).width() - $("#popUpContent").outerWidth())/2+$(window).scrollLeft();
                             
                                 $("#popUpContent").css('left', left+"px");
		 //$("#popUpContent").center();
		/*
		
		
		if($.browser.msie){
			$("#topMid").css('width', "50px"); 
			
			alert(" ie w : " + $("#topMid").css('width') );
		}else{
			
			var width = $(window).width();
			
			width = width - ($("#logoTop").width() + $("#topRght").width());
			
			$("#topMid").css('width', width + "px");
			
				alert(" ff w : " + $("#topMid").css('width') );
		}
		
		*/
			var width = $(window).width();
			//alert("width : " + width);
		width = width - ($("#logoTop").width() + $("#topRght").width());
			//alert("width : " + width);
		
		
		
		 if($.browser.msie){
		 		$("#blackout").center()
			  $("#myAlertDiv").center();
			  
		   if($(window).width() >= 1300){
				//$("#topMid").css('width', width + "px");
			//	$("#header").css('width', $(window).width() + "px");
				}else{
				//		$("#topMid").css('width', "498px");
				 	$("#header").css('width', "1300px");
				}  
			
		 }else{
			if(width > 520){
			//$("#topMid").css('width', width + "px");
			}else{
				//	$("#topMid").css('width', "520px");
			} 
			 
		 
		 }
		
		
		//alert(document.body.clientHeight);
		var x = $("#finishPlcHldr").offset().left - 93;	
		var y = $("#finishPlcHldr").offset().top;
		
		var ie6Val = document.getElementById("finishPlcHldr").offsetLeft + document.getElementById("finishPlcHldr").offsetParent.offsetLeft;
		var topPs =  y;
		
		
		//alert(y);
		
		
		if($.browser.msie /*&& Number(jQuery.browser.version.split(".")[0]) < 7*/){
			 var leftps =  (ie6Val + 40) + 'px' ;
				topPs = topPs + 20;
		}else if($.browser.safari){
			 var leftps = (x -94) + 'px' ; 
			 
			 
		 }else{
			 var leftps = x + 'px' ; 
		 }
		  
		 topPs = topPs + "px";
			 $("#finishBtnImg").css("left", String(leftps));
		 	$("#finishBtnImg").css("top", String(topPs));
		 
				
				if(document.body.clientWidth < 900){
					   
				//	$('#shell').css('width', '900px'); 
					  
				}else{
					 $('#shell').css('width', '100%');   
					 
				}  
				
				if(document.body.clientHeight < 1055){
					   
				//	$('#footer').css('top', '1055px'); 
					  
				}else{
				//	$('#footer').css('top', ''); 
				//	 $('#footer').css('bottom', '0%');   
					 
				}  
				
				var linksLeft=	(document.body.clientWidth  * 1600) / 1920;
			 
			if(document.body.clientWidth > 1300){
				$("#right").css('padding-left', linksLeft+"px");
			}else{
				$("#right").css('padding-left', "1100px");
			}
			
			var navLeft = $("#mainnav").offset().left + popUpBorder;
$("#popUpContent").css("left", navLeft); 
					
	}
						function enableFinishBtn(){
							document.getElementById("finishHldr").style.display = "block";	
							setCheckOutBtnPos();
							
							
							 document.getElementById("finishBtnImg").style.visibility = "visible";	
							
						}
						 
						function disableFinishBtn(){
						 		 document.getElementById("finishBtnImg").style.visibility = "hidden";	
								 
						}

function generatePass(){

		  // start with a blank password
		 var  $password = "";
		var nums = new Array();
		 var length = 15
		  // define possible characters
		 var  possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ"; 
			
		  // set up a counter
		  var i = 0; 
			
		  // add random characters to $password until $length is reached
		  while (i < length) { 

			// pick a random character from the possible ones 
			 var index = Math.random() * ($length - 1);
			
			 if(!Util.arrayContainsValue(nums, index)){
			  var char = $possible.substr(index, 1)
			  password += $char;
			  i++;
			  nums.push(index)
			 }

		  }

		  // done!
		  return $password;

		}


function removeUnderscore(txtFile) {
			 var myPattern = /_/g;   
			return txtFile.replace(myPattern, " "); 
}

