function deleteconfirm(name,url){
	if(confirm("Are you sure want to delete the "+name+". If ok all the information associated with the "+name+" will be removed from the system. \n You can't undo this process")){ 
		 window.location = url;
	}else return false;	 
}

function Updatecouponlist(value,couponId,base){  
	if(value =="off"){
		$("#coupon_"+couponId).attr('checked','checked'); 
 		$("#img_"+couponId).html( '<img src="'+base+'images/checkbox-on.jpg" border=0   onclick=Updatecouponlist("on","'+couponId+'","'+base+'") ;    style=" cursor:pointer"   /> ');
	}else{
		$("#coupon_"+couponId).attr('checked','');
 		$("#img_"+couponId).html('<img src="'+base+'images/checkbox-off.jpg" border=0   onclick=Updatecouponlist("off","'+couponId+'","'+base+'");    style=" cursor:pointer"    />');
	}
	
}

function sendcoupondetails(base,publisherId,page){    
	document.getElementById('ajaxloader').style.display="block";
	var total = document.getElementById('toatalcoupon').value;
	var flag=0;
	var value ="";
	var errflag=0;
	
	for(i=1;i<total;i++){
			if( document.getElementById('coupon_'+i).checked==true){
				flag =1;
				value +=document.getElementById('coupon_'+i).value+"~*"; 
			}		
	}
	var option = document.getElementById('sendoption').value;
	if(flag==0){
		document.getElementById('ajaxloader').style.display="none"; 
		alert("Hey you forgot to choose a coupon");
		errflag =1;
	}else if(document.getElementById('urcellno').value ==""){
		document.getElementById('ajaxloader').style.display="none";
		alert("Hey you forgot to enter your mobile number");
		errflag =1;
	}
	
	if( option=='email'){
			if(document.getElementById('carrier').value ==""  )
			{
				document.getElementById('ajaxloader').style.display="none";
				alert("Hey you forgot to choose your carrier");
				errflag =1;
			}
	} 
	if(errflag ==0) { 
		// send coupon code 	

		$.post(base+"index.php/blink/home/submit/"+publisherId, { mobile: $("#urcellno").val(), carrier: $("#carrier").val(),coupon:value,page:page }, function (data) { 
 			$("#couponMsg").html(data+"<br/>");
			document.getElementById('ajaxloader').style.display="none";
		});

		
	}

}

function updatecouponlength() {
        var new_length = $('#desc').val().length;  
        $('#charcount').text(new_length + ' / 100');
}

function cancelbroadcast(url){
	window.location=url;
}

function sendlbroadcast(url){
 	document.broadcast.action =url;
	document.broadcast.submit();
}

function showOffers(widget,option){
	if(option=="pre"){
		var current = parseInt(widget)-1;
		if(current ==0) current=2;
 		$('#widget_'+widget).hide();	
		$('#widget_'+current).show();	
		$('#offerImg_'+widget).show();	
		$('#showmobile_'+widget).hide();
	}else{
		var current = parseInt(widget)+1;
		var total = document.getElementById('toatalcoupon').value;// alert("w=" + widget + " tot = " + total + "cc== " + current);
		if(current >= parseInt(total) )  current =1;
		$('#widget_'+widget).hide();	
		$('#widget_'+current).show();	
		$('#offerImg_'+widget).show();	
		$('#showmobile_'+widget).hide();
	}
	var total =  $('#toatalcoupon').val();  
	$('#offerscnt_'+current).html('<font size="1"  style="vertical-align:top; ">Offers '+current+' of '+total+'</font>');	
}

function getthisoffer(widget){
	var frm = $('#offer').html();
	frm = frm+"<input type='hidden' name='selwidget' id='selwidget'  value='"+widget+"' /> ";
	$('#showmobile_'+widget).show();
	$('#showmobile_'+widget).html(frm);	
	$('#offerImg_'+widget).hide();	
}

