﻿
 function save(linkid,catID)
 {
   var x= doit(linkid,catID);   
 } 
var inCategoryWin;
function OpenCategoryWindow(binType)
{    

    //var appPath="http://beta.ibibo.com/experts/";
    var content="<div id='divCategoryData' ><div id='loading'><br><img src='" +  appPath + "images/load.gif'/>Please wait...</div></div>";
   
    inCategoryWin=dhtmlwindow.open("categorybox", "inline",content ,"Choose Category/City", "width=670px,height=375px,resize=0,scrolling=0,center=1" , "recal");
   
    inCategoryWin.moveTo('middle','middle');
    inCategoryWin.isResize(false);
    
    Controls_ExploreAllCategoryCtrl.GetSawaalBinList(binType, ShowContent_CallBack);
    
    hideSelectAsk();
     showFade();

    inCategoryWin.onclose=function()
    {          
      showSelectAsk();       
      hideFade();
    return true;
    };
    return;
}
function ShowContent_CallBack(response)
{     
    if(response.error == null)
    { 
        try
        {            
            document.getElementById("divCategoryData").innerHTML = response.value;             
        }
        catch(e)
        {             
        }
    }
    else
    {            
    }
     
}





var winSelectCat=null;
function DoSelect(desc,shorturl,catcityid,bin)
{
    document.getElementById("ctl00_mainBody_AskQuestion1_txtCatCityName").value=desc;
    document.getElementById("hdnCatCityID").value=catcityid;
    document.getElementById("hdnShortUrl").value=shorturl;
    document.getElementById("hdnBin").value=bin;    
    if(bin=="L" || bin=="l")
    {         
         document.getElementById("locality").checked=true;
         document.getElementById("spanCatLabel").innerHTML="<h3>City</h3>";
    }
    else
    {
         document.getElementById("category").checked=true;
         document.getElementById("spanCatLabel").innerHTML="<h3>Category</h3>";
    }
    catCityDiv();    
    winSelectCat.hide();
     showSelectAsk();       
     hideFade();   
}
function catCityDiv()
     {
          document.getElementById("divCatCity").style.display="block";
          document.getElementById("divCatRadError").style.display="none";
     }
function OpenCategoryWindowToChoose(binType,catCityID)
{     
    var content="<div id='divCategoryAskData'><div id='loading'><br><img src='" +  appPath + "images/load.gif'/>Please wait...</div></div>";
    
    if(winSelectCat!=null)
       winSelectCat=null;
    winSelectCat=dhtmlwindow.open("categoryAskbox", "inline",content ,"Choose Category/City", "width=670px,height=375px,resize=0,scrolling=0,center=1" , "recal");
    winSelectCat.moveTo('middle','middle');
    winSelectCat.isResize(false);
    Controls_SelectCategoryCtrl.GetSawaalBinList(binType,catCityID,ShowCats_CallBack);
    
    hideSelectAsk();
     showFade();
     
    winSelectCat.onclose=function()
    {          
      showSelectAsk();       
      hideFade();
    return true;
    };
    return;
}

function ShowCats_CallBack(response)
{     
    if(response.error == null)
    { 
        try
        {            
            document.getElementById("divCategoryAskData").innerHTML = response.value;             
        }
        catch(e)
        {             
        }
    }
    else
    {            
    }
    
}





function questionCheck()
{
     if(document.getElementById("ctl00_mainBody_AskQuestion1_txtQuestion").value=="")
    {
        alert("Enter Question");
        return false;
    }
    
    var catCityName=document.getElementById("ctl00_mainBody_AskQuestion1_txtCatCityName").value;

if(catCityName=="")
{
    alert("Choose Category");
    return false;
}
return true;
}
function hideSelectAsk()
{
    var pq=null;
    var pqHead=document.getElementById("selLookIn"); 
    var pqAreaFilter=document.getElementById("ctl00_mainBody_ddlCityArea");
    
    if(document.getElementById("divHeaderAd")!=null)
            document.getElementById("divHeaderAd").style.visibility="hidden";        
    
   if(pqHead!=null)
       pqHead.style.visibility="hidden";   
  if(document.getElementById("ctl00_mainBody_ddlCityArea")!=null)
        document.getElementById("ctl00_mainBody_ddlCityArea").style.visibility="hidden";     
  if(document.getElementById("ctl00_mainBody_QuestionList_ddlFavCatCity")!=null)
        document.getElementById("ctl00_mainBody_QuestionList_ddlFavCatCity").style.visibility="hidden";
        
  
}

