var enabletip = false;
var cur_ad_index = 0;
var ads = new Array();
var adObjs = new Array();
var xmlObj;

document.onmousemove=positionTip;


function val_con()
{
	if( document.contact.yname.value.length < 5 )
		{
		alert( "You must enter in a name." );
		document.contact.yname.focus();
		return;
		}
	if( document.contact.phone.value.length < 7 )
		{
		alert("You must enter a telephone number." );
		document.contact.phone.focus();
		return;
		}
	document.contact.sub.disabled = true;
	document.contact.submit();
}



function val_con_label()
{
        document.contact.submit();
}

function validate_contact() {

	
	if( document.contact.yname.value.length < 5 )
		{
		alert( "You must enter in a name." );
		document.contact.yname.focus();
		return;
		}
	if( document.contact.contact_by.value == "Telephone" )
		{
		if( document.contact.phone.value.length < 7 )
			{
			alert("You have requested to be contacted by telephone but have not entered a valid phone number.\nPlease check the number and try again." );
			document.contact.phone.focus();
			return;
			}
		}
	else if( document.contact.contact_by.value == "Email" )
		{
		if( document.contact.eaddy.value.length < 10 || document.contact.eaddy.value.indexOf( "@" ) == -1 || document.contact.eaddy.value.indexOf( "." ) == -1 )
			{
			alert("You have requested to be contacted by email but have not entered a valid email address.\nPlease check the address and try again." );
			document.contact.eaddy.focus();
			return;
			}
		}
	else if( document.contact.contact_by.value == "Mail" )
		{
		if( document.contact.addr1.value.length < 7 )
			{
			alert( "You have requested to be contacted by mail but have not entered in a valid address.\nPlease check the address and try again." );
			document.contact.addr1.focus();
			return;
			}
		else if( document.contact.city.value.length < 4 )
			{
			alert( "You have requested to be contacted by mail but have not entered in a valid city.\nPlease check the city and try again." );
			document.contact.city.focus();
			return;
			}
		else if( document.contact.state.value.length < 2 )
			{
			alert( "You have requested to be contacted by mail but have not entered in a valid state.\nPlease check the state and try again." );
			document.contact.state.focus();
			return;
			}
		else if( document.contact.zip.value.length < 5 )
			{
			alert( "You have requested to be contacted by mail but have not entered in a valid zip code.\nPlease check the zip code and try again." );
			document.contact.zip.focus();
			return;
			}
		}
	else if( document.contact.contact_by.value == "Fax" )
		{
		if( document.contact.fax.value.length < 7 )
			{
			alert( "You have requested to be contacted by fax but have not entered in a valid fax number.\nPlease check the fax number and try again" );
			document.contact.fax.focus();
			return;
			}
		}
	
	document.contact.submit();
}


function edit_link( custid, linkid ) {
	var Ourl = "link.php?id="+custid+"&link="+linkid+"&edit=1";
	window.open( Ourl, "EditLink", "left=20,top=20,width=400,height=75,toolbar=0,location=0,status=0,menubar=0,resizable=0");
}


function act_deact_link( act, custid, linkid ) {

	if( window.XMLHttpRequest )
		{
		xmlObj = new XMLHttpRequest();
		xmlObj.onload = act_res( );
		}
	else if( window.ActiveXObject )
		{
		xmlObj = new ActiveXObject( "Microsoft.XMLHTTP" );
		xmlObj.onreadystatechange = act_res;
		}
	else
		{
		alert( "Error no xmlHttpRequest" );
		}
	xmlObj.open( 'GET', 'link.php?act='+act+'&custId='+custid+'&linkId='+linkid, true );
	xmlObj.send( null );
}

function act_res( ) {
	setTimeout( 'self.location.reload( false )', 500 );
}


function change_order( mov, custid, linkid ) {
	if( window.XMLHttpRequest )
		{
		xmlObj = new XMLHttpRequest();
		xmlObj.onload = act_res;
		}
	else if( window.ActiveXObject )
		{
		xmlObj = new ActiveXObject( "Microsoft.XMLHTTP" );
		xmlObj.onreadystatechange = act_res;
		}
	else
		{
		alert( "Error no xmlHttpRequest" );
		}

	xmlObj.open( "GET", "link.php?mov="+mov+"&custId="+custid+"&linkorder="+linkid, true );
	xmlObj.send( null );
}


