// JavaScript Document
function getPopup(src,index,iframe_class,iframe_css){
	var creatediv="<div class='outer' id='outer"+index+"'><div class='inner "+iframe_class+"' class='"+iframe_css+"' id='inner"+index+"'><iframe src='"+src+"' class='frame' id='frame"+index+"' width='100%' height='100%'  frameborder='0'></iframe><img src='"+URL_ROOT+"media/close.png' class='close' /></div></div>";
	$('body').append(creatediv);
}

$(document).ready(function(){
	$('.fancybox').each(function(index, value){
		var target=$(this).attr('href');
		var iframe_css=$(this).attr('data-css');
		var iframe_class=$(this).attr('data-class');
		$(this).attr('href','javascript:;');
		$(this).click(function(){
			getPopup(target,index,iframe_class,iframe_css);
			$(".close").click(function() {
				$(this).parent().remove();
			});
			$(".outer").click(function() {
				$(this).remove();
			});
		});
	});
	
	$('.onlyZero').blur(function(){
		if($(this).val()==''){
			$(this).val('0');
		}
	});
});
function featured_yes(url){
	if(confirm("are you sure want to add as featured"))window.location=url;
}
function featured_no(url){
	if(confirm("are you sure want to remove this featured product"))window.location=url;
}
function del(url)
{
	if(	confirm("Are you sure you want to delete it?") )
	{
		window.location=url;
	}
}
function SpaceReplace(id){
	var str=id.value;
	$(id).val(str.replace(/ /g, '-'));
}


function printDiv(divID) {
	var contents = $("#"+divID).html();
	var styles="<script type='test/javascript' src='"+root+"js/jquery-1.10.2.js'></script><style>button{display:none}</style><link href='"+root+"assets/css/print.css' rel='stylesheet'></script>";
	var frame1 = $('<iframe />');
	frame1[0].name = "frame1";
	frame1.css({ "position": "absolute", "top": "-1000000px" });
	$("body").append(frame1);
	var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
	frameDoc.document.open();
	frameDoc.document.write('</head><body>'+headPrint );
	//Append the external CSS file.
	frameDoc.document.write(styles);
	//Append the DIV contents.
	frameDoc.document.write(contents);
	frameDoc.document.write("</body></html>");
	frameDoc.document.close();
	setTimeout(function () {
		window.frames["frame1"].focus();
		window.frames["frame1"].print();
		frame1.remove();
	}, 500);
/*	var styles="<script type='test/javascript' src='"+root+"js/jquery-1.10.2.js'></script><style>button{display:none}</style><link href='"+root+"assets/css/print.css' rel='stylesheet'></script>";
	var divElements = document.getElementById(divID).innerHTML;
	var newbody="<html><head><title></title>"+styles+"</head><body>" + headPrint +
	  divElements + "<hr/><div class='footerPrint'><span>signature...............................</span></div></body>";
    var thePopup = window.open( '', "Print", "menubar=0,location=0,height=700,width=700" );
    thePopup.document.write(newbody);
    thePopup.print();*/
}
/*
function printDiv(divID) {
	var styles="<script type='test/javascript' src='"+root+"js/jquery-1.10.2.js'></script><style>button{display:none}</style><link href='"+root+"assets/css/print.css' rel='stylesheet'></script>";
	var divElements = document.getElementById(divID).innerHTML;
	var newbody="<html><head><title></title>"+styles+"</head><body>" + headPrint +
	  divElements + "<hr/><div class='footerPrint'><span>signature...............................</span></div></body>";
    var thePopup = window.open( '', "Print", "menubar=0,location=0,height=700,width=700" );
    thePopup.document.write(newbody);
    thePopup.print();
}*/
function printDivNoHeader(divID) {
	var styles="<style>button{display:none}</style><link href='"+root+"assets/css/print.css' rel='stylesheet'></script>";
	var divElements = document.getElementById(divID).innerHTML;
	var newbody="<html><head><title></title>"+styles+"</head><body>" +
	  divElements + "</body>";
    var thePopup = window.open( '', "Print", "menubar=0,location=0,height=700,width=700" );
    thePopup.document.write(newbody);
    thePopup.print();
}

function fnCreateSelect( aData )
{
	var r='<select style="width:100px"><option value="">None</option>', i, iLen=aData.length;
	for ( i=0 ; i<iLen ; i++ )
	{
		r += '<option value="'+aData[i]+'">'+aData[i]+'</option>';
	}
	return r+'</select>';
}
 
 




var th = ['', 'thousand', 'million', 'billion', 'trillion'];

var dg = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];

var tn = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];

var tw = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];

function toWords(s) {
    s = s.toString();
    s = s.replace(/[\, ]/g, '');
    if (s != parseFloat(s)) return 'not a number';
    var x = s.indexOf('.');
    if (x == -1) x = s.length;
    if (x > 15) return 'too big';
    var n = s.split('');
    var str = '';
    var sk = 0;
    for (var i = 0; i < x; i++) {
        if ((x - i) % 3 == 2) {
            if (n[i] == '1') {
                str += tn[Number(n[i + 1])] + ' ';
                i++;
                sk = 1;
            } else if (n[i] != 0) {
                str += tw[n[i] - 2] + ' ';
                sk = 1;
            }
        } else if (n[i] != 0) {
            str += dg[n[i]] + ' ';
            if ((x - i) % 3 == 0) str += 'hundred ';
            sk = 1;
        }
        if ((x - i) % 3 == 1) {
            if (sk) str += th[(x - i - 1) / 3] + ' ';
            sk = 0;
        }
    }
    if (x != s.length) {
        var y = s.length;
        str += 'point ';
        for (var i = x + 1; i < y; i++) str += dg[n[i]] + ' ';
    }
    return str.replace(/\s+/g, ' ');

}
function uploadToProceed(){
	
	$("#checkStatusUpload").show();
	$("#checkStatusUpload").html("Processing...");
	$("#uploadRefreshBtn").hide();
	$(this).hide();
	/*$.post( "ajax.php", { type: "uploadToProceed"} , function( data ) {
		$("#checkStatusUpload").html(data);
		$("#uploadRefreshBtn").show();
	});*/
	$("#fileProcess").click()
}

$(document).ready(function(e) {
	$.fn.dataTableExt.sErrMode = 'throw';
    var oTable = $('#example').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
});