var divwin;
function preview()
 {
    ShowBorder="Y";    
   hideSelectAsk();
   showFade();
    if(divwin!=null)  
    {
      divwin=null;
    }
        divwin=dhtmlwindow.open('QPreview', 'iframe', 'QuestionPreview.aspx', 'Question Preview', 'width=600px,height=250px,resize=0,scrolling=no,center=1', 'recal');   
        divwin.moveTo('middle','middle');   
    
    divwin.onclose=function()
    {         
        
      showSelectAsk();       
      hideFade();
     
    return true;
    };    
    
	ShowBorder="Y";    
 }
function showFade()
{  
  var x = document.getElementById("divPopUp");
   x.style.display = 'block'; 
   this.flagState = 1;    
}
function hideFade()
{
    var x = this.parent.parent.document.getElementById('divPopUp');
    x.style.display = 'none';  
    this.flagState = 0;       
}
function showSelectAsk()
{  
    var pq=null;
    var pqAreaFilter=document.getElementById("ctl00_mainBody_ddlCityArea");
    var pqHead=document.getElementById("selLookIn"); 
   
   if(document.getElementById("divHeaderAd")!=null)
            document.getElementById("divHeaderAd").style.visibility="visible";              
    
   if(pqAreaFilter!=null)
       pqAreaFilter.style.visibility="visible";   
   if(pqHead!=null)
       pqHead.style.visibility="visible";  
   if(document.getElementById("ctl00_mainBody_ddlCityArea")!=null)
        document.getElementById("ctl00_mainBody_ddlCityArea").style.visibility="visible"; 
   if(document.getElementById("ctl00_mainBody_QuestionList_ddlFavCatCity")!=null)
        document.getElementById("ctl00_mainBody_QuestionList_ddlFavCatCity").style.visibility="visible";
        
   
}
function OpenAuthWnidow(URL)
{
  var divwin=dhtmlwindow.open('googlebox', 'iframe', URL, 'Login', 'width=610px,height=334px,resize=0,scrolling=no,center=1,', 'recal');
}
function setCookie(c_name,value,expiredays,minutes)
{
    var exdate=new Date();
    exdate.setMinutes(exdate.getMinutes()+minutes);
    exdate.setDate(exdate.getDate()+expiredays);    
    document.cookie=c_name+ "=" +value+((expiredays==null) ? "" : ";expires="+exdate.toString());
} 
function delCookie(c_name,value,date)
{
   document.cookie=c_name+ "=" +value+ ";expires="+date;
}  
var winAdaptor;
function Adopt(url)
{ 
    ShowBorder="Y";   
    hideSelectAsk();
    showFade();
    if(winAdaptor!=null)  
    {
      winAdaptor=null;
    }
    winAdaptor=dhtmlwindow.open('divAdoptWin', 'iframe', url + 'adopting.html', 'Adopt a Sawaal Category', 'width=315px,height=255px,resize=0,scrolling=no,center=1', 'recal');   
    winAdaptor.moveTo('middle','middle');   
    
    winAdaptor.onclose=function()
    {   
      showSelectAsk();       
      hideFade();
      return true;
    };        
	ShowBorder="Y";
 } 
 
   var timeoutID = null; 
  function loadLytebox(id) {
    var anc = document.getElementById(id); 
    if (typeof myLytebox != 'undefined') 
    {        
        myLytebox.start(anc, false, true, false);
    } 
    else 
    {     
        if (timeoutID) { clearTimeout(timeoutID); }
        timeoutID = setTimeout('loadLytebox("'+id+'")', 100);
    }    
  }
  function shareLayer(id,url)
  {
     var lnkObj=document.getElementById(id);
     lnkObj.href=url;
     loadLytebox(id);
  }  
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 replaceword5()
{
    obj = currentObj;    
    if(diffStr(globalold,obj.value).o.length>2&&diffStr(globalold,obj.value).o[2].text+""!="undefined"&&diffStr(globalold,obj.value).o[2].text+""!="")
    { 
        var wd = checkthehindi();
        if(wd==""||wd+""=="undefined")
        {
            if(contentloading==true)
                setTimeout('replaceword5();',100);
            else
                checking =false;
        }
        else
        {                             
            replaceSelection (obj,checkthehindi()+ ' '); 
            global[0]="";
            checking =false;
        }
    }
    else if(diffStr(globalold,obj.value).o[2].text+""=="undefined"||diffStr(globalold,obj.value).o[2].text+""==""||diffStr(globalold,obj.value).o.length<3||diffStr(globalold,obj.value).o[2].text+""==" ")
    {  
      global[0]="";
      checking =false;
    }
    else  
    {
        if(contentloading==true)
                setTimeout('replaceword5();',100);
        else
            checking =false;
    }
}
//question detail
function sendEMail(quesId, sb, catcityid, tab, catShortUrl)
{
    window.open(appPath + 'EmailToFriend.aspx?quesid=' + quesId + '&amp;sb=' + sb + '&amp;tab=' + tab + '&amp;catcityId=' + catcityid + '&amp;csurl=' + catShortUrl ,'', 'height=650,width=600,top=20,left=20,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no');        
}
function sendSMS(quesId)
{
    window.open(appPath + 'SMSToFriend.aspx?quesid=' + quesId ,'',        'height=650,width=600,top=20,left=20,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no');         
}
function showAnswerNow(ctrl)
{
    var a=document.getElementById('ctl00_mainBody_QuestionDetail1_divAnswerNow');
    a.style.display='';
    ctrl.style.display ="none"; 
    return false;
}     
function reportAbuse(quesId)
{        
    var s=window.location.toString();
    window.open(appPath + 'ReportAbuse.aspx?quesid='+ quesId + "&type=0&refurl=" + escape(s)  ,'','height=650,width=850,top=20,left=20,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
}		
function CreateBookmarkLink() 
{ 
   title = "" ;   
   url=location.href;       
   if (window.sidebar) 
   { 
   // Mozilla Firefox Bookmark		
    window.sidebar.addPanel(title, url,"");	
   } 
   else if( window.external ) 
   { 
   // IE Favorite		
    window.external.AddFavorite( url, title); 
   }	
   else if(window.opera && window.print) 
   { 
   // Opera Hotlist		
        return true; 
   } 
}       
function reportAbuse_callback(response)
{
  alert(response.value);
}    
function showLogin(ctrl)
{
    ctrl.visible=true;
}    
function showDiv()
{       
    document.getElementById("divAnswerNow").style.display ='block' ;   
}        
function BindQuestionThumbsUpDown(type, queId, catcityId, ctrlId, classType, sawaalBin, tab, subTabType, catShorturl, quesShorturl)
{       
    var index = 0, str = '';
    if(ctrlId + '' != '')
    {
        index = ctrlId.indexOf('_');
        index = ctrlId.indexOf('_', index + 1);
        index = ctrlId.indexOf('_', index + 1);
        str = ctrlId.substring(0, index);    
        isLoggedIn = (document.getElementById(str + '_hdnIsLoggedIn').value == 'True')?true:false;
        uid = document.getElementById(str + '_hdnUserID').value;        
        var url = authPath + '/RegistrationStart.aspx?surl=' + appPath + catShorturl + tab + quesShorturl + '.html';
        if(isLoggedIn ==  false)
            window.location.href  = url;
        else
        {
            if(classType == 'Q')
                Controls_QuestionDetailCtrl.QuestionThumbsUpDown(type, queId, uid, isLoggedIn, catcityId, ctrlId, classType, sawaalBin, tab, subTabType, catShorturl, quesShorturl, BindThumbsUpDown_CallBack); 
            else
                Controls_ViewAnswerCtrl.AnswerThumbsUpDown(type, queId, uid, isLoggedIn, catcityId, ctrlId, classType, sawaalBin, tab, catShorturl, quesShorturl, BindThumbsUpDown_CallBack); 
        }
    } 
}
function BindThumbsUpDown_CallBack(response)
{     
    if(response.error == null)
    { 
        try
        {            
            var r = response.value;
            var res = new Array();
            res = r.split('!!');
            if(response.error == null)
            {
                document.getElementById(res[0]).innerHTML = res[1];
            }
            else
            {
                document.getElementById(res[0]).innerHTML = '';
            }
        }
        catch(e)
        {
            //alert('Exception');
        }
    }
    else
    {        
    }
}
//answer list
function reportAbuseAnswer(quesId)
{
    //0 for question and 1 for answer
    var s=window.location.toString();
    window.open(appPath + 'ReportAbuse.aspx?quesid='+ quesId + "&type=1&refurl=" + escape(s)  ,'',
         'height=650,width=850,top=20,left=20,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes');
}		
function reportAbuse_callback(response)
{
    alert(response.value);
}
function setLoginDiv(editLink)
{
    var controlLogin = editLink.id.substring(0,editLink.id.indexOf('Login'));
    controlLogin.style.display = '';        
}
//added by umed - start
function BindAnswerThumbsUpDown(type, ansId, queId, catcityId, ctrlId, classType, sawaalBin, tab, catShorturl, quesShorturl)
{ 
    var index = 0, str = '';
    if(ctrlId + '' != '')
    {
        index = ctrlId.indexOf('_');
        index = ctrlId.indexOf('_', index + 1);
        index = ctrlId.indexOf('_', index + 1);
        str = ctrlId.substring(0, index);
    
        isLoggedIn = (document.getElementById(str + '_hdnIsLoggedIn').value == 'True')?true:false;
        uid = document.getElementById(str + '_hdnUserID').value;

        var url = authPath + '/RegistrationStart.aspx?surl=' + appPath + catShorturl + tab + quesShorturl + '.html';
        if(isLoggedIn ==  false)
            window.location.href  = url;
        else
        {
            if(classType == 'Q')
                Controls_QuestionDetailCtrl.QuestionThumbsUpDown(type, queId, uid, isLoggedIn, catcityId, ctrlId, classType, sawaalBin, tab, 'R', catShorturl, quesShorturl, BindThumbsUpDown_CallBack); 
            else
                Controls_AnswerListCtrl.AnswerThumbsUpDown(type, ansId, queId, uid, isLoggedIn, catcityId, ctrlId, classType, sawaalBin, tab, catShorturl, quesShorturl, BindAnswerThumbsUpDown_CallBack); 
        }
    } 
}
function BindAnswerThumbsUpDown_CallBack(response)
{     
    if(response.error == null)
    { 
        try
        {
            var r = response.value;
            var res = new Array();
            res = r.split('!!');
            if(response.error == null)
            {
                document.getElementById(res[0]).innerHTML = res[1];
            }
            else
            {
                document.getElementById(res[0]).innerHTML = '';
            }
        }
        catch(e)
        {
            //alert('Exception');
        }
    }
    else
    {        
    }
}
//add comments
function checkCommentMaxLength(e,el, cLen) 
{  
    switch(e.keyCode) 
    {
        case 37: // left
        return true;
        case 38: // up
        return true;
        case 39: // right
        return true;
        case 40: // down
        return true;
        case 8: // backspace
        return true;
        case 46: // delete
        return true;
        case 27: // escape
        el.value='';
        return true;
    }
    
    if(el.value.length < cLen)
    { 
      return true;
    }       
    else
    {
      return false;
    }
} 