function ID(obj){return document.getElementById(obj);}

function SetCookie(name,value,expires,path,domain,secure){

var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



var landing='';
var email='';
var linkname='';
var googleid='';
var yahooid='';
var msnid='';
var pagetype='';
var sampleid='';
var version='';
var trial='';
function createLink(site,type){
	if(ID('privacy').checked==false){
		
		alert("Please Agree to Our Affiliate Terms");
		return false;
	}
	if(ID('linkname').value==""){
		
		alert("Link Name is a required field");
		return false;
	}
	
	ID('aff_error_box').style.display="none";
	if(ID('version'))version=ID('version').value;
	if(ID('landing'))landing=ID('landing').value;
	if(ID('email'))email=ID('email').value;
	if(ID('linkname'))linkname=ID('linkname').value;
	if(ID('googleid'))googleid=ID('googleid').value;
	if(ID('yahooid'))yahooid=ID('yahooid').value;
	if(ID('msnid'))msnid=ID('msnid').value;
	if(ID('pagetype'))pagetype=ID('pagetype').value;
	if(ID('sampleid'))sampleid=ID('sampleid').value;
	if(ID('trial'))trial=ID('trial').value;

	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if(!emailPattern.test(ID('email').value)){
		ID('aff_error_box').style.display='block';
		return false;
	}


	if(ID('aff_result_div'))ID('aff_result_div').innerHTML='Loading...'
	SetCookie('landing',landing,30);
	SetCookie('email',email,30);
	SetCookie('linkname',linkname,30);
	SetCookie('googleid',googleid,30);
	SetCookie('yahooid',yahooid,30);
	SetCookie('msnid',msnid,30);
	SetCookie('pagetype',pagetype,30);
	SetCookie('sampleid',sampleid,30);
	SetCookie('trial',trial,30);
	if(type=='landingpages'){
		location.reload();
		return false;
	}
	if(type=='ads'){
		location.href='?aff_type='+type+'&action=do';
		return false;
	}
	JsHttpRequest.query(
		'../ajax.php?x='+Math.random(), 
		{
		'landing': landing,
		'version': version,
		'email': email,
		'googleid': googleid,
		'yahooid': yahooid,
		'msnid': msnid,
		'pagetype': pagetype,
		'sampleid': ID('sampleid').value,
		'site': site,
		'type': type,
		'linkname': linkname,
		'trial': trial
		},
 
		function(result, errors) {
			if(errors)alert(errors);
			else{
				if(type=='creatives' || type=='advancedlink' || type=='landing_page_sales_funnel' || type=='advanced_teaser' || type=='emailparser'){
					location.href='?aff_type='+type+'&linkAdr='+result;
					return false;
				}
				ID('aff_result_div').innerHTML=result;
			}
			return false;
		}
	);
}

function goToTool(type){
	ddId='s'+type;
	value=ID(ddId).value;
	locHref=siteAdr+'/'+value+'/?aff_type='+type;
	location.href=locHref;
}


(function($) {

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {  				
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);
