﻿// JScript File
// manage all the calls to the web service from script manager
//to do all search engine services like
//add to favorite , add comment, send to friend
var tdId;
var divId;
//---------------------------------------------------
//      send to friend
//---------------------------------------------------
function Validate(field, regexp, warning)
{
	var element = document.getElementById(field);

	if (element)
	{
		var re = new RegExp(regexp);

		element.value = element.value.trim();

		if (element.value == "" || !element.value.match(re))
		{
			alert(warning);
			element.select();
			return false;
		}
	}

	return true;
}

function SendMail(documentID)
{
    var reEmail = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
          
    var userMail="";
     if(document.getElementById("CtlShowDocument1_CtlSendToFriend1_txtSendToFriendEmail").value != "") userMail=document.getElementById("CtlShowDocument1_CtlSendToFriend1_txtSendToFriendEmail").value;
      if (userMail=="")
      {
        alert("חובה למלא מייל")  
        return ;
      }
      
      if (!Validate("CtlShowDocument1_CtlSendToFriend1_txtSendToFriendEmail", reEmail, "מייל לא תקין")) return;        
    
    var userName="";
     if(document.getElementById("CtlShowDocument1_CtlSendToFriend1_txtSendToFriendName").value != "") userName=document.getElementById("CtlShowDocument1_CtlSendToFriend1_txtSendToFriendName").value;
      if (userName=="")
      {
        alert("חובה למלא שם משתמש")  
        return ;
      }
    
        
    var UniqeId= "CtlShowDocument1$ctlSendToFriend1";
    SearchEngineToolServices.SendDocument(documentID,document.getElementById(UniqeId + "$txtSendToFriendEmail").value,document.getElementById(UniqeId + "$txtSendToFriendName").value ,OnSendMailComplete,OnSendMailTimeOut,OnSendMailError);
}

function OnSendMailComplete(args)
{
if (args==true)
    alert("המסמך נשלח בהצלחה");
else
    alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית");
}

function OnSendMailTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית" + "\n" + args);
}

