// JavaScript Document
function swapRegisterDiv(name){
	var obj1 = $('#'+name);
	if(name == 'loginBox'){
		obj1.fadeIn();
		$('#registerBox').hide();
	}else{
		obj1.fadeIn();
		$('#loginBox').hide();
	}
}

function CopyToClipboard(id)
{
	//alert(id);
	document.getElementById('codeinput'+id).focus();
   	document.getElementById('codeinput'+id).select();
   	CopiedTxt = document.selection.createRange();
   	CopiedTxt.execCommand("Copy");

}

function adjustClicks(url,table,id,clicks,div){
	var urls = url+'coupon/rates/'+table+'/'+id+'/'+clicks+'/'+div;
	ajax.requestFile = urls	// Specifying which file to get
	ajax.onCompletion = showOfferResponse;	// Specify function that will be executed after file has been found
	ajax.onLoading = showOfferWaitMessage(div);	// Action when AJAX is loading the file
	ajax.runAJAX();
	}

function showOfferWaitMessage(div){
	document.getElementById('loadDiv'+div).style.display='block';
	}
function showOfferResponse(){
	var data = ajax.response;
	//alert(data);
	var out = data.split('-+==+-');
	document.getElementById('loadDiv'+out[1]).style.display='none';
	document.getElementById('votingOutput'+out[1]).innerHTML = out[3];
	document.getElementById('rate'+out[1]).innerHTML = out[4]+'%';
	}


function showCommentBox(url,id,div){
	//alert(id);
	var urls = url+'coupon/commentbox/'+id+'/'+div;
	ajax.requestFile = urls	// Specifying which file to get
	ajax.onCompletion = showCommentDiv;	// Specify function that will be executed after file has been found
	ajax.onLoading = showCommentDivWaitMessage(div);	// Action when AJAX is loading the file
	ajax.runAJAX();
}
function showCommentDiv(){
	//alert('commentsBox'+div);
	var data = ajax.response;
	//alert(data);
	var out = data.split('--+==+--');
	//alert(out[1]);
	document.getElementById('commentsBox'+out[1]).innerHTML = out[2];
	$('#commentsBox'+out[1]).show('slow');
	}
function showCommentDivWaitMessage(d){
	/*document.getElementById('commentsBox'+div).innerHTML = data;
	document.getElementById('commentsBox'+div).style.display='block';*/
	}
function closeCommentBox(d){
	$('#commentsBox'+d).hide('slow');
}
function toggleCommentBox(id){
	$('.allCommentBox'+id).slideToggle('slow');
	
}


function verifyPrintableCoupon(){
	var errors = '';
	
	if($('#ptitle').val()=='' || $('#ptitle').val()=='Title'){
		errors += "Title Field is empty<br />";
	}
	if($('#purl').val()=='' || $('#purl').val()=='URL To Print'){
		errors += "Url Field is empty<br />";
	}
	if($('#pcategory').val()==''){
		errors += "Category Field is empty<br />";
	}
	
	
	if(errors != '') {
		$('#perrorMsg').html(errors);
		$('#perrorMsg').slideDown();
		return false;
	} else return true;
}
