//--------------------------------------------------------------------------------------------------------------------------//
// For Data collection
var headline		= new Array() ;
var lastArray  		= ["last","last_name" , "lastname" , "lastn" ,"last_n" , "fields_lname" , "family_name" ,"surname" ];
var firstArray 		= ["first","name","first_name","firstname","firstn" , "first_n" , "fields_fname"];
var addressArray 	= ["address","address1", "address_1", "street_address","street_address1" ,"fields_address1", "address-1"];
var cityArray 		= ["city", "town", "town_or_city" ,"fields_city", "state-city"];
var stateArray 		= ["state", "state_or_county" ,"fields_state"];
var countryArray 	= ["country"];
var countyArray 	= ["county"];
var zipArray 		= ["zip","zipcode","postcode","zip_code", "zip_or_postcode","post_code","postal_code" ,"fields_zip" ,"post_code-zip"];
var emailArray 		= ["email","emailaddress","from" ,"fields_email"];
var phoneArray 		= ["phone","telephone","phonenum", "phone_number" , "Phone_Number","fields_phone" ,"ph", "telephone_number" ];
var businessArray 	= ["business", "business_name"];
var faxArray 		= ["fax"];
var companyArray 	= ["company"];

var clientIDArray	= ["client_id"];
var campaignIDArray	= ["campaign_id"];
var programIDArray	= ["program_id"];
var nicheIDArray	= ["niche_id"];
var teamIDArray		= ["team_id"];
var memberIDArray	= ["member_id"];
var autoTypeArray	= ["auto_type"];

var excludeArray	= ["hidden","reset","submit"];
var adsource        = urlparameter("target") ;
var campaign        = urlparameter("campaign") ;
var adgroup         = urlparameter("adgroup") ;
var keyword         = urlparameter("keyword") ;
var leadtype        = urlparameter("leadtype") ;
var clickbank       = urlparameter("clickbank") ;
var hop		       	= urlparameter("hop") ;
var sponsor_id     	= urlparameter("sponsor") ;
var verifyFields    = true ;

if ( typeof blogForm == "undefined" ) {
	var blogForm  	= false ;
}

var domain     		= 'http://advancedleadgeneration.com' ;
var leadtype        = "LEAD" ;
//var domain     = 'http://74.53.24.242/~palger' ;
var initFrame  	= domain + '/leadpage_templates/blank.htm' ;
var adleadURL  	= domain + '/common/addleadUpdateN.php' ;
var adclickURL 	= domain + '/common/recordclick.php' ;
var adClientURL = domain + '/common/addClient.php' ;
var adMemberURL = domain + '/common/addMember.php' ;

if ( typeof current_unique_id == "undefined" ) {
	var unique_id  	= unique_id() ;
} else {
	var unique_id  	= current_unique_id ;
}

// alert("Start ID "  + unique_id )  ;

var errorPage = "http://advancedleadgeneration.com/missingvalue.htm" ;
var leadPageID = 0 ;

var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

leadPageID = urlparameter("id") ;

//Time in days to save form fields values after last visit
//Set to different value to reset cookie (ie: "101 days" instead of "100 days"):
var memoryduration="100 days" ;
var memorizearray = new Array() ;

window.onerror = handleErr ;

//--------------------------------------------------------------------------------------------------------------------------//
  function submitMyForm( form ) {
//--------------------------------------------------------------------------------------------------------------------------//  
	if ( captureForm( form ) != false ) {
		document.forms[0].submit() ;
	}
  }


//--------------------------------------------------------------------------------------------------------------------------//
function displayURLData( saveURL ) {
//--------------------------------------------------------------------------------------------------------------------------//
	document.forms[0].saveurl.value = saveURL ;
	alert("Save URL" ) ;
}


//--------------------------------------------------------------------------------------------------------------------------//
function handleErr(msg,url,l) {
//--------------------------------------------------------------------------------------------------------------------------//
	var txt="";
	txt="There was an error on this page.\n\n";
	txt+="Error: " + msg + "\n";
	txt+="URL: " + url + "\n";
	txt+="Line: " + l + "\n\n";
	txt+="Click OK to continue.\n\n";
	alert(txt);
	return true;
}

//--------------------------------------------------------------------------------------------------------------------------//
function getNicheData( formfield, form , index ) {
//--------------------------------------------------------------------------------------------------------------------------//
	var nicheArray = ["niche1" , "niche2" , "niche3" , "niche4" , "niche5" , "niche6" , "niche7" , "niche8" , "niche9" , "niche10" ] ; 
	var add2URL  = false ;
			//alert("Check Field " + formfield) ;
	fieldtype = form.elements[index].type.toLowerCase();
	// Test for Field Type 
	if (  !in_array( excludeArray, fieldtype )  ) {
		formfield  = fixControlName ( formfield ) ;
	}

	if ( in_array( nicheArray, formfield ) )  {
		add2URL = true ;
	}		

	return add2URL  ;

}