function ddrivetip( thetext, thewidth, thecolor )
{
	if( document.all )
		{
		var tipobj = document.all['tooltip'];
		var pointerobj = document.all['pointer'];
		}
	else
		{
		var tipobj = document.getElementById('tooltip');
		var pointerobj = document.getElementById('pointer');
		}

	if( typeof thewidth != "undefined" )
		{
		tipobj.style.width=thewidth+"px";
		}
	if( typeof thecolor != "undefined" && thecolor != "" )
		{
		tipobj.style.backgroundColor = thecolor;
		}
	tipobj.innerHTML=thetext;
	enabletip = true;	 
}

function positionTip( e )
{
	if( document.all )
		{
		var tipobj = document.all['tooltip'];
		var pointerobj = document.all['pointer'];
		var mainobj = document.all['main2'];
		var curX = event.clientX + ietruebody().scrollLeft + 20;
		var curY = event.clientY + ietruebody().scrollTop + 20;
		}
	else
		{
		var tipobj = document.getElementById('tooltip');
		var pointerobj = document.getElementById('pointer');
		var curX = e.pageX + 20;
		var curY = e.pageY + 20;
		}
	if( enabletip )
		{
		tipobj.style.left = curX + "px";
		tipobj.style.top = curY + "px";
		tipobj.style.visibility="visible";
 		}	
}


function hidetip() 
{
	enabletip = false;
	if( document.all )
		{
		var tipobj = document.all['tooltip'];
		var pointerobj = document.all['pointer'];
		}
	else
		{
		var tipobj = document.getElementById('tooltip');
		var pointerobj = document.getElementById('pointer');
		}
	tipobj.innerHTML = "";
	tipobj.style.visibility = "hidden";
	tipobj.style.width="";
}

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function add_ad_objs( linkname, imgname )
{
	var tempArray = new Array();
	
	tempArray[0] = linkname;
	tempArray[1] = imgname;
	adObjs[adObjs.length] = tempArray;
}


function init_ads()
{
	if( window.XMLHttpRequest )
		{
		xmlObj = new XMLHttpRequest();
		xmlObj.onload = load_ads;
		}
	else if( window.ActiveXObject )
		{
		xmlObj = new ActiveXObject( "Microsoft.XMLHTTP" );
		xmlObj.onreadystatechange = load_ads
		}	
	xmlObj.open( 'GET', "ads.php", true );
	xmlObj.send( null );
}


function load_ads( )
{
	if( xmlObj.readyState != 4 ) return;
	
	valArray = xmlObj.responseText.split( "\n" );
	for( var i=0; i <= valArray.length; i++ )
		{
		if( typeof( valArray[i] ) != "undefined" )
			{
			if( valArray[i].length > 4 )
				{
				newArray = valArray[i].split( "-" );
				ads[i] = newArray;
				}
			}
		}
	cur_ad_index = Math.round( (ads.length-1) * Math.random() );
	var temp_idx = cur_ad_index;
	
	
	for( var j=0; j<adObjs.length; j++ )
		{
		temp_idx = cur_ad_index + j;
		if( temp_idx >= ads.length)
			{
			temp_idx = (temp_idx -adObjs.length);
			}
		if( document.all )
			{
			document.all[adObjs[j][0]].href = ads[temp_idx][0];
			document.all[adObjs[j][1]].src = ads[temp_idx][1];
			}
		else
			{
			document.getElementById( adObjs[j][0] ).href = ads[temp_idx][0];
			document.getElementById( adObjs[j][1] ).src = ads[temp_idx][1];
			}
		}
	cur_ad_index++;
	
	var t = setTimeout( 'rotate_ads()', 5000 );
}


function rotate_ads()
{
	if( cur_ad_index > adObjs.length )
		cur_ad_index = 0;
	
	var temp_idx = cur_ad_index;
	
	
	for( var j=0; j<adObjs.length; j++ )
		{
		temp_idx = cur_ad_index + j;
		if( temp_idx >= ads.length)
			{
			temp_idx = (temp_idx -adObjs.length);
			}
		if( document.all )
			{
			document.all[adObjs[j][0]].href = ads[temp_idx][0];
			document.all[adObjs[j][1]].src = ads[temp_idx][1];
			}
		else
			{
			document.getElementById( adObjs[j][0] ).href = ads[temp_idx][0];
			document.getElementById( adObjs[j][1] ).src = ads[temp_idx][1];
			}
		}
	cur_ad_index++;
	
	var t = setTimeout( 'rotate_ads()', 5000 );
}


function add_link( custid, linkid ) {
	var Ourl = "link.php?id="+custid+"&add="+linkid+"";
	window.open( Ourl, "AddLink", "left=20,top=20,width=400,height=75,toolbar=0,location=0,status=0,menubar=0,resizable=0");
}	


function online_pop()
{
	window.open( "https://www.onlineremits.com","Login", "left=20,top=20,width=875,height=620,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1" );

}

