var requester;
	   function createPlayer()
      {
        var s1 = new SWFObject('/ShowBinary?nodePath=<%=nodePath%>', '', '100%', '100%', '9', '#FFFFFF');
          
            s1.write('preview');
      } 
	
	
	function dispatchClickLinkEvent(link) {
		 
		if (requester != null && requester.readyState != 0 && requester.readyState != 4)
		{
			requester.abort();
		}
		
		if (window.XMLHttpRequest) // for other browsers 
		{
			requester = new XMLHttpRequest();
			//alert("Mozilla");
			if (requester.overrideMimeType) {
				requester.overrideMimeType('text/xml');
			}			
		}
		else if (window.ActiveXObject) // for IE
		{ 
				requester = new ActiveXObject("Microsoft.XMLHTTP");
				//alert("IE");						
		}
		
		var url = '/sendClickLinkEvent?link='+link;
		requester.open("GET", url, true);
		requester.onreadystatechange = function() {done(); };
		requester.send(null);
		
		return true;
	}	
	
	
  function done() {
		
		//alert("readyState: " + requester.readyState);
		if (requester.readyState == 4)
    	{
    		//alert("inside status: " + requester.status);
        	if(requester.status == 200)
        	{				
            	//process the response
            	//get the XML send by the servlet
                var profileXML = requester.responseXML.getElementsByTagName("event")[0];
                 //alert(" event xml" + profileXML); 
        	}
        	else
        	{
            	// alert("Error sending event\n"+ requester.status +":"+ requester.statusText);
        	}
    	}   
	}
	
	
	
	
	
	 
	