function OnSendMailError(args)
{
    alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

//---------------------------------------------------
//      Get Xml Of Document Path
//---------------------------------------------------
function GetXmlTree(documentID , tdTool , divToShow , type)
{
    //debugger;
    if (document.getElementById("CtlShowDocument1_HidTdXml").value == "")
    {
        document.getElementById("CtlShowDocument1_HidTdXml").value = tdTool;
        document.getElementById("CtlShowDocument1_HidDivId").value = divToShow;
        SearchEngineToolServices.GetXmlTree(documentID,type,OnGetXmlTreeComplete,OnGetXmlTreeTimeOut,OnGetXmlTreeError);
    }
    else
        ChangeShowDocumentSettings(document.getElementById("CtlShowDocument1_HidTdXml").value,document.getElementById("CtlShowDocument1_HidDivId").value);
}

function OnGetXmlTreeComplete(args)
{
    //debugger;
    //document.getElementById("CtlShowDocument1_DocumentMap1_divTree").innerHTML = args;
    document.getElementById("CtlShowDocument1_DocumentMap1_Panel1").innerHTML = args;
    ChangeShowDocumentSettings(document.getElementById("CtlShowDocument1_HidTdXml").value,document.getElementById("CtlShowDocument1_HidDivId").value);
//if (args==true)
//    alert("המסמך התווסף למועדפים בהצלחה");
//else
//    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית");
}

function OnGetXmlTreeTimeOut(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}

function OnGetXmlTreeError(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------


//---------------------------------------------------
//      Get Html Table Of Misui Penyoni Links
//---------------------------------------------------
//function GetMisuiHtmlTable(documentID , divTreeId , imgId)
function GetMisuiHtmlTable(documentID)
{
    //debugger;    
    var imgId = "image"+documentID;
    var divTreeId = "divTableTree"+documentID;
    var divTreeIdRight = "divTableTreeRight"+documentID;
    
    if (document.images[imgId].nameProp == 'Plus.gif')
    {
        document.images[imgId].src = 'Images/Minus.gif';
        //document.getElementById("ctl00_ContentPlaceHolder1_SearchResultRP1_HidRowId").value = divTreeId;
        document.getElementById("HidRowId").value = divTreeId;
        document.getElementById("HidRowRight").value = divTreeIdRight;
        SearchEngineToolServices.GetMisuiHtmlTable(documentID,OnGetMisuiHtmlTableComplete,OnGetMisuiHtmlTableTimeOut,OnGetMisuiHtmlTableError);        
    }
    else
    {
        document.images[imgId].src = 'Images/Plus.gif';
        //var rowId = document.getElementById("ctl00_ContentPlaceHolder1_SearchResultRP1_HidRowId").value;
        document.getElementById(divTreeId).innerHTML = "";
        document.getElementById(divTreeIdRight).innerHTML = "";
    }           
       
}

function OnGetMisuiHtmlTableComplete(args)
{
    //debugger;
    var rowId = document.getElementById("HidRowId").value;
       var rowIdRight = document.getElementById("HidRowRight").value;
    document.getElementById(rowId).innerHTML = args;
    document.getElementById(rowIdRight).innerHTML = "&nbsp;";
}

function OnGetMisuiHtmlTableTimeOut(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}

function OnGetMisuiHtmlTableError(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------


//---------------------------------------------------
//      add to favorite
//---------------------------------------------------
function AddToFavorite(documentID)
{
    //debugger;
    //var documentID=1;
    //var userId=document.getElementById("ctl00_UserId").value;//19548;
    //var orgId=document.getElementById("ctl00_OrgId").value;//33832;
    SearchEngineToolServices.AddDocumentToFavorite(documentID,OnAddDocumentToFavoriteComplete,OnAddDocumentToFavoriteTimeOut,OnAddDocumentToFavoriteError);
}

function OnAddDocumentToFavoriteComplete(args)
{
if (args==true)
    alert("המסמך התווסף למועדפים בהצלחה");
else
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית");
}

function OnAddDocumentToFavoriteTimeOut(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}

function OnAddDocumentToFavoriteError(args)
{
    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------


//---------------------------------------------------
//      add Comment
//---------------------------------------------------
function AddComment(documentID)
{
    //debugger;
    //var documentID=1;  
    //var userId=19548;
    //var orgId=33832;
    var title="";
     if(document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentTitle")!=null) title=document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentTitle").value;
     title = title.trim();
      if (title=="")
      {
        alert("חובה למלא את כותרת ההערה")  
        return false;
      }
      
    var body="";
     if(document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentText")!=null) body=document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentText").value;
      body = body.trim();
      if (body=="")
      {
        alert("חובה למלא את גוף ההערה")  
        return false;
      }  
      
    var type=0;
     if(document.getElementById("CtlShowDocument1$CtlAddComment1$GroupRemark")!=null)
     {
        if(document.getElementById("CtlShowDocument1$CtlAddComment1$GroupRemark").checked==true)
            type=0;//GROUP COMMENT
        else
            type=1;//PERSONAL COMMANT
      }  
      
    SearchEngineToolServices.AddComment(documentID,type,title,body,OnAddCommentToDocumentComplete,OnAddCommentToDocumentTimeOut,OnAddCommentToDocumentError);

}

function OnAddCommentToDocumentComplete(args)
{
if (args==true)
{    
    //debugger;
    loadFrame();
    document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentTitle").value = "";
    document.getElementById("CtlShowDocument1$CtlAddComment1$txtAddCommentText").value = "";     
    alert("ההערה התווספה למסמך בהצלחה");
    //After the insert load the frame to show the new comments
    //loadFrame();
    //txtTitle.Value = "";
    //txtText.Value = "";
}
else
    alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
}

function OnAddCommentToDocumentTimeOut(args)
{
    alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
}

function OnAddCommentToDocumentError(args)
{
    alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

//---------------------------------------------------
//     Update User Info
//---------------------------------------------------
function UpdateUserInfo()
{
    //debugger;    
    var userName="";
     if(document.getElementById("ctl00_ContentPlaceHolder1_System1_txtName")!=null) userName=document.getElementById("ctl00_ContentPlaceHolder1_System1_txtName").value;
      if (userName=="")
      {
        alert("חובה למלא שם משתמש")  
        return ;
      }
      
    var userMail="";
     if(document.getElementById("ctl00_ContentPlaceHolder1_System1_txtEmail")!=null) userMail=document.getElementById("ctl00_ContentPlaceHolder1_System1_txtEmail").value;
      if (userMail=="")
      {
        alert("חובה למלא מייל")  
        return ;
      }             
      
    SearchEngineToolServices.UpdateUserInfo(userName,userMail,OnUpdateUserInfoComplete,OnUpdateUserInfoTimeOut,OnUpdateUserInfoError);

}

function OnUpdateUserInfoComplete(args)
{
if (args==true)
{    
    //debugger;    
    alert("המשתמש עודכן בהצלחה");
    //After the insert load the frame to show the new comments
    //loadFrame();
    //txtTitle.Value = "";
    //txtText.Value = "";
}
else
    alert("!ארעה תקלה בעת עדכון המשתמש, אנא נסה שנית" + "\n" + args);
}

function OnUpdateUserInfoTimeOut(args)
{
    alert("!ארעה תקלה בעת עדכון המשתמש, אנא נסה שנית" + "\n" + args);
}

function OnUpdateUserInfoError(args)
{
    alert("!ארעה תקלה בעת עדכון המשתמש, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

//---------------------------------------------------
//      add New Question
//---------------------------------------------------
function AddNewQuestion()
{
    //debugger
    var subject=document.getElementById("ctl00_ContentPlaceHolder1_Department1_NewQuestion1_txtSubject").value;
    if (subject.trim()=="")
    {
       alert("חובה למלא נושא לפנייה")  
       return ;
    }    
    var body=document.getElementById("ctl00_ContentPlaceHolder1_Department1_NewQuestion1_txtMessage").value;        
    if (body.trim()=="")
    {
       alert("חובה למלא תוכן לפנייה")  
       return ;
    }
    
    var radQuestionType = document.getElementById("radioQuestionType1").status;        
    var QuestionType;
    if (radQuestionType)
        QuestionType = 0;
    else
        QuestionType = 1;
                    
    var parentThread = document.getElementById("HidThreadId").value;
        if (document.images["BtnSubmitD"].nameProp == 'SendR.gif')    
        document.images["BtnSubmitD"].src = 'Images/Kolmas/SendDisable.gif';       
    else
        return;
               
    SearchEngineToolServices.AddNewQuestion(subject,body,parentThread,QuestionType,OnAddNewQuestionComplete,OnAddNewQuestionTimeOut,OnAddNewQuestionError);
}

function OnAddNewQuestionComplete(args)
{
document.images["BtnSubmitD"].src = 'Images/Kolmas/SendR.gif';
if (args==true)
{
    clearNewQuestionFields();
    alert("שאלתך נקלטה במערכת," + "\n" + "בדקות הקרובות ישלח אליך מייל המאשר" + "\n" + "את קבלת הפניה. תודה, מערכת כל מס");
}
else
    alert("!ארעה תקלה בעת הוספת השאלה , אנא נסה שנית");
}

function OnAddNewQuestionTimeOut(args)
{
    document.images["BtnSubmitD"].src = 'Images/Kolatid/SendR.gif';
    alert("!ארעה תקלה בעת הוספת השאלה, אנא נסה שנית" + "\n" + args);
}

function OnAddNewQuestionError(args)
{
    document.images["BtnSubmitD"].src = 'Images/Kolatid/SendR.gif';   
    alert("!ארעה תקלה בעת הוספת השאלה, אנא נסה שנית" + "\n" + args);
}

function clearNewQuestionFields()
{
    document.getElementById("ctl00_ContentPlaceHolder1_Department1_NewQuestion1_txtSubject").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_Department1_NewQuestion1_txtMessage").value = "";
    if (document.getElementById("HidThreadId").value == "0")
        document.getElementById("radioQuestionType1").status = true;
 
}

//---------------------------------------------------
//      send Email for Password Remainder
//---------------------------------------------------

function sendPasswordToClient()
{
    //debugger;
    var email=document.getElementById("ctl00_ContentPlaceHolder1_CtlPasswordReminder1_txtEmail").value;
    SearchEngineToolServices.sendPasswordToClient(email,OnsendPasswordToClientComplete,OnsendPasswordToClientTimeOut,OnsendPasswordToClientError);
}

function OnsendPasswordToClientComplete(args)
{
    //debugger;
    if (args=="sendOk")
    {
        document.getElementById("ctl00_ContentPlaceHolder1_CtlPasswordReminder1_divReminder").className = 'HideHomePageDiv';
        document.getElementById("ctl00_ContentPlaceHolder1_CtlPasswordReminder1_divReminderResult").className = 'ShowHomePageDiv';
        document.getElementById("ctl00_ContentPlaceHolder1_CtlPasswordReminder1_lblReminderEmail").innerText = document.getElementById("ctl00_ContentPlaceHolder1_CtlPasswordReminder1_txtEmail").value
    }
    else
    {
        if (args=="sendError")             
            alert("!ארעה תקלה בעת שליחת המייל , אנא נסה שנית");        
        else
            alert(args);      
    }
}

function OnsendPasswordToClientTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}

function OnsendPasswordToClientError(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

//---------------------------------------------------
//      Get Related Documents By Keyword
//---------------------------------------------------

function getRelatedDocumentByKeyword(keyId , keyName)
{
    //debugger;
    var DefaultProduct = "254";
    HomePageServices.getRelatedDocumentByKeyword(keyId,keyName,DefaultProduct,OngetRelatedDocumentByKeywordComplete,OngetRelatedDocumentByKeywordTimeOut,OngetRelatedDocumentByKeywordError);
}

function OngetRelatedDocumentByKeywordComplete(args)
{
    //debugger;
    var temp = new Array();
    temp = args.split('$');
    if (temp[0] == "אין נתונים. תקלה!")
        alert(temp[0]);
    else
    {
        document.getElementById("divBackShowDocument").className = "ShowHomePageDiv";
        //document.getElementById("divResaultTable").innerHTML = args;
        //document.getElementById("divProducts").className = "ShowHomePageDiv";
        document.getElementById("divResaultTable").innerHTML = temp[0];
        document.getElementById("hDescription").value = temp[1];
        document.getElementById("hXmlToSearch").value = temp[2];
        //document.getElementById("CtlShowDocument1_NewSearchResultRP1_hDefaultProductCode").value = temp[3];                 
        //loadResaultFrame();
        //checkboxInitialization();
        ChangeToRepeater();   
    }
}

function OngetRelatedDocumentByKeywordTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}

function OngetRelatedDocumentByKeywordError(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

//---------------------------------------------------
//      send Email for Password Remainder
//---------------------------------------------------

function getRelatedDocumentByCategory(catId,catName)
{
    //debugger;
    var DefaultProduct = "254";
    HomePageServices.getRelatedDocumentByCategory(catId,catName,DefaultProduct,OngetRelatedDocumentByCategoryComplete,OngetRelatedDocumentByCategoryTimeOut,OngetRelatedDocumentByCategoryError);
}

function OngetRelatedDocumentByCategoryComplete(args)
{
    var temp = new Array();
    temp = args.split('$');
    if (temp[0] == "אין נתונים. תקלה!")
        alert(temp[0]);
    else
    {
        document.getElementById("divBackShowDocument").className = "ShowHomePageDiv";
        //document.getElementById("divResaultTable").innerHTML = args;
        //document.getElementById("divProducts").className = "ShowHomePageDiv";
        document.getElementById("divResaultTable").innerHTML = temp[0];
        document.getElementById("hDescription").value = temp[1];
        document.getElementById("hXmlToSearch").value = temp[2];
        //document.getElementById("CtlShowDocument1_NewSearchResultRP1_hDefaultProductCode").value = temp[3];                 
        //loadResaultFrame();
        //checkboxInitialization();
        ChangeToRepeater();
    }       
}

function OngetRelatedDocumentByCategoryTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}

function OngetRelatedDocumentByCategoryError(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}
//---------------------------------------------------

/// for Document Path in wfShowDocument moreInfo ascx ///
function getRelatedDocumentByParentCategory(catId , catName)
{
    //debugger;
    var DefaultProduct = "254";    
    HomePageServices.setCategoryParentResault(catId,catName,DefaultProduct,OngetRelatedDocumentByParentCategoryComplete,OngetRelatedDocumentByParentCategoryTimeOut,OngetRelatedDocumentByParentCategoryError);
}

function OngetRelatedDocumentByParentCategoryComplete(args)
{
    //debugger;
    var temp = new Array();
    temp = args.split('$');
    if (temp[0] == "אין נתונים. תקלה!")
        alert(temp[0]);
    else
    {
        document.getElementById("divBackShowDocument").className = "ShowHomePageDiv";
        //document.getElementById("divProducts").className = "ShowHomePageDiv";
        document.getElementById("divResaultTable").innerHTML = temp[0];
        document.getElementById("hDescription").value = temp[1];
        document.getElementById("hXmlToSearch").value = temp[2];
        //document.getElementById("CtlShowDocument1_NewSearchResultRP1_hDefaultProductCode").value = temp[3];                 
        //loadResaultFrame();
        //checkboxInitialization();
        //document.getElementById("divResaultTable").innerHTML = args;
        ChangeToRepeater();
    }        
}

function OngetRelatedDocumentByParentCategoryTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}

function OngetRelatedDocumentByParentCategoryError(args)
{
    alert("!ארעה תקלה בעת שליחת המייל, אנא נסה שנית" + "\n" + args);
}