﻿
var popupwin;
var contentOpen;

function popup(page, title, w, h, scroll, resize)
{
    var s = "";
    var r = "";
    if (scroll == true)
    {
        s = "yes";
    }
    else
    {
        s = "no";
    }
    if (resize == true)
    {
        r = "yes";    
    }
    else
    {
        r = "no";
    }
    
    var args = "width="+w+",height="+h+",toolbar=no,scrollbars="+s+",location=no,statusbar=no,menubar=no,resizable="+r;
	popupwin = window.open(page, title, args);
	popupwin.focus();
}

function popupClose()
{
    if (popupwin != null)
    {
        popupwin.close();
        popupwin = null;
   }

}

function cropText(txt, maxChars) {
	
	if (txt.length >= maxChars) {
		return txt.substring(0, maxChars-3)+"...";
	}
	
	return txt;
	
}



function create(type, css)
{
    
   var t = document.createElement(type);
   if (css != undefined)
   {
     t.className = css;
   }
   
   return t;

}



function asDecimal(txt)
{
	var index = txt.indexOf(".");
	if (index == 0)
	{
		txt = "0"+txt;
	}
	else if (index == -1)
	{
		txt = txt+".0";
	}
	else 
	{
		return txt;
	}
	

}

function getNumber(txt) {
	var regex = /\d+/g;
	regex.lastIndex = 0;
	
	var result = regex.exec(txt);
	if (result != null) {
		return result[0];
	}
	return 0;
}

function deleteWords(text, limit)
{
	var r = 0;
	var a = text;
	
	    while(a.indexOf('\n') > 0) {
		    a = a.replace('\n', ' ');
	    }
    	
	    var arr = trim(a).split(' ');
	    
	    var len = arr.length-limit;
	    if (len > -1)
	    {
			arr.splice(limit, len);
	    }
	    
	    var str = "";
	    for(var i=0; i < arr.length; i++)
	    {
			str += arr[i] + " ";
	    }
	    
	    return str;
}

function countWords(text) {

	var r = 0;
	var a = text;
	
	    while(a.indexOf('\n') > 0) {
		    a = a.replace('\n', ' ');
	    }
    	
	    var arr = trim(a).split(' ');
	    for (var i=0; i < arr.length; i++) {
		    if (trim(arr[i]).length > 0) {
			    r++;
			    
		    }
    		
	    }
	
	return r;
	
}



function lTrim(str) { 

	    for (var k=0; k < str.length && str.charAt(k)<=' ' ; k++) ;
	    return str.substring(k,str.length);

}

function rTrim(str) {
    
	    for (var j=str.length-1; j>=0 && str.charAt(j)<=' ' ; j--) ;
	    return str.substring(0,j+1);

	    
}
function trim(str) {
    if (str != null)
    {
	    return lTrim(rTrim(str));   
    }
    return "";
}

function escape(str)
{
    return str.replace(/\\\'/g, "'").replace(/'/g, "\\'").replace(/"/g, "\\\"").replace(/'/g, "\\'");
}

function clean(str)
{
    return escape(trim(str));
}

function pasteClean(html) 
{
   

   var last = html.lastIndexOf("-->");
	var goodText = "";
	if (last > -1)
	{
		goodText = html.substring(last+3);
	}
	else 
	{
		goodText = html;
	}
	


    goodText = goodText.replace(/<(\/)*(\\?xml:|meta|link|span|div|p|font|del|ins|st1:|[ovwxp]:)((.|\s)*?)>/gi, '');
    goodText = goodText.replace(/(class|style|type|start)=("(.*?)"|(\w*))/gi, '');
    goodText = goodText.replace(/<style(.*?)style>/gi, '');
    goodText = goodText.replace(/<script(.*?)script>/gi, '');
    goodText = goodText.replace(/<!--(.*?)-->/gi, '');

    goodText = goodText.replace(/&rsquo;/gi, "'");
    goodText = goodText.replace(/&ldquo;/gi, "\"");
    goodText = goodText.replace(/&rdquo;/gi, "\"");
    
    return goodText;
}


function isIE()
{
	if (navigator.appName.indexOf("Microsoft") > -1)
	{
		return true;
	}
	return false;
}

function isiPad()
{
	return (navigator.platform.toLowerCase().search("ipad") > -1);
}


function isApple()
{
	return (isMac() || isAppleMobile());	
}

function isMac()
{
	return (window.navigator.platform.toLowerCase().indexOf("mac") > -1)
}

function isMobile()
{
	return isAppleMobile() || isAndroid();
}

function isAppleMobile()
{
	return (isiPhone() || isiPod() || isiPad());
}	

function isiPhone()
{

	return (navigator.platform.toLowerCase().search("iphone") > -1);	

}

function isiPod()
{
	return (navigator.platform.toLowerCase().search("ipod") > -1);
}

function isAndroid()
{
	return (navigator.userAgent.toLowerCase().search("android") > -1);	
}