function toggleBox(szDivID, iState,hidedivs) // 1 visible, 0 hidden
{
 var browser=navigator.appName;
 var b_version=navigator.appVersion;
  
 
  
    if(document.layers)	   //NN4+
    {
       
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
      
        var obj = document.getElementById(szDivID);
        if (browser == 'Netscape' || IsIE8Browser() )
         obj.style.position = "relative";
        
        obj.style.visibility = iState ? "visible" : "hidden";
      
        
        splitdivs = hidedivs.split(',');
       
         for (i=0;i<splitdivs.length;i++) {
        
          var obj2= document.getElementById(splitdivs[i]);
           obj2.style.visibility =  "hidden";
          obj2.style.position="absolute";
 
        }  
        
        
    
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function IsIE8Browser() {
    var rv = -1; 
       var ua = navigator.userAgent;   
        var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");  
          if (re.exec(ua) != null) 
          { 
                 rv = parseFloat(RegExp.$1);  
          
            }  
    return (rv == 4);
    
    }

function  getContent(nodeId,document) {
		//alert(nodeId);
		//alert('document:'+document);
		 
		
		 
		 var fileName = document.substring(document.lastIndexOf('/')+1);
		
	 	   if (fileName == 'null' ) {
				alert('No document has been uploaded yet');
				return;
			}
		
		 // alert('fileName:'+fileName)
		 var path = '/DownloadBinaryServlet?nodeId='+nodeId+'&propertyId='+nodeId+'/Upload&fileName='+fileName
		  
		  //alert(path);
		 
		  
		  window.status = 'downloading';
		  window.location =  path;
	  }
	  
	  function clearstatusbar() {

 		window.status= 'download content';
 
	  }
	  
	  function ____viewInSeparateWindow( nodepath,document,docid,pageName )
		{
		
			var fileName = document.substring(document.lastIndexOf('/')+1);
		
	 	   if (fileName == 'null' ) {
				alert('No document has been uploaded yet');
				return;
			}
		
   			window.open('/viewcontent.jsp?nodepath='+nodepath+'&docid='+docid+'&fileName='+fileName+'&pageName='+pageName,'',"menubar=no,location:yes;status:no;url:no;dialogWidth:1024px;dialogHeight:768px%;dialogHide:true;scroll:no;");
 	 
}

function viewInSeparateWindow(pageName )
		{
		
			 
 
		
   			window.open('/viewdocument/'+pageName,'',"menubar=no,location:yes;status:no;url:no;dialogWidth:1024px;dialogHeight:768px%;dialogHide:true;scroll:no;");
 	 
}


function viewVideoInSeparateWindow(videoName,w,h )
		{
	 
		 var newlink = "'/viewvideo/"+videoName+"'";
		 var name  = "'video'";
		 //var widthheight = 'width='+w+',height='+h;
			 var widthheight = 'width=570,height='+h;
 
		//'width=560,height=331'
   			window.open('/viewvideo/'+videoName,'video',widthheight);
 	 
}

      
function showhide(id){

//var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
//alert(sPage);



	if (document.getElementById){
		obj = document.getElementById(id);
	if (obj.style.display == "none"){
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
  }
}
	
function tracklink(obj,pagelabel,windowtitle,windowid) {
	 //alert(pagelabel+'|'+windowtitle+'|'+windowid);
	

	var link = 'type=portlet|pagename='+pagelabel+'|windowtitle='+windowtitle+'|windowID='+windowid+'|link='+obj.href;
    var link = link.replace('.html','');
 if (requester != null && requester.readyState != 0 && requester.readyState != 4)
		{
			requester.abort();
		}
		
		if (window.XMLHttpRequest) // for other browsers 
		{
			requester = new XMLHttpRequest();
			//alert("Mozilla");
			if (requester.overrideMimeType) {
				requester.overrideMimeType('text/xml');
			}			
		}
		else if (window.ActiveXObject) // for IE
		{ 
				requester = new ActiveXObject("Microsoft.XMLHTTP");
				//alert("IE");						
		}
		
		var url = '/sendClickLinkEvent?link='+link;
		// alert(url);
		requester.open("GET", url, true);
		requester.onreadystatechange = function() {done(); };
		requester.send(null);
		
	 
	
		if (obj.href == undefined ) {
	 alert('undefined');
	 
	} else {
		window.location  = obj.href;
	 }
	return false;
}	

// form validation function //
function validate(form) {
	 
  var companyname = form.companyname.value;
  var contactname = form.contactname.value;
  var address1 = form.address1.value;
  var address2 = form.address2.value;
  var city = form.city.value;
  var state = form.state.value;
  var zipcode = form.zipcode.value;
  var phone1 = form.phone1.value;
    var email = form.email.value;
  var operatingsince = form.operatingsince.value;
   var typebusiness = form.typebusiness.value;
   var ygsales = form.ygsales.value;
   var mvisasales = form.mvisasales.value;
     var hearaboutus = form.hearaboutus.value;
     var cashusage = form.cashusage.value;
     
 var dateXReg = /^\d{4}-\d{2}-\d{2}$/ 

 
  var txtRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
   var numRegex = /^[0-9]+$/;
   var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  var operatingsinceRegEx = /^\d{2}-\d{4}$/;
  
  if(companyname == "") {
    inlineMsg('companyname','You must enter your company name.',2);
    return false;
  }
  if(!companyname.match(txtRegex)) {
    inlineMsg('companyname','You have entered an invalid company name.',2);
    return false;
  }
  
  
    if(contactname == "") {
    inlineMsg('contactname','You must enter the contact name.',2);
    return false;
  }
  if(!contactname.match(txtRegex)) {
    inlineMsg('contactname','You have entered an invalid contact name.',2);
    return false;
  }
  
  if(address1 == "") {
    inlineMsg('address1','You must enter the address.',2);
    return false;
  }
 
  
    if(city == "") {
    inlineMsg('city','You must enter the city.',2);
    return false;
  }
  if(!city.match(txtRegex)) {
    inlineMsg('city','You have entered an invalid city.',2);
    return false;
  }
  
  if(state == "0") {
    inlineMsg('state','Please select the state.',2);
    return false;
  }
  
  if(zipcode == "") {
    inlineMsg('zipcode','Please enter your zip code.',2);
    return false;
  }
 
   if(!zipcode.match(numRegex)) {
    inlineMsg('zipcode','You have entered an invalid zip code.',2);
    return false;
  }
 
   if(phone1 == "") {
    inlineMsg('phone1','Please enter your phone number.',2);
    return false;
  }
 
 
  
  if(email == "") {
    inlineMsg('email','You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','You have entered an invalid email.',2);
    return false;
  }
 
 
 
 
  if(operatingsince == "") {
    inlineMsg('operatingsince','Please enter the date you began operations.',2);
    return false;
  }
 
   if(!operatingsince.match(operatingsinceRegEx)) {
    inlineMsg('operatingsince','You have entered an invalid date.',2);
    return false;
  }
  
  
    if(typebusiness == "0") {
    inlineMsg('typebusiness','Please select your Business Type.',2);
    return false;
  }
  
  
   if(ygsales == "0") {
    inlineMsg('ygsales','Please select your Yearly Gross Sales.',2);
    return false;
  }
  
 
   if(mvisasales == "0") {
    inlineMsg('mvisasales','Please select your Monthly VISA/MC.',2);
    return false;
  }
  
   if(cashusage == "0") {
    inlineMsg('cashusage','Please tell us the cash usage.',2);
    return false;
  }
  
     if(hearaboutus  == "0") {
    inlineMsg('hearaboutus','Please tell us how you heard about us.',2);
    return false;
  }
 
  return true;
}


function validatecus(form) {

 var firstName = form.firstName.value;
 var lastName = form.lastName.value;
 var email  = form.email.value;
 var companyName = form.companyName.value;
 var merchantID = form.merchantID.value;
 
  var txtRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var numRegex = /^[0-9]+$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
 if(firstName == "") {
    inlineMsg('firstName','You must enter your firstname.',2);
    return false;
  }
  if(!firstName.match(txtRegex)) {
    inlineMsg('firstName','You have entered an invalid  firstname.',2);
    return false;
  }
  
   if(lastName == "") {
    inlineMsg('lastName','You must enter your lastname.',2);
    return false;
  }
  if(!lastName.match(txtRegex)) {
    inlineMsg('lastName','You have entered an invalid lastname.',2);
    return false;
  }
  
   if(email == "") {
    inlineMsg('email','You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','You have entered an invalid email.',2);
    return false;
  }

  return true;

}



function validatecareers(form) {

 var firstName = form.firstName.value;
 var lastName = form.lastName.value;
 var email  = form.email.value;
 var fileUpload = form.fileUpload.value;
 
  var txtRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var numRegex = /^[0-9]+$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
 if(firstName == "") {
    inlineMsg('firstName','You must enter your firstname.',2);
    return false;
  }
  if(!firstName.match(txtRegex)) {
    inlineMsg('firstName','You have entered an invalid  firstname.',2);
    return false;
  }
  
   if(lastName == "") {
    inlineMsg('lastName','You must enter your lastname.',2);
    return false;
  }
  if(!lastName.match(txtRegex)) {
    inlineMsg('lastName','You have entered an invalid lastname.',2);
    return false;
  }
  
   if(email == "") {
    inlineMsg('email','You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','You have entered an invalid email.',2);
    return false;
  }

 if(fileUpload == "") {
    inlineMsg('fileUpload','You must attach your work history ( resume ).',2);
    return false;
  }

 

  return true;

}



function validatesales(form) {

 var sfirstName = form.sfirstName.value;
 var slastName = form.slastName.value;
 var semail  = form.semail.value;
  
 
  var txtRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var numRegex = /^[0-9]+$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
 if(sfirstName == "") {
    inlineMsg('sfirstName','You must enter your firstname.',2);
    return false;
  }
  if(!sfirstName.match(txtRegex)) {
    inlineMsg('sfirstName','You have entered an invalid  firstname.',2);
    return false;
  }
  
   if(slastName == "") {
    inlineMsg('slastName','You must enter your lastname.',2);
    return false;
  }
  if(!slastName.match(txtRegex)) {
    inlineMsg('slastName','You have entered an invalid lastname.',2);
    return false;
  }
  
   if(semail == "") {
    inlineMsg('semail','You must enter your email.',2);
    return false;
  }
  if(!semail.match(emailRegex)) {
    inlineMsg('semail','You have entered an invalid email.',2);
    return false;
  }

  return true;

}


// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  msg.style.fontsize = '8px';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "/images/msg_arrow.gif"; 
}
	
	
	