$(document).ready(function() {
	$('#advertise-countryPayoutTable').dataTable( { 
		"sPaginationType": "full_numbers", 
		"sDom": '<"toolbar">frtip', 
		"bFilter": false,"bInfo": false, 
		"iDisplayLength": 20
	} );
	$('#user-links').dataTable( { 
		"sPaginationType": "full_numbers", 
		"sDom": '<"toolbar">frtip', 
		//"bFilter": false,
		//"bInfo": false, 
		"iDisplayLength": 20,
		"sSearch": "Search all columns:"
	} );
	$('#user-links-new').dataTable( { 
		"sPaginationType": "full_numbers", 
		"sDom": '<"toolbar">frtip', 
		//"bFilter": false,
		//"bInfo": false, 
		"iDisplayLength": 20,
		"sSearch": "Search all columns:",
		"bProcessing": true,
		"bServerSide": true,
		"sAjaxSource": '/user/fetch_links.php'
	} );
} );
$(document).ready(function() {
	$("#popupJoinNowTop").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 500,
		'height'			: 600,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupJoinNow").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 500,
		'height'			: 600,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupForgotPassword").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'frameWidth'		: 500,
		'frameHeight'		: 40,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoReferrer").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 800,
		'height'			: 415,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoOperatingSystem").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 800,
		'height'			: 415,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoBrowser").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 800,
		'height'			: 415,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoFrequencyCap").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 800,
		'height'			: 190,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoBidding").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#000000',
		'width'				: 800,
		'height'			: 365,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true',
		'margin'			: 0,
		'padding'			: 0
	});
	$("#popupAdvertiseMoreInfoEditCampaign").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'width'				: '60%',
		'height'			: '80%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'margin'			: 0,
		'padding'			: 0
	});
	$("popupReferralCenterBanners").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'width'				: '60%',
		'height'			: '80%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'margin'			: 0,
		'padding'			: 0
	});
	$(".popupLinkEdit").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'width'				: '40%',
		'height'			: '20%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'margin'			: 0,
		'padding'			: 0
	});
	$(".popupCampaignEdit").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'width'				: '55%',
		'height'			: '20%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'margin'			: 0,
		'padding'			: 0
	});
	$(".popupLinkDelete").fancybox({
		'showCloseButton'	: true,
		'overlayColor'		: '#ffefdb',
		'width'				: '60%',
		'height'			: '80%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'margin'			: 0,
		'padding'			: 0
	});
});

function showSingleLinkBox() {
	document.getElementById("singleShrinkBox").style.display="";
	document.getElementById("multipleShrinkBox").style.display="none";
}

function showMultipleLinkBox() {
	document.getElementById("singleShrinkBox").style.display="none";
	document.getElementById("multipleShrinkBox").style.display="";
}

function linkDeleteConfirmation(id) {
	var where_to= confirm("Are you sure you want to delete this link?");
	if (where_to== true) {
		window.location="./?deleteLinkId="+id;
	}
}

function campaignDeleteConfirmation(id) {
	var where_to= confirm("Are you sure you want to delete this campaign?");
	if (where_to== true) {
		window.location="?deleteCampaignId="+id;
	}
}

function campaignStatusPaused(id) {
	window.location="?campaignStatus=Paused&campaignStatusID="+id;
}

function campaignStatusActive(id) {
	window.location="?campaignStatus=Active&campaignStatusID="+id;
}

function linkDeleteCheckAll(chk) {
	chk = document.getElementsByName(chk);
	for (i = 0; i < chk.length; i++)
		chk[i].checked = true ;
}

function linkDeleteUnCheckAll(chk) {
	chk = document.getElementsByName(chk);
	for (i = 0; i < chk.length; i++)
		chk[i].checked = false ;
}

function campaignDeleteCheckAll(chk) {
	chk = document.getElementsByName(chk);
	for (i = 0; i < chk.length; i++)
		chk[i].checked = true ;
}

function campaignDeleteUnCheckAll(chk) {
	chk = document.getElementsByName(chk);
	for (i = 0; i < chk.length; i++)
		chk[i].checked = false ;
}

function ajaxRequest(){
	var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] // activeX versions in IE
	if (window.ActiveXObject){ // test support for ActiveXObject in IE
		for (var i=0; i<activexmodes.length; i++){
			try{
				return new ActiveXObject(activexmodes[i])
			}
			catch(e){
				// suppress
			}
		}
	}
	else if (window.XMLHttpRequest) // mozilla,safari,chrome,opera
		return new XMLHttpRequest()
	else
		return false
}

function shrinkSingle() {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("shrinkResult").innerHTML=mygetrequest.responseText
			}
		}
	}
	var urlvalue=encodeURIComponent(document.getElementById("singleUrl").value)
	mygetrequest.open("POST", "/js/api/jquery.shrink_single.php?url="+urlvalue, true)
	mygetrequest.send(null)
}

function shrinkSingleNoUser() {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("shrinkResult").innerHTML=mygetrequest.responseText
			}
		}
	}
	var urlvalue=encodeURIComponent(document.getElementById("singleUrlNoUser").value)
	mygetrequest.open("POST", "/js/api/jquery.shrink_singleNoUser.php?url="+urlvalue, true)
	mygetrequest.send(null)
}

function shrinkMultiple() {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("shrinkResult").innerHTML=mygetrequest.responseText
			}
		}
	}
	var urlvalue=encodeURIComponent(document.getElementById("multipleUrl").value)
	var parameters="url="+urlvalue
	mygetrequest.open("POST", "/js/api/jquery.shrink_multiple.php", true)
	mygetrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mygetrequest.send(parameters)
}

function checkBid(country) {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("checkBidResult").innerHTML=mygetrequest.responseText
			}
		}
	}
	//var urlvalue=encodeURIComponent(document.getElementById("singleUrl").value)
	mygetrequest.open("POST", "/js/api/jquery.check_bid.php?country="+country, true)
	mygetrequest.send(null)
}

/* DEPRECATED June 7, 2011
function linkEdit(id) {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("linkEditOriginal_"+id).style.display="none";
				document.getElementById("linkEditResult_"+id).style.display="";
				document.getElementById("linkEditResult_"+id).innerHTML=mygetrequest.responseText
			}
		}
	}
	mygetrequest.open("POST", "/js/api/jquery.linkEdit.php?id="+id, true)
	mygetrequest.send(null)
}

function linkEditCancel(id) {
	document.getElementById("linkEditResult_"+id).style.display="none";
	document.getElementById("linkEditOriginal_"+id).style.display="";
}

function campaignEdit(id) {
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function() {
		if (mygetrequest.readyState==4) {
			if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
				document.getElementById("campaignEditOriginal_"+id).style.display="none";
				document.getElementById("campaignEditResult_"+id).style.display="";
				document.getElementById("campaignEditResult_"+id).innerHTML=mygetrequest.responseText
			}
		}
	}
	mygetrequest.open("POST", "/js/api/jquery.campaignEdit.php?id="+id, true)
	mygetrequest.send(null)
}

function campaignEditCancel(id) {
	document.getElementById("campaignEditResult_"+id).style.display="none";
	document.getElementById("campaignEditOriginal_"+id).style.display="";
} */

function formValidateAddFundsPayPal() {
	var x=document.forms["addFundsPayPal"]["amount"].value
	if (x==null || x<25) {
		alert("You must deposit at least $25.00.");
		return false;
	}
}

function formValidateAddFundsAlertPay() {
	var x=document.forms["addFundsAlertPay"]["ap_amount"].value
	if (x==null || x<25) {
		alert("You must deposit at least $25.00.");
		return false;
	}
}
