﻿// JScript File
function textCounter(field,cntfield,maxlimit) {             
    var val = document.getElementById(field).value;
    
    if (!(val.length >= maxlimit)){ // otherwise, update 'characters left' counter
        document.getElementById(cntfield).innerHTML = new Number(maxlimit) - val.length;
        return true;
    }else{
        document.getElementById(field).value = val.substr(0,maxlimit);        
        if(event.keyCode!=8)            
        {
            document.getElementById(cntfield).innerHTML = new Number(maxlimit) - val.length;                     
            return false;
        }
        else
        {   
            document.getElementById(cntfield).innerHTML = new Number(maxlimit) - val.length;            
            return true;
        }        
    }
}

function textCounterV2(field,cntfield,maxlimit) {    
    var valWithTags = field.getContent();
    var valMax = document.getElementById(maxlimit).value;
    var val = stripHTML(field.getContent());
    if (!(val.length > valMax)){ // otherwise, update 'characters left' counter
        document.getElementById(cntfield).innerHTML = new Number(valMax) - val.length;
    }else{
                document.getElementById(cntfield).innerHTML = new Number(valMax) - val.length;
           if((new Number(valMax) - val.length) < 0)
                document.getElementById(cntfield).innerHTML="0"; 
            return false;
    }
}

function stripHTML(value){
        var re = new RegExp(/(<([^>]+)>)/gi);
    return value.replace(re,'');
}


function ignoreSingleQuote(e)
{//debugger;
    if (!e) 
      e = event;   
    if(e.keyCode == 222)
        return false;         
    else
        return true;
}

function ignoreSpaceAndSingleQuote(e)
{
    if (!e) 
      e = event;   
    if(e.keyCode == 32||e.keyCode == 222)
        return false;         
    else
        return true;
}

function stripIt(x){
    return x.replace(/[^a-zA-Z0-9\_\-]+/g,'');
}

function OpenNewWindow(url,rand)
{    
    displayPdfPopup(rand,'1015px','1000px',url,'scrollbars=yes');
    return false; 
}

if(document.activePopup == null)
    document.activePopup = new Array();

var isOpera = navigator.userAgent.indexOf("Opera") > -1;
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;
var isChrome = navigator.userAgent.indexOf('Chrome');
var cssClass = isIE ? 'class' : 'class';

var win;
function displayPdfPopup(id,width,height,url,params){
   var width  = width;
   var height = height; 
   var left   = window.outerWidth + "px";//(screen.width  - parseInt(width))/2; 
   var top    = window.outerHeight + "px";//(screen.height - parseInt(height))/2;

    if (true){ 
        params += ',width='+width+',height='+height+',top='+top+',left='+ left;
        try{
        id = new String(id).replace(/-/g,"");
        win = window.open(url,id, params,true);
            if(win){
                if(win.closed){
                    document.activePopup.push(win);
                    win.focus();
                }else if (!win.closed){ 
                    if(!isIE)
                        win.focus();
                    else{
                        // Opened window is not allowed to focus again in IE 7/8. if this fails to re-open the window, opened window 
                        // will be cloased and reload window again
                        try{ 
                            win.focus();
                        }catch(e){
                            if(win) win.close();
                            win = window.open(url,id, params);
                            if(win)win.focus();
                        }
                    }
                }
            }
          //This is fix for chrome, for child wondow is not focussing when same window instance is triggered
          if(win &&  isChrome > 0) 
             win.blur();
        }catch(e){
            alert("Invalid operation");
        }
    }
}


function UpdateDealStatistics(dealid, dealtype, pagename, userid, merchantid, locationid, state, city, domainName)
{   
  var strURL = "processblank.aspx?domain=" + domainName + "&action=access-to-merchant-profile&dealid=" + dealid + "&dealtype=" + dealtype + "&pagename=" + pagename + "&userid="+userid+"&merchantid="+merchantid+"&locationid="+locationid+"&state="+state+"&city="+city;
  //var strReturn=window.showModalDialog(strURL,'Process','status:no;resizable:yes;dialogWidth:670px;dialogHeight:10px;dialogHide:true;help:no;scroll:no');   
  window.location= strURL;
}


function RestrictChar()
{
    var exp = String.fromCharCode(window.event.keyCode)
    //Below line will have the special characters that is not allowed you can add if you want more for some characters you need to add escape sequence
    var r = new RegExp("[-_.0-9a-zA-Z\r]", "g");
    if (exp.match(r) == null)
    {
        window.event.keyCode = 0
        return false;
    }
} 