
var v_on_page_exit = 0;
var exit_from_link = '0';
var start_time = new Date();
var form_submited = false;

function onPageExit(){
	if(v_on_page_exit) return 0;
	v_on_page_exit = 1;
	if( !form_submited ){
		var duration = (Math.floor(((new Date()).getTime() - start_time.getTime())/1000)).toString();
		var i_ms_join_lp = new Image();
		//i_ms_join_lp.src = "http://preslav.masq/agamimedia/Root/HTDOCS/php/redir.php?ms_join_lp&"+exit_from_link+"&"+duration+"?http://preslav.masq/agamimedia/Root/HTDOCS/images/s.gif";
		i_ms_join_lp.src = "http://www.agamimedia.com/php/redir.php?ms_join_lp&"+exit_from_link+"&"+duration+"?http://www.agamimedia.com/images/s.gif";
	}
}

function setExitVariable(){
	exit_from_link = '1';
}

function changeEmail(){
	document.forms[0].email_h.value = document.forms[0].email.value;
}

function hideElement( name ){
	elem = document.getElementById( name );
	if( undefined != elem ) elem.style.display = "none";
}

function showElement( name ){
	elem = document.getElementById( name );
	if( undefined != elem ) elem.style.display = "";
}

function changeChannels(){
	if( 'Email' == document.forms[0].promotion_channels.value ){
		showElement( "txt5_tr" );
		showElement( "email_possession_tr" );
		showElement( "email_list_join_form_tr" );
		showElement( "email_list_opt_in_tr" );
		showElement( "email_list_length_tr" ); 
		document.getElementById('website1').innerHTML = 'Primary Website URL*';

	}else{
		hideElement( "txt5_tr" );
		hideElement( "email_possession_tr" );
		hideElement( "email_list_join_form_tr" );
		hideElement( "email_list_opt_in_tr" );
		hideElement( "email_list_length_tr" ); 
	}
	
//	document.getElementById('website1').innerHTML = document.forms[0].promotion_channels.selectedIndex;


//	document.getElementById('website1').innerHTML = document.forms[0].promotion_channels[1].selected;
	
	if( document.forms[0].promotion_channels[1].selected){
		document.getElementById('website1').innerHTML = 'Primary Website URL*';
		document.getElementById('traffic').innerHTML = 'Average Monthly Unique Site Visitors*';
		document.getElementById('incentives_offered_1').innerHTML = 'Does your site offer incentives?*';
		document.getElementById('category_1').innerHTML = 'Category 1*';

	}else{
		document.getElementById('website1').innerHTML = 'Primary Website URL';
		document.getElementById('traffic').innerHTML = 'Average Monthly Unique Site Visitors';
		document.getElementById('incentives_offered_1').innerHTML = 'Does your site offer incentives?';
		document.getElementById('category_1').innerHTML = 'Category 1';
	}
}

function changeCountry(){
	var country = document.forms[0].country.value;
	if( 'GUM'==country || 'MHL'==country || 'PRI'==country || 'UMI'==country || 'USA'==country || 'VIR'==country ){		
		showElement( "select_state_tr" );
		showElement( "tax_id_tr" );
		
		hideElement( "other_not_state_tr" );
		hideElement( "select_state_ca_tr" );
		document.forms[0].zip.maxLength = 5;
	}else if( 'CAN'==country ){
		showElement( "select_state_ca_tr" );
		
		hideElement( "select_state_tr" );
		hideElement( "other_not_state_tr" );
		hideElement( "tax_id_tr" );
		document.forms[0].zip.maxLength = 7;
	}else{
		showElement( "other_not_state_tr" );
		
		hideElement( "select_state_ca_tr" );
		hideElement( "select_state_tr" );
		hideElement( "tax_id_tr" );
		document.forms[0].zip.maxLength = 2147483647;
	}
}

function changePayment(){
	if( 'P' == document.forms[0].payment_method.value ){
		showElement( "paypal_login_tr" );
	}else{
		hideElement( "paypal_login_tr" );
	}	
}

function changeAboutUs(){
	if( 'other' == document.forms[0].about_us.value ){
		showElement( "about_us_specify_tr" );
	}else{
		hideElement( "about_us_specify_tr" );
	}	
}

function generateWebsiteRows(){
	var curr_sites = 3;
	var max_to_add = 5;

	gen = Number( document.forms[0].num_to_gen.value );
	if( gen > max_to_add ) gen = max_to_add;
	gen = gen + curr_sites;

	hideElement( "num_to_gen_tr" );
	
	for( var i = curr_sites; i < gen; i++ ){
		showElement( "website"+i+"_tr" );
	}
}

function clearList( theList ){
	for( x = theList.length; x >= 0; x-- ){
		 theList.options[x] = null;
	}
}