//--------------------------------------------------------------------------------------------------------------------------//
function setformobjects(){
//--------------------------------------------------------------------------------------------------------------------------//
	var theforms=document.forms

	//alert("Set Form") ;
	for (i=0; i< theforms.length; i++){
		for (j=0; j< theforms[i].elements.length; j++){
			if (theforms[i].elements[j].className.indexOf("memorize")!=-1 && theforms[i].elements[j].type=="text") {
				memorizearray[memorizearray.length]=theforms[i].elements[j]
				//alert("Remeber " + theforms[i].elements[j].name ) ;
			}
		}
	}


var retrievedvalues=get_cookie("mvalue"+window.location.pathname)
if (retrievedvalues!=""){
	retrievedvalues=retrievedvalues.split("|")
	if (retrievedvalues[retrievedvalues.length-1]!=parseInt(memoryduration)) //reset cookie if var memoryduration has changed
		resetcookie("mvalue"+window.location.pathname)
	else{
		for (i=0; i<memorizearray.length; i++){
			if ( retrievedvalues[i]!="empty_value"  && typeof retrievedvalues[i] != 'undefined' && retrievedvalues[i] != "" )
				memorizearray[i].value=retrievedvalues[i]
			}
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------------//
function get_cookie(Name) {
//--------------------------------------------------------------------------------------------------------------------------//
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}


//--------------------------------------------------------------------------------------------------------------------------//
function isInteger(s)
//--------------------------------------------------------------------------------------------------------------------------//
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


//--------------------------------------------------------------------------------------------------------------------------//
function trackclick() {
//--------------------------------------------------------------------------------------------------------------------------//
	return true ;
}


//--------------------------------------------------------------------------------------------------------------------------//
function resetcookie(id){
//--------------------------------------------------------------------------------------------------------------------------//
	var expireDate = new Date()
	expireDate.setDate(expireDate.getDate()-10)
	document.cookie = id+"=;path=/;expires=" + expireDate.toGMTString()
}

//--------------------------------------------------------------------------------------------------------------------------//
function saveformvalues(){
//--------------------------------------------------------------------------------------------------------------------------//
	var formvalues=new Array(), temp
	for (i=0; i<memorizearray.length; i++){
		temp=memorizearray[i].value!=""? memorizearray[i].value : "empty_value"
		formvalues[formvalues.length]=escape(temp)
		//alert("Save " + escape(temp) ) 
	}
	formvalues[formvalues.length]=parseInt(memoryduration)
	formvalues=formvalues.join("|")
	var expireDate = new Date()
	expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
	document.cookie = "mvalue"+window.location.pathname+"="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
}
 //--------------------------------------------------------------------------------------------------------------------------//
	function skipForm(  ) {

		var form 		= document.forms[0] ;
		verifyFields 	= false ;

		captureForm( form ) ;			
		document.location.href = document.forms[0].redirect.value ;
		//setTimeout( "document.forms[0].submit()",1000) ;		
		//form.submit() ;		
	}

//--------------------------------------------------------------------------------------------------------------------------//
	function captureForm( form ) {
		var delay           = 3000 ;
	//	var start 			= unique_id() ;
		var nichecount 		=  0 ;
		var firstname 		= '';
		var lastname 		= '';
		var email 			= '';		
		var urldata 		= '';	
		var customIndex 	= 0 ;
		var fieldType 		=  "";
		var error 			= 0 ;
		var errorMessage	=  "" ;
		var showURL			=  "N" ;
	

		processExit 		= 0 ;
			
		if ( checkcontrols( 'leadtype' , form ) ) {
		   leadtype = form.leadtype.value ;
		} 
	
		for (var i=0;i<form.length;i++) {
	
			formfield 		= form.elements[i].name ;
			formfield 		= formfield.toLowerCase() ;
	
			//alert("Check Field " + formfield) ;
			fieldtype = form.elements[i].type.toLowerCase();
			// Test for Field Type 
			if (  !in_array( excludeArray, fieldtype )  ) {
				formfield  = fixControlName ( formfield ) ;
			}
	
	//		alert( formfield ) ;
			
			if ( in_array(firstArray, formfield ) )  {
				if( form.elements[i].value != "" ) {
					if ( leadtype == "CLIENT" ) {
						urldata +=  ad2URL("contact_first=" + form.elements[i].value , urldata ) ; 				
					} else {
						firstname = form.elements[i].value ;
						urldata +=  ad2URL("first_name=" + form.elements[i].value , urldata ) ; 
					}
				} else {
					error = 1;
					errorMessage += " First Name \n " ;
				}	
			}		
			else if ( in_array(lastArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					if ( leadtype == "CLIENT" ) {
						urldata +=  ad2URL("contact_last=" + form.elements[i].value , urldata ) ; 				
					} else {
						lastname = form.elements[i].value ;				
						urldata +=  ad2URL("last_name=" + form.elements[i].value , urldata ) ; 
					}
				} else {
					error = 1;
					errorMessage += " Last Name \n " ;
				}	
		
			}	
			else if ( in_array(companyArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("client_name=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Company \n " ;
				}	
		
			}	
	
			else if ( in_array(addressArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("address=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Address \n " ;
				}	
			}
			else if ( in_array(cityArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("city=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " City/Town \n " ;
				}	
				
			}
			else if ( in_array(stateArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("state=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " State \n " ;
				}	
				
			}
			else if ( in_array(countyArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("county=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " County \n " ;
				}	
				
			}
	
			else if ( in_array(zipArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("zipcode=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Zip/Post Code \n " ;
				}	
				
			}
			else if ( in_array(countryArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("country=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Country \n " ;
				}	
				
			}
	
			else if ( in_array(businessArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("business_name=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Business Name \n " ;
				}	
				
			}
	
			else if ( in_array(autoTypeArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					urldata +=  ad2URL("auto_type=" + form.elements[i].value , urldata ) ; 
				}	
				
			}		
			else if ( in_array(phoneArray, formfield ) )  {	
				if( form.elements[i].value != ""  && checkInternationalPhone(form.elements[i].value  ) ) {
					urldata +=  ad2URL("telephone=" + form.elements[i].value , urldata ) ; 
				} else {
					error = 1;
					errorMessage += " Phone \n " ;
				}	
			}
			else if ( in_array(faxArray, formfield ) )  {	
				if( form.elements[i].value != ""  ) {
					urldata +=  ad2URL("fax=" + form.elements[i].value , urldata ) ; 
				}	
			}
	
			else if ( in_array(emailArray, formfield ) )  {	
				if( form.elements[i].value != "" ) {
					if ( !isValidEmail( form.elements[i].value ) ) {
						error = 1;
						errorMessage += " Email Address \n " ;
					} else {
						email = form.elements[i].value ;				
						urldata +=  ad2URL("email=" + form.elements[i].value , urldata ) ; 
					}
				} else {
					error = 1;
					errorMessage += " Email Address \n " ;
				}	
				
			}
			else if ( in_array(memberIDArray, formfield ) )  {	
				urldata +=  ad2URL("member_id=" + form.elements[i].value , urldata ) ; 
			}
			else if ( in_array(teamIDArray, formfield ) )  {	
				urldata +=  ad2URL("team_id=" + form.elements[i].value , urldata ) ; 
			}
			else 	if ( in_array(clientIDArray, formfield ) )  {	
				urldata +=  ad2URL("client_id=" + form.elements[i].value , urldata ) ; 
			}
			else 	if ( in_array(campaignIDArray, formfield ) )  {	
				urldata +=  ad2URL("campaign_id=" + form.elements[i].value , urldata ) ; 
			}
			else 	if ( in_array(programIDArray, formfield ) )  {	
				urldata +=  ad2URL("program_id=" + form.elements[i].value , urldata ) ; 
			}
			else 	if ( in_array(nicheIDArray, formfield ) )  {	
				urldata +=  ad2URL("niche_id=" + form.elements[i].value , urldata ) ; 
			}

			else 	if ( getNicheData( formfield , form , i ) )  {
				if ( form.elements[i].checked ) {
					nichecount++ ;
					urldata +=  ad2URL("niche" + nichecount + "=" + form.elements[i].value , urldata ) ; 
					// alert("Add Niche " + "niche" + nichecount + "=" + form.elements[i].value ) ;
				}
			}
	
			else {
				fieldtype = form.elements[i].type.toLowerCase();
				if (  !in_array( excludeArray, fieldtype )  ) {
				   // Custom Fields //
					//alert("Custom Field " + formfield + " " + form.elements[i].value ) ;
					customIndex++ ;
					fieldname = "custom" + customIndex ;
					urldata +=  ad2URL(fieldname + '=' + form.elements[i].value , urldata ) ; 				
				 }
			}
	
	   }

	  if ( typeof pageID != "undefined" ) {
		 urldata +=  ad2URL("leadpage_id=" +  pageID  , urldata ) ; 	  
	  }
	  if ( typeof messageID != "undefined" ) {
		 urldata +=  ad2URL("message_id=" +  messageID  , urldata ) ; 	  
	  }

	  if ( error == 0 || verifyFields == false ) {

		for (var i=0;i<form.length;i++) {
			formfield 		= form.elements[i].name ;
			formfield 		= formfield.toLowerCase() ;
			formfield  		= fixControlName ( formfield ) ;
			if ( formfield == "unique_id" ) {
				if ( form.elements[i].value == "" || form.elements[i].value == "{UNIQUE_ID}" ) {
					form.elements[i].value  = unique_id  ;
					break ;					
				}
				// alert( " ID A " + form.elements[i].value ) ;				
			}

		}			
		  
		  urldata +=  ad2URL("unique_id=" +  unique_id  , urldata ) ; 
	
		  switch( leadtype.toUpperCase() ) {
			case "CLIENT" :
				  if ( showURL == "Y" ) {
					alert("Save Client " + adClientURL + urldata  ) ;				  
				  }
				  
				 myimage02 = new Image();	
				 myimage02.name = "image999" ;
				 myimage02.src = adClientURL + urldata ;  
				 break ;
	
			case "MEMBER" :			  
				  if ( showURL == "Y" ) {
					alert("Save Member " + adMemberURL + urldata  ) ;				  
				  }
				  if ( checkcontrols( 'processor' , form ) ) {
						processor = form.processor.value ;
						if ( processor.toLowerCase()  == "clickbank" ) {
						  if ( checkcontrols( 'clickbank' , form  ) ) {
							  nickname = form.clickbank.value ;
						  } else {
							  nickname = "palger" ;	
						  }
						  form.redirect.value = "http://1.palger.pay.clickbank.net/?unique_id=" + unique_id + "&email=" + email + "&name=" + firstname + " " + lastname ;
						}
						if ( processor.toLowerCase()  == "paypal" ) {
						  form.redirect.value = "http://advancedleadgeneration.com/common/payform.php?unique_id=" + unique_id ;
						}
						
				  }
				  if ( checkcontrols( 'sponsor_id' , form ) ) {
					sponsor_id = form.sponsor_id.value ;
				  }	else {
					  sponsor_id = 1 ;
				  }
				  urldata +=  ad2URL('sponsor_id=' + sponsor_id , urldata ) ; 							  
				  myimage02 = new Image();	
				  myimage02.name = "image999" ;
				  myimage02.src = adMemberURL + urldata ;  

				  break ;
	
			case "{LEADTYPE}" :
			case "LEAD" :
			default :

				  if ( checkcontrols( 'replicate_id' , form ) ) {
					  urldata +=  ad2URL('replicate_id=' + form.replicate_id.value , urldata ) ; 							  
				  }

				  if ( checkcontrols( 'replicate_client_id' , form ) ) {
					  urldata +=  ad2URL('replicate_client_id=' + form.replicate_client_id.value , urldata ) ; 							  
				  }
				  if ( checkcontrols( 'replicate_niche_id' , form ) ) {
					  urldata +=  ad2URL('replicate_niche_id=' + form.replicate_niche_id.value , urldata ) ; 							  
				  }

				  if ( checkcontrols( 'debug' , form ) ) {
						if ( form.debug.value == 1 ) {
							showURL = "Y" ;
						}
				  }

				 // displayURLData( adleadURL + urldata ) ;		  
				  if ( showURL == "Y" ) {
				  	alert("Save Lead " + adleadURL + urldata ) ;
				  }
				   var iImage = document.createElement("img");
					iImage.name = "savelead";		
					iImage.src =  adleadURL + urldata ;  					
					document.body.appendChild(iImage);
					//alert("Add iImage") ;
				  break ;		
			
		  }
		  
		  
		  if ( verifyFields ) {	
			  alert("Thank you for your submission") ;	  
		  } else {
			  alert("You will redirected to your free report") ;	  		  
		  }
		  return true  ;
	  } else {
		 errorMessage = "Required fields are missing or Invalid \n" + errorMessage ;
		 alert(errorMessage ) ;
		 return false;  
	  }
	
	}  


//--------------------------------------------------------------------------------------------------------------------------//
function in_array(array,elemento) {	
//--------------------------------------------------------------------------------------------------------------------------//
	for(var i in array) { 
		if(array[i]==elemento) {
			return true;
		}	
   }
return false;
} 


//--------------------------------------------------------------------------------------------------------------------------//
function isValidEmail(str) {
//--------------------------------------------------------------------------------------------------------------------------//
//   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
   return (str.indexOf("@") > 0);   
}


//--------------------------------------------------------------------------------------------------------------------------//
 function displayDate() {
//--------------------------------------------------------------------------------------------------------------------------//
	var now 	= new Date();
	var days 	= new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var months 	= new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var date 	= ((now.getDate()<10) ? "0" : "")+ now.getDate();
//	var today =  days[now.getDay()] + ", " +  months[now.getMonth()] + " " + date + ", " + now.getYear() ;
	var today =  months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())) ;
return today ;
}


//--------------------------------------------------------------------------------------------------------------------------//
function fourdigits(number)	{
//--------------------------------------------------------------------------------------------------------------------------//
	return (number < 1000) ? number + 1900 : number;
}


//--------------------------------------------------------------------------------------------------------------------------//
function captureTest() {
//--------------------------------------------------------------------------------------------------------------------------//
	alert("On Submit" ) ;
	return false ;
}


//--------------------------------------------------------------------------------------------------------------------------//
function unique_id() {
//--------------------------------------------------------------------------------------------------------------------------//
	adate = new Date() ;
	return adate.valueOf() ;
}


//--------------------------------------------------------------------------------------------------------------------------//
function stripCharsInBag(s, bag) {   
//--------------------------------------------------------------------------------------------------------------------------//
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//--------------------------------------------------------------------------------------------------------------------------//
function checkInternationalPhone(strPhone){
//--------------------------------------------------------------------------------------------------------------------------//
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//--------------------------------------------------------------------------------------------------------------------------//
function isValidEmail(str) {
//--------------------------------------------------------------------------------------------------------------------------//
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}


//--------------------------------------------------------------------------------------------------------------------------//
function fixControlName( name ) {
//--------------------------------------------------------------------------------------------------------------------------//
	var count = 0 ;
	while ( name.indexOf(" ") > 0 ) {
		// Remove the first portion and replace the remaining with _
		if ( count == 0 ) {
			name = name.substr( name.indexOf(" ") + 1 ) ;		
		} else {
			name = name.substring( 0, name.indexOf(" ") ) + "_" + name.substr( name.indexOf(" ") + 1 ) ;
		}
		count++ ;
	}
	//alert("Name " + name);
	return name ;
}

//--------------------------------------------------------------------------------------------------------------------------//
function urlparameter( name ) {
//--------------------------------------------------------------------------------------------------------------------------//
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//--------------------------------------------------------------------------------------------------------------------------//
function ad2URL( string , URL ) {
//--------------------------------------------------------------------------------------------------------------------------//
  if ( URL == '' ) {
	char = "?" ;
  } else {
	char = "&" ;
  }	
  return char + string ;
}	

//--------------------------------------------------------------------------------------------------------------------------//
function checkcontrols( strControlName , form ) {
//--------------------------------------------------------------------------------------------------------------------------//
   var valid = false ;
   for(i=0;i< form.length;i+=1) {
	   if ( form.elements[i].name == strControlName ) {
		  valid = true ;
		  break ;
	   }
   }
 return valid ;
}


//--------------------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------------------------------------//
var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex = 255;

function fadeText(divId) {
  if(tickerObj)
  {
    if(hex>0) {
      hex-=5; // increase color darkness
      tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
      setTimeout("fadeText('" + divId + "')", fadeSpeed); 
    } else
      hex=255; //reset hex value
  }
}

function initialiseList(divId) {
//  tickerObj = document.getElementById(divId);
  if(!tickerObj)
    reportError("Could not find a div element with id \"" + divId + "\"");
  list = tickerObj.childNodes;
  if(list.length <= 0)
    reportError("The div element \"" + divId + "\" does not have any children");
  for (var i=0; i <list.length; i++) {
    var node = list[i];
    if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
              tickerObj.removeChild(node);
  }
  run(divId, 0);
}

function run(divId, count) {
  fadeText(divId);
  list[count].style.display = "block";
  if(count > 0)
    list[count-1].style.display = "none";
  else
    list[list.length-1].style.display = "none";
  count++;
  if(count == list.length)
    count = 0;
  window.setTimeout("run('" + divId + "', " + count+ ")", interval*1000);
}
function reportError(error) {
  alert("The script could not run because you have errors:\n\n" + error);
  return false;
}

var interval = 7; // interval in seconds
var fadeSpeed = 40; // fade speed, the lower the speed the faster the fade.  40 is normal.
//--------------------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------------------------------------//


//Splash Page script- http://www.dynamicdrive.com/
//Created: August 17th, 2007'
//--------------------------------------------------------------------------------------------------------------------------//
var splashpage={
//--------------------------------------------------------------------------------------------------------------------------//
	// Splash Page Script Activation (1=enabled, 0=completely disabled!)
	splashenabled: 0 ,
	
	//1) URL to file on your server to display as the splashpage
	splashpageurl: "http://google.com/",
	
	//2) Enable frequency control? (1=yes, 0=no)
	enablefrequency: 0,
	
	//3) display freqency: "sessiononly" or "x days" (string value). Only applicable if 3) above is enabled
	displayfrequency: "2 days",
	
	//4) HTML for the header bar portion of the Splash Page
	// Make sure to create a link that calls "javascript:splashpage.closeit()")
	// An IE bug means you should not right align any image within the bar, but instead use "position:absolute" and the "right" attribute
	
	defineheader: '<div style="padding: 5px; color: white; font: bold 16px Verdana; background: black url(blockdefault.gif) center center repeat-x;"><a style="position:absolute; top: 2px; right: 5px" href="javascript:splashpage.closeit()" title="Skip to Content"><img src="skip.gif" border="0" width="114px" height="23px" /></a>Bought to you by Google Image...</div>',
	
	//5) cookie setting: ["cookie_name", "cookie_path"]
	cookiename: ["splashpagecookie", "path=/"],
	
	//6) Auto hide Splash Page after x seconds (Integer value, 0=no)?
	autohidetimer: 15,
	
	////No need to edit beyond here//////////////////////////////////
	
	launch:false,
	browserdetectstr: (window.opera&&window.getSelection) || (!window.opera && window.XMLHttpRequest), //current browser detect string to limit the script to be run in (Opera9 and other "modern" browsers)
	
	output:function(){
		document.write('<div id="slashpage" style="position: absolute; z-index: 100; color: white; background-color:white">') //Main splashpage container
		document.write(this.defineheader) //header portion of splashpage
		document.write('<iframe name="splashpage-iframe" src="about:blank" style="margin:0; padding:0; width:100%; height: 100%"></iframe>') //iframe
		document.write('<br />&nbsp;</div>')
//		this.splashpageref=document.getElementById("slashpage")
		this.splashiframeref=window.frames["splashpage-iframe"]
		this.splashiframeref.location.replace(this.splashpageurl) //Load desired URL into splashpage iframe
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		if (!/safari/i.test(navigator.userAgent)) //if not Safari, disable document scrollbars
		this.standardbody.style.overflow="hidden"
		this.splashpageref.style.left=0
		this.splashpageref.style.top=0
		this.splashpageref.style.width="100%"
		this.splashpageref.style.height="100%"
		this.moveuptimer=setInterval("window.scrollTo(0,0)", 50)
	},
	
	closeit:function(){
		clearInterval(this.moveuptimer)
		this.splashpageref.style.display="none"
		this.splashiframeref.location.replace("about:blank")
		this.standardbody.style.overflow="auto"
	},
	
	init:function(){
		if (this.enablefrequency==1){ //if frequency control turned on
			if (/sessiononly/i.test(this.displayfrequency)){ //if session only control
				if (this.getCookie(this.cookiename[0]+"_s")==null){ //if session cookie is empty
					this.setCookie(this.cookiename[0]+"_s", "loaded")
					this.launch=true
				}
			}
			else if (/day/i.test(this.displayfrequency)){ //if persistence control in days
				if (this.getCookie(this.cookiename[0])==null || parseInt(this.getCookie(this.cookiename[0]))!=parseInt(this.displayfrequency)){ //if persistent cookie is empty or admin has changed number of days to persist from that of the stored value (meaning, reset it)
					this.setCookie(this.cookiename[0], parseInt(this.displayfrequency), parseInt(this.displayfrequency))
					this.launch=true
				} 
			}
		}
		else //else if enablefrequency is off
			this.launch=true
		if (this.launch){
			this.output()
			if (parseInt(this.autohidetimer)>0)
				setTimeout("splashpage.closeit()", parseInt(this.autohidetimer)*1000)
		}
	},
	
	getCookie:function(Name){
		var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
		if (document.cookie.match(re)) //if cookie found
			return document.cookie.match(re)[0].split("=")[1] //return its value
		return null
	},
	
	setCookie:function(name, value, days){
		var expireDate = new Date()
		//set "expstring" to either an explicit date (past or future)
		if (typeof days!="undefined"){ //if set persistent cookie
			var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
			document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; "+splashpage.cookiename[1] //last portion sets cookie path
		}
	else //else if this is a session only cookie setting
		document.cookie = name+"="+value+"; "+splashpage.cookiename[1] //last portion sets cookie path
	}

}


//--------------------------------------------------------------------------------------------------------------------------//
 myPageData = {
//--------------------------------------------------------------------------------------------------------------------------//

	searchTerm: "" ,
	keyword: "" ,

		
	//--------------------------------------------------------------------------------------------------------------------------//
	 noPercent:function(x) {
	//--------------------------------------------------------------------------------------------------------------------------//
		x = unescape(x);
		return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	} ,

	//--------------------------------------------------------------------------------------------------------------------------//
	setKeyword:function () {
	//--------------------------------------------------------------------------------------------------------------------------//
		this.keyword = urlparameter( "keyword" ) ;
	} ,

	//--------------------------------------------------------------------------------------------------------------------------//
	getSearchTerm:function () {
	//--------------------------------------------------------------------------------------------------------------------------//
		return this.searchTerm ;
	} ,

	//--------------------------------------------------------------------------------------------------------------------------//
	getRef:function () {
	//--------------------------------------------------------------------------------------------------------------------------//
		var ref = document.referrer;
		var re = /(\?|&)(q|p|query)=([^&]*)/;
		var searchq = re.exec(ref);
		var seachTerm = "" ;
		if ( searchq ) {
			this.searchTerm = this.noPercent(searchq[3]);
		}
	} ,

	//--------------------------------------------------------------------------------------------------------------------------//
	sleuth:function () {
	//--------------------------------------------------------------------------------------------------------------------------//
		if(document.location.search.indexOf("gclid")!=-1||document.location.search.indexOf("cpc")!=-1) {
			this.getRef();
		}
	}
}


//--------------------------------------------------------------------------------------------------------------------------//
var myPageForm ={ 
//--------------------------------------------------------------------------------------------------------------------------//
	form_unique_id: "" ,

	setThankYouPage:function( form ) {
		var link_var = "" ;
		if ( checkcontrols(  'alg_thankyou' , form ) && checkcontrols( 'redirect' , form )  ) {
			if ( form.alg_thankyou.value != "" ) {
				if ( form.redirect.value == "" ) {
					if ( typeof thankYou != 'undefined' ) {				
						form.redirect.value = thankYou ;				
					} else {
						form.redirect.value = form.alg_thankyou.value ;
					}
				}
			}
		}


		if ( !checkcontrols(  'alg_thankyou' , form ) && checkcontrols( 'redirect' , form )  ) {
			if ( typeof thankYou != 'undefined' ) {
				if ( thankYou.indexOf(".")==-1  ) {
					thankYou = thankYou + this.form_unique_id ;
				}
				
//				if ( form.redirect.value.lastIndexOf(".htm")==-1 ) {
//					thankYou = thankYou + this.form_unique_id ;
//				}
				if ( form.redirect.value == "" ) {
					form.redirect.value = thankYou ;
					//alert("Thank You " + form.redirect.value ) ;
				}
				//alert("Thank You Page " + form.redirect.value ) ;
			}

			if ( typeof thankyou_page_key != 'undefined' ) {
				//alert("Set Forim Thanks") ;
				if ( form.redirect.value == "" ) {
					for (var i=0;i<form.length;i++) {
						formfield 		= form.elements[i].name ;
						formfield 		= formfield.toLowerCase() ;
						formfield  		= fixControlName ( formfield ) ;
						if ( formfield == "unique_id" || formfield == "fields_unique_id" ) {
							this.form_unique_id = form.elements[i].value ;
							break ;					
						}
			
					}			
				  if ( typeof click_type != "undefined" ) {
					this.urldata +=  ad2URL("click_type=" +  click_type  , this.urldata ) ; 	  

					switch ( click_type.toUpperCase()  ) {
						case "EXTERNAL":
							//link_var = "/e/" ;	
							break;									
						case "THANKYOU":					
							link_var = "/ty/" ;	
							break;									
						case "WARMUP":					
							link_var = "/w/" ;	
							break;									
						case "FOLLOWUP":	
							link_var = "/f/" ;	
							break;									
						case "MEMBER":																	
							link_var = "/m/" ;	
							break;									
					}
					thankYou = "http://" + document.domain + link_var +  leadpage_id + "/" +  this.form_unique_id ;					
					//thankYou = "http://" + document.domain + link_var +  thankyou_page_key + "/" +  this.form_unique_id ;
					form.redirect.value = thankYou ;
				  }
					//alert("Thank You " + form.redirect.value ) ;
				}
			}
			
		}
		
		if ( checkcontrols(  'meta_redirect_onlist' , form ) && checkcontrols( 'redirect' , form )  ) {
			form.meta_redirect_onlist.value = form.redirect.value ;
		}
		
		
	} ,

	setFormUniqueID:function( form ) {
		//alert("Set Unique ID ") ;

		for (var i=0;i<form.length;i++) {
			formfield 		= form.elements[i].name ;
			formfield 		= formfield.toLowerCase() ;
			formfield  		= fixControlName ( formfield ) ;
			if ( formfield == "unique_id" || formfield == "fields_unique_id"  ) {
				if ( form.elements[i].value == "" || form.elements[i].value == "{UNIQUE_ID}" ) {
					form.elements[i].value = unique_id ;
					this.form_unique_id = unique_id ;
					break ;					
				}
				// alert( " ID A " + form.elements[i].value ) ;				
			}

		}			
	} ,
	
	setFormOnSubmit:function( form ) {
		// alert("Called onSub") ;
		form.onsubmit = function() { return captureForm( form ) ; } 		

	} 

}

//--------------------------------------------------------------------------------------------------------------------------//
var myTracking={ 
//--------------------------------------------------------------------------------------------------------------------------//
	urldata				: "" ,
	newScript			: "" ,
	dataScript			: 'pagedata.js' ,
    trackingData		: "" ,
	trackingFields 		: new Array() ,
	recordClick			: true ,

	setTrackingFields:function() {

		this.trackingFields[0] = 'replicate_niche_id' ;		
		this.trackingFields[1] = 'replicate_client_id' ;				
		this.trackingFields[2] = 'campaign_id' ;
		this.trackingFields[3] = 'program_id' ;		
		this.trackingFields[4] = 'campaign' ;				
		this.trackingFields[5] = 'item_id' ;						
		this.trackingFields[6] = 'ad_id' ;								
		this.trackingFields[7] = 'advert_id' ;										
		this.trackingFields[8] = 'advert' ;												
		this.trackingFields[9] = 'client_id' ;												
		this.trackingFields[10] = 'member_id' ;														
		this.trackingFields[11] = 'team_id' ;
		this.trackingFields[12] = 'niche_id' ;		
		this.trackingFields[13] = 'leadpage' ;				
		this.trackingFields[14] = 'adsource' ;						
		this.trackingFields[15] = 'replicate_id' ;						

	} ,
				
	getTrackingValues:function( ) {
		if ( document.forms.length > 0 ) {
			form =  document.forms[0] ;
	
			for ( f1=0; f1 < this.trackingFields.length ; f1+=1 ) {
			  if ( checkcontrols( this.trackingFields[f1] , form ) ) {
					formValue = form.elements[this.trackingFields[f1]].value  ;	
					this.urldata +=  ad2URL( this.trackingFields[f1] + "=" +  formValue , this.urldata ) ; 	  
			  }
			}
		}
	} ,

	recordClick: function( searchTerm ) {
	//  alert("Save Tracking A" + this.urldata ) ;
	  if ( typeof pageID != "undefined" ) {
		  this.urldata +=  ad2URL("leadpage_id=" +  pageID  , this.urldata ) ; 	  
	  }
	  if ( typeof messageID != "undefined" ) {
		  this.urldata +=  ad2URL("message_id=" +  messageID  , this.urldata ) ; 	  
	  }

	  if ( typeof page_key != "undefined" ) {
		  this.urldata +=  ad2URL("page_key=" +  page_key  , this.urldata ) ; 	  
	  }

	  // Passing Click type indicates an external page click 
	  if ( typeof click_type != "undefined" ) {
		  this.urldata +=  ad2URL("click_type=" +  click_type  , this.urldata ) ; 	  
	  }

	  if ( typeof external_id != "undefined" ) {
		  this.urldata +=  ad2URL("external_id=" +  external_id  , this.urldata ) ; 	  
	  }

	  // Passing Click type indicates an external page click 
	  if ( typeof clicked_by != "undefined" ) {
		  this.urldata +=  ad2URL("clicked_by=" +  clicked_by  , this.urldata ) ; 	  
		  if ( clicked_by == "test" ) {
			  this.recordClick = false ;
		  }	  
	  }
	  // If this is valid, it's a member click on a progress page //
	  if (  typeof click_member_id !=  "undefined" ) {
		  this.urldata +=  ad2URL("click_member_id=" +  click_member_id  , this.urldata ) ; 	  
	  }

	  for ( var i=0;i< document.forms.length;i++) {
	  		form			= document.forms[i] ;
			formfield 		= form.elements[i].name ;
			formfield 		= formfield.toLowerCase() ;
			formfield  		= fixControlName ( formfield ) ;
			if ( formfield == "unique_id" ) {
			    unique_id = form.elements[i].value ; 
				break ;
			}

		}			
	  this.urldata +=  ad2URL("unique_id=" +  unique_id  , this.urldata ) ; 

	  if ( searchTerm != "" ) {
		  this.urldata +=  ad2URL("search_term=" +  searchTerm  , this.urldata ) ; 	  
	  }
	  if ( document.referrer != "" ) {
	      //this.urldata +=  ad2URL("referrer=" +  document.referrer , this.urldata ) ;   	  
	  }


	  if ( document.forms.length == 0 )  {
			this.recordClick = false ;
	  }

	 if ( this.recordClick ) {
		  if ( checkcontrols( 'adsource' , document.forms[0] )  ) {
				if ( document.forms[0].adsource.value ==  "TRACKING" ) {
					this.recordClick = false ;
				}
		  }      
	  }
	  // alert("Save Tracking " + this.urldata ) ;
	
	  if ( this.recordClick ) {
		  adclickURL += this.urldata ;
		  if(document.images) { 
		   if ( checkcontrols( 'debug' , document.forms[0] ) ) {
				if (document.forms[0].debug.value == 1  ) {
					alert("Save Tracking " + this.urldata ) ;
				}
			}
			//alert("Save Tracking " + this.urldata ) ;
			 myimage01 = new Image();	
			 myimage01.name="image001" ;
			 myimage01.src= adclickURL ; 
		  } 
	  }

	} 

}


//--------------------------------------------------------------------------------------------------------------------------//
var myLightBox ={
//--------------------------------------------------------------------------------------------------------------------------//
	scriptList : new Array() ,
	
	 addLightBox:function( ) {

//		var headID 		= document.getElementsByTagName("head")[0];         
		var newScript 	= document.createElement('script');
		var newScript1 	= document.createElement('script');
		
		newScript.type 	= 'text/javascript';
		newScript.src 	= "http://advancedleadgeneration.com/js/lightboxform/lightboxform.js";
		headID.appendChild(newScript);
		


		newScript1.type = 'text/javascript';
		newScript1.src 	= "http://advancedleadgeneration.com/js/lightboxform/swfobject.js"
		headID.appendChild(newScript1);
	
	}
}

//--------------------------------------------------------------------------------------------------------------------------//
var myPageDraw ={
//--------------------------------------------------------------------------------------------------------------------------//

	google_text_color : '#000000' ,
	google_link_colors : new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff') ,
	
	renderPage:function() {
		// this.addDataSource() ;
		// this.headDivision = document.getElementById("headline") ;
		//window.onload = this.replaceText() ;
		//window.onload = this.init_google() ;		
		this.replaceText() ;
	} ,

	init_google:function (){
		var pattern = /google\./i;
		if (pattern.exec(document.referrer) != null){
			var url_parts = document.referrer.split('?');
			if (url_parts[1]){ 
				var url_args = url_parts[1].split('&');
				for(var i=0; i<url_args.length; i++){
					var keyval = url_args[i].split('=');
					if (keyval[0] == 'q'){
						this.go_google(this.decode_url(keyval[1]));
						return;
					}
				}
			}
		}
	} ,

	 decode_url:function(url){
		return unescape(url.replace(/\+/g,' '));
	} ,

	go_google: function (terms){
		terms = terms.replace(/\"/g,"");
		var terms_split = terms.split(' ');
		var c = 0;
		for(var i=0; i<terms_split.length; i++){
			this.highlight_goolge(terms_split[i], document.body, this.google_link_colors[c]);
			c = (c == this.google_link_colors.length-1)?0:c+1;
		}
	} ,

	highlight_goolge:function (term, container, color){
		var term_low = term.toLowerCase();
	
		for(var i=0; i<container.childNodes.length; i++){
			var node = container.childNodes[i];
	
			if (node.nodeType == 3){
				var data = node.data;
				var data_low = data.toLowerCase();
				if (data_low.indexOf(term_low) != -1){
					//term found!
					var new_node = document.createElement('SPAN');
					node.parentNode.replaceChild(new_node,node);
					var result;
					while((result = data_low.indexOf(term_low)) != -1){
						new_node.appendChild(document.createTextNode(data.substr(0,result)));
						new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));
						data = data.substr(result + term.length);
						data_low = data_low.substr(result + term.length);
					}
					new_node.appendChild(document.createTextNode(data));
				}
			}else{
				//recurse
				this.highlight_goolge(term, node, color);
			}
		}
	} ,

	create_node_google:function (child, color){
		var node = document.createElement('SPAN');
		node.style.backgroundColor = color;
		node.style.color = this.google_text_color;
		node.appendChild(child);
		return node;
	} ,
	
	
	addDataSource:function() {

		var headID 		= document.getElementsByTagName("head")[0];         
		var newScript 	= document.createElement('script');

		newScript.type 	= 'text/javascript';
		newScript.src 	= 'pagedata.js';
		headID.appendChild(newScript);

		//alert("add script") ;

	} ,
	
	replaceText:function (  ){

//	   var head1 		= document.getElementById("head1");
//	   var head2 		= document.getElementById("head2");	   
//	   var head3 		= document.getElementById("head3");	   	   
	//   head1.innerHTML 	= newtitle ;
//	   if ( typeof head1 != 'undefined' ) {
		//   head1.innerHTML 	= headlines[0] ;	   
//	   }
		
		//headDivision.innerHTML = '<p align="center"><b><font color="#FF0000" face="Impact" size="6">Be Sure to Get This Shocking Report Before You Talk with Any Company</font></b></p>' ;
		//bodyContents  = document.getElementsByTagName("body").item(0) ,
	} 
}


//--------------------------------------------------------------------------------------------------------------------------//
var capture ={
//--------------------------------------------------------------------------------------------------------------------------//
	searchTerm : "" ,
	pageTracking: myTracking ,
    pageForm: myPageForm , 
	pageDraw: myPageDraw ,
	pageData: myPageData ,	
	splash   : splashpage ,
    lightBox : myLightBox ,
	documentForms: Array() ,
		
//	formFill: myFill ,

	initPage:function(){

		var pageKey		= urlparameter('id') ;
		var pageKeyWord	= urlparameter('keyword') ;		
		var displayPage	= true ;
		var forms = 0 ;
		
		// For Dynamic Page Dispay
		if ( pageKey != "" || pageKeyWord != "" ) {
			displayPage = true ;
			
			if ( pageKey != "" ) {
				//this.pageDraw.renderPage( 'key' , pageKey ) ;
			} else {
				//this.pageDraw.renderPage(  'keyword' , pageKeyWord ) ;			
			}
		}
		if ( !displayPage ) {
			this.displayErrorPage() ;
		}
	},

	drawPage:function() {
		this.pageDraw.renderPage() ;						
	} ,


	drawLeadIframe:function(){
		var addFrame = true ;
		for ( frameCount = 0 ; frameCount < window.frames.length ; frameCount+=1 ) {
			if ( window.frames[frameCount].name == "savelead" ) {
				addFrame = false ;
			}
		}
		if ( addFrame ) {
			var iLeadFrame = document.createElement("iframe");
			iLeadFrame.style.display = "none";
			iLeadFrame.name = "savelead";		
			document.body.appendChild(iLeadFrame);
			//alert("added Frame") ;		
		}
		//alert("Frame Count " + window.frames.length ) ;		
		for ( frameCount = 0 ; frameCount < window.frames.length ; frameCount+=1 ) {
			//alert("Frame " + window.frames[frameCount].name ) ;
		}
		
		
	},


	displayErrorPage:function(){
		document.location.href = errorPage ;		
	} ,

	setFormOnSubmit:function(){
		for( y=0; y <  this.documentForms.length ; y+=1 ) {
			this.pageForm.setFormOnSubmit( this.documentForms[y] , this.captureForm ) ;
		}
	},

	setFormUniqueID:function(){
		for( y1=0; y1 < this.documentForms.length ; y1+=1 ) {
			this.pageForm.setFormUniqueID( this.documentForms[y1] ) ;
		}
	},

	setThankYouPage:function(){
		for( z=0; z < this.documentForms.length ; z+=1 ) {
			this.pageForm.setThankYouPage( this.documentForms[z] ) ;
		}
	},

	getTrackingValues:function(){
		this.pageTracking.setTrackingFields() ;
		this.pageTracking.getTrackingValues() ;
	},

	recordClick:function(){
		this.pageTracking.recordClick( this.searchTerm ) ;
	},

	getSearchTerm:function() {
		this.pageData.sleuth() ;
		this.searchTerm = this.pageData.getSearchTerm() ;
	} ,

	start:function() {
		this.getSearchTerm() 
		this.initPage()
		//this.drawPage()		
	} ,

	addLightBox:function() {
		this.lightBox.addLightBox() 
	} ,
	
	showSplashPage:function() {
		if ( this.splash.browserdetectstr && this.splash.splashenabled==1) {
			this.splash.init() 
		}
	} ,
	
	getDocumentForms:function() {
		var formCount = 0 ;
		for( index = 0; index < document.forms.length ; index+=1 ) {
			action = document.forms[index].action ;
			if ( action.indexOf( document.domain ) == - 1 ) {
				this.documentForms[formCount] = document.forms[index] ;
				formCount++ ;
			}
		}
	} ,
	
	finish:function() {
		//this.drawLeadIframe()
		this.getDocumentForms() ;
		this.setFormUniqueID();		
		this.getTrackingValues()
		if ( !blogForm ) {
			this.recordClick( )
		}
		this.setThankYouPage() 
		this.setFormOnSubmit() 		

	}
}
//--------------------------------------------------------------------------------------------------------------------------//

capture.start() ;
//window.onload = capture.finish() ;
setTimeout("capture.finish()",3000) ;
