﻿// JScript File


var rootpath1 = 'http://quest.webdunia.com';

function getSearchPage()
{
    var objSearch = document.getElementById("txtSearch");
    var strResult;
    
    if(objSearch)
    {     
        strResult  = objSearch.value;    

        if(strResult.length == 0)
        strResult= " ";

        if((strResult.indexOf('%')>-1) || (strResult.indexOf('#')>-1))
        {
        alert("Following special character(s) are not allowed.\n %, #");
        document.getElementById("txtSearch").focus();
        return;
        }
        window.location.href= rootpath1 + "/" + LanguageName +"/"+LangId + "/" + strResult + "/search/searchresult.html";
    }
}

function  ShowFeedBack(url)
{
	openWindowCenterScreen(url,'FeedBack',460,480);	
}

function openWindowCenterScreen(url,name,height,width,hasScroll,hasResize)
{
try
    {
  var sBars='no';
  var sResise='no';
  if(hasScroll!=null)
    sBars=hasScroll
  if(hasResize!=null)
    sResise=hasResize  
  var w =width; //32;
  var h =height; //96;
  var wleft = (screen.width - w) / 2;
  var wLinks = (screen.height - h) / 2;
  var win = window.open(url,name,
                            'width=' + w + ', height=' + h + ', ' +
                            'left=' + wleft + ', Links=' + wLinks + ', ' +
                            'location=no, menubar=no, ' +
                            'status=no, toolbar=no, scrollbars=' + sBars + ', resizable=' + sResise );
  // Just in case width and height are ignored
  //win.resizeTo(w, h);
  // Just in case left and Links are ignored
  win.moveTo(wleft, wLinks);
  win.focus();    
    }
    catch(e)
    {
    }
}



/********************************************************************************
* Class Name    : CookieHandler ( static )
* Purpose       : To provide an interface for handling cookies through Javascript
* Developed By  : Mukesh R Yadav (mukesh.yadav@suviinfo.com
* Company       : Suvi Information Pvt. Ltd.
* Created Date  : June 14, 2007
*
* Methods
* CookieHandler.setCookie( name, value, expires, path, domain, secure ) 
*       Set a cookie
*       name    = Name of the cookie
*       value   = Value of the cookie
*       expires = [Optional], Set the duration of cookie
*       path    = [Optional], Set cookie path 
*       domain  = [Optional], Set domain of cookie
*       secure  = [Optional], Set cookie as a secure cookie
*
* CookieHandler.getCookie( name) 
*       Retrieve a cookie
*       name    = Name of the cookie
*
* CookieHandler.deleteCookie( name, path, domain ) 
*       Delete a cookie
*       name    = Name of the cookie
*       path    = [Optional], Set cookie path 
*       domain  = [Optional], Set domain of cookie
*
**********************************************************************************/

CookieHandler = new function(){
    this.setCookie = function( name, value, expires, path, domain, secure ) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );
        /* if the expires variable is set, make the correct expires time, the current script below will set 
        it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24 */
        if ( expires ){
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) + 
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
            ( ( path ) ? ";path=" + path : "" ) + 
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ( ( secure ) ? ";secure" : "" );
    }

    this.getCookie = function ( name ) {
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
            return null;
        }
        if ( start == -1 ) {
            return null;
        }
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) { 
            end = document.cookie.length;
        }
        return unescape( document.cookie.substring( len, end ) );
    }
    
    // this deletes the cookie when called    
    this.deleteCookie =function ( name, path, domain ) {
        //if ( this.GetCookie( name ) ) {
            document.cookie = name + "=" +
                ( ( path ) ? ";path=" + path : "") +
                ( ( domain ) ? ";domain=" + domain : "" ) +
                ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
        //}
    }
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function isabusivecontent(content,abusewordlist,isQuestion)
{
    var message;
    if(isQuestion)
     {
       message="The question cannot be posted as it contains abusive content. Please remove abusive content before submitting.";
     }
    else
     {
      message="The answer cannot be posted as it contains abusive content. Please remove abusive content before submitting.";
     }
    var result = abusewordlist.split('|');
        for(var index=0;result.length>index;index++)
        {
            var l = result[index].toLowerCase();        
            content = content.toLowerCase();
            if(content.search(l)>=0)
            {
                alert(message);
                return true;
            }
        }
   return false;     
}