﻿// JScript File

function SaveReviews()
{
   
    if(ValidateAddReviewsForm()==false)
    {
        return(false);
    }
    else
    {
       // alert("Validation successful");
        return(true);
    }
   
}

//Added By Amit To Clear the Form fields on clic of Reset button.

function ResetReviewData()
{
    document.getElementById("txtTitle").value ="";
    document.getElementById("txtDescription").value ="";
     document.getElementById("lblScript").innerHTML ="";
     var registrationErrorsDiv = document.getElementById("WarningMsgs_RegistrationErrors");
     document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
        registrationErrorsDiv.style.display = "none";   
        
        return(false);
}

function ValidateAddReviewsForm()
{
    //alert("In Function to Validate AddEvent Form");
    //errors = "<ul>";
    errors = "";
  mandatoryFieldsErrorFlag = false;
  var status = ValidateAddReviewsFormRoutines();
  if(status == false)
   {
       
        var registrationErrorsDiv = document.getElementById("WarningMsgs_RegistrationErrors");

        registrationErrorsDiv.style.display = "block";
//        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
        registrationErrorsDiv.innerHTML = errors; 
       
        return false;   
    }
    else 
    {
        return true;
    }   
}


function ValidateAddReviewsFormRoutines()
{
    
    errors = "";
    
    var status = true;
    mandatoryFieldsErrorFlag=false;
    
    // validating Title field
    var varTemp = document.getElementById("txtTitle");
  
    var alertName = " Title";
    var isMandatory = 'True';
    if(bValidate(varTemp, "General" ,isMandatory , alertName) != true)
    { 
       varTemp.focus();
	   status = false;
	   return false; 
    }
   
    // validating Description field           
    varTemp = document.getElementById("txtDescription");  
    alertName = " Review";
    isMandatory = 'True'; 
    if(bValidate(varTemp,"",isMandatory , alertName) != true)
    { 
        varTemp.focus();
	    status = false;
	    return false; 
    }
   
   //validating uploading filename field
   varTemp = document.getElementById("PhotoUpload");
   alertName = " Picture";
   //var isMandatory = 'True'; 
   if(varTemp!= null && varTemp!= "")
   {
      //Get the filename
      varTemp = varTemp.value;
      if(varTemp!= null && varTemp!= "")
      {
         //Get extension of filename
         var extension =   varTemp.substring(varTemp.length-3);
      
       //  if(extension == "flv" || extension == "swf" || extension == "peg" || extension == "FLV")
           var ValidImage = CheckImageFileType(varTemp);
           if(!ValidImage)
           {
                errors += " for " + alertName+ '.<br/>'
                status = false;
			    return false; 
           }
      }      
   }          
}

function DeleteReviewRecordConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Would you like to delete this record?');
    return false;
}

function OffensiveReviewConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to report this review as offensive?');
   
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Would you like to report this review as offensive?');
    return false;
}
function ShowLoading()
{
    if(document.getElementById("divLoading")!=null)
    {
        document.getElementById("divLoading").style.display="block";
     }
    return true;
}

function SaveReviewMessage(status)
{ 
   if(status=="add")
   {
      var msg ="Your product review is added successfully and will be visible after Administrator approval";
   }
   else
   {
     var msg = "Review has been successfully updated.";
   }
   ShowMessageBox(msg);
   //alert('Review is added successfully.\nIt will be visible after approval of admin.');
   ResetReviewData();
}
function EditReviewValidate()
{
   
    if(ValidateEditReviewsForm()==false)
    {
        return(false);
    }
    else
    {
       // alert("Validation successful");
        return(true);
    }
}

function ValidateEditReviewsForm()
{
    //alert("In Function to Validate AddEvent Form");
    //errors = "<ul>";
    errors = "";
  mandatoryFieldsErrorFlag = false;
  var status = ValidateEditReviewsFormRoutines();
  if(status == false)
   {       
        var registrationErrorsDiv = document.getElementById("WarningMsgs_RegistrationErrors");

        registrationErrorsDiv.style.display = "block";
//        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
        registrationErrorsDiv.innerHTML = errors; 
       
        return false;   
    }
    else 
    {
        return true;
    }   
}