function sendcoupontext(base,publisherId){   
	document.getElementById('ajaxloader').style.display="block";
	var total = document.getElementById('toatalcoupon').value;
	var flag=0;
	var value ="";
	value =document.getElementById('selwidget').value; 
	 if(document.getElementById('urcellno').value ==""){
		document.getElementById('ajaxloader').style.display="none";
		alert("Hey you forgot to enter your mobile number");
	}else if(document.getElementById('carrier').value ==""){
		document.getElementById('ajaxloader').style.display="none";
		alert("Hey you forgot to choose your carrier");
	}else { 
		// send coupon code 	
		$.post(base+"index.php/blink/home/submit/"+publisherId, { mobile: $("#urcellno").val(), carrier: $("#carrier").val(),coupon:value }, function (data) { 
 			$("#couponMsg").html(data+"<br/>"); 
			document.getElementById('ajaxloader').style.display="none";
		});
  	}
}

function getfuturecoupon(base,publisherId,clientId){
	document.getElementById('ajaxloader').style.display="block";
	var total = document.getElementById('toatalcoupon').value;
	var flag=0;
	var value ="";
	var errflag =0;
	var carrier="";
	for(i=1;i<total;i++){
			if( document.getElementById('coupon_'+i).checked==true){
				flag =1;
				value +=document.getElementById('coupon_'+i).value+"~*"; 
			}		
	}
		var option = document.getElementById('sendoption').value;
	if(flag==0){
		document.getElementById('ajaxloader').style.display="none"; 
		alert("Hey you forgot to choose a coupon");
		errflag =1;
	}else if(document.getElementById('urcellno').value ==""){
		document.getElementById('ajaxloader').style.display="none";
		alert("Hey you forgot to enter your mobile number");
		errflag =1;
	}
	
	if( option=='email'){
		 if(document.getElementById('carrier').value ==""){
			document.getElementById('ajaxloader').style.display="none";
			alert("Hey you forgot to choose your carrier");
			errflag =1;
		}else
		{
			carrier=  $("#carrier").val();
		}
	}
	
	
	if(errflag ==0) { 
		// send coupon code 	
		
		$.post(base+"index.php/blink/home/subscribe/"+publisherId, { mobile: $("#urcellno").val(),carrier:carrier ,coupon:value,clientId:clientId }, function (data) { 
 			$("#couponMsg").html(data+"<br/>");
			document.getElementById('ajaxloader').style.display="none";
		});

		
	}

}
function showCouponReport(base)
{
	if( $('#startdate').val().length =="" )
	{
		alert("Please choose starting date"); return false;	
	}
	else
	{
		var url = base+"publisher/couponreport/index/"+$('#startdate').val()+"/business/asc/";
		var business =   $('#business :selected').val(); 
		if(business) url +=business; 
		window.location = url;
	}
}

function printCouponreport(url)
{
	window.open(url,'_blank');
 }
 
 function exportCouponreport(url)
{
	window.location=url;
 }

function sendsupercoupon(base,publisherId,supercouponId)
{
//	document.getElementById('superc_'+supercouponId).style.display="block";
	 if(document.getElementById('phone').value ==""){
		document.getElementById('superc_'+supercouponId).style.display="none";
		alert("Hey you forgot to enter your mobile number");
	}else { 
		// send coupon code 	
		$.post(base+"index.php/supercoupon/widget/sendsupercoupon/"+publisherId+"/"+supercouponId, { phone: $("#phone").val()}, function (data) { 
		alert(data);
			//document.getElementById('superc_'+supercouponId).style.display="block";																																			
 			//$('superc_'+supercouponId).html(data+"<br/>"); 
		});
  	}
}

function clearstartdate(base,coupon_id,storeid)
{
	if(confirm("Are you sure to clear start date of the selected coupon"))
	{ 
		window.location =base+"publisher/coupon/clearstartdate/"+storeid+"/"+coupon_id;
	}
	else
	{
		return false;	
	}
}

function sendcoupondetailsforflashwidget(base,publisherId)
{
	 if(document.getElementById('no').value ==""){
		alert("Hey you forgot to enter your mobile number");
	}else { 
		$('#blink').hide();
		$('#sending').show();
		$.post(base+"index.php/blink/home/sendcoupondetailsfromflash/"+publisherId, { mobile: $("#no").val(),coupon:$("#coupon").val() }, function (data) { 
			alert(data);
			$('#blink').show();
			$('#sending').hide();
			$("#no").val("");
		});
  	}
}

function stripNonNumeric( str ){
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for( var i = 0; i < str.length; i++ ){
    if( rgx.test( str.charAt(i) ) ){
      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
             ( str.charAt(i) == '-' && out.length != 0 ) ) ){
        out += str.charAt(i);
      }
    }
  }
  return out;
}