function ValidateEditReviewsFormRoutines()
{
    
    errors = "";
    
    var status = true;
    mandatoryFieldsErrorFlag=false;
    
    // validating Title field
    var varTemp = document.getElementById("txtTitle");
 
    var alertName = " Title ";
    var isMandatory = 'True';
    if(bValidate(varTemp, "AlphaWithSpaceApostropheComma" ,isMandatory , alertName) != true)
    { 
        status = false;   
        varTemp.focus();
 	    return false; 
    }
   
    // validating Description field           
    varTemp = document.getElementById("txtDescription");  
    alertName = " Review ";
    isMandatory = 'True'; 
    if(bValidate(varTemp,"",isMandatory , alertName) != true)
    { 
       status = false;   
       varTemp.focus();
 	   return false; 
    }
   
    //validating uploading filename field
   varTemp = document.getElementById("PhotoUpload");
   alertName = " Picture";
   if(varTemp!= null && varTemp!= "")
   {
      //Get the filename
      varTemp = varTemp.value;
      if(varTemp!= null && varTemp!= "")
      {
         //Get extension of filename
         var extension =   varTemp.substring(varTemp.length-3).toLowerCase();
         var extension2 =   varTemp.substring(varTemp.length-4).toLowerCase(); 
      
       //  if(extension == "flv" || extension == "swf" || extension == "peg" || extension == "FLV")
      // if(extension == "png" || extension == "jpg" || extension == "gif" || extension == "bmp" || extension == "PNG" || extension == "JPG" || extension == "GIF" || extension == "BMP")
         if(extension == "png" || extension == "gif" || extension == "bmp" || extension1 == "jpg" || extension== "jpe"  || extension2 == "jpeg" || extension2 == "jfif")
         {  


         }
         else
         {
            errors +="Only bmp, gif, jpg and png file types are allowed for " +alertName +"."; 
            status = false;
         }
      }
    }
   
   //if validation of any field comes out to be invalid then display error message 
   if(status == false)
   {
       
        var registrationErrorsDiv = document.getElementById("WarningMsgs_RegistrationErrors");

        registrationErrorsDiv.style.display = "block";
//        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
         document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
        registrationErrorsDiv.innerHTML = errors; 
       
        return false;   
    }
    else 
    {
        return true;
    }   
}

  function CreateFormReviews(FileName)
{
  
    var form=document.createElement("form");
    form.method = 'post';
    form.enctype = 'multipart/form-data'; 
    form.setAttribute('accept-charset', 'utf-8'); 
    var urlValue = FileName;
   // alert(urlValue);
    var imageextension =FileName.substring(FileName.length-3);
   	var currUrl=String(self.location);
    var startPos= currUrl.indexOf("WebPages");
	currUrl=currUrl.substring(0,startPos);
	urlValue= currUrl+"ReviewImages/"+urlValue;
	var  snipshotoutputoptions ="{ 'size': {'max': {'width': "+ 100 +", 'height':"+ 100 +" } }," +
                                  " 'filetype': '"+imageextension+"' }";
                              
    addInputElement(document, form, "snipshot_input", urlValue);
      
    urlValue=currUrl+"WebPages/Reviews/ReviewSnapsCallBack.aspx";
        
    addInputElement(document, form, "snipshot_callback", urlValue);
            
    addInputElement(document, form, "snipshot_callback_agent","user");
    
    addInputElement(document, form, "snipshot_output_options",snipshotoutputoptions); 
        
    addInputElement(document, form, "snipshot_output", "file");
        
    document.body.appendChild(form);
    form.action = "http://services.snipshot.com/";
	form.submit();
	document.body.removeChild(form);
	return false;
  }
  function addInputElement(doc, form, name, value) 
  {
	  var e = doc.createElement('input');
	
	  e.name = name;
	 
	  e.value = value;
	 
	  form.appendChild(e);
 }

function loadUPReviewHandler()
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(UPEndReviewRequestHandler);
    
}

function UPEndReviewRequestHandler(sender, args) 
{
    var err = args.get_error();
    if (err)
    {
      if (err.name == "Sys.WebForms.PageRequestManagerServerErrorException")
       {
             args.set_errorHandled(true);
        }
        if (err.name == "Sys.WebForms.PageRequestManagerParserErrorException") 
              {
                e.set_errorHandled(true);
              }
    }
   var UserMessage = null;
      
    UserMessage = document.getElementById("hidUserMessage"); 
  
    if(UserMessage != null && UserMessage != "")
    {
       var UserMessageVal = UserMessage.value;
    }
    switch(UserMessageVal)
    {
   
        case "AddReviewSuccessful":
            UserMessage.value = "";
            //alert("Review is added successfully.\nIt will be visible after approval of admin.");
            var msg="Congratulations! Review is added successfully.\nIt will be visible after approval of admin.";
            ShowMessageBox(msg);
            break;  
           
        case "AddReviewCommentSuccessful":
            UserMessage.value = "";
            closepopup('pnlComment');
            var msg="Congratulations! Comments has been added successfully.";
            ShowMessageBox(msg);
            break;  
       
//       case "AddReviewCommentSuccessful":
//             ShowMessageBox("Congratulations! Comment added successfully.");
//             UserMessage.value = "";  
//            break;
//        
       case "ReviewDeleteDone":
             UserMessage.value = "";
             var msg="Review has been deleted successfully.";   
             ShowMessageBox(msg);
             break;
             
       case "ReviewApproveDone":
             UserMessage.value = "";
             var msg="Review has been approved successfully.";   
             ShowMessageBox(msg);
             break;
             
       case "CommentDeleteDone":
             UserMessage.value = "";
             var msg="Comment has been successfully deleted.";   
             ShowMessageBox(msg);
             break;
             
       case "ReviewOffensiveRoprted":
             if(document.getElementById("divLoading")!=null)
             {
                document.getElementById("divLoading").style.display="none";
             }
             UserMessage.value = "";
             var msg="The content has been reported as offensive successfully.";   
             ShowMessageBox(msg);
             break;     
    }
}
//function checkForLogin()
//{
// var hidAddCommentsEnable = document.getElementById("hidAddCommentsEnable").value;
//    if(hidAddCommentsEnable == "true")
//    {
//        return ShowModalPopup('pnlComment','Add Comments');
//    }
//    else
//    {
//        ShowInformationMessageBox("Please Login to Add Comments");
//        return false;
//    }
//    
//}
