﻿
function ShowFgtPwd(ObjCntrl) {
    var IdPrefix = ObjCntrl.substring(0, (ObjCntrl.lastIndexOf("_") + 1));
    document.getElementById(IdPrefix + 'lblErrMsgFrgtPwd').innerHTML = "";
    document.getElementById(IdPrefix + 'txtEmail').value = "";
    document.getElementById(ObjCntrl).style.display = "none";
    document.getElementById('tblFrgt').style.display = "block";
    if ($('#' + IdPrefix + 'spnBox').length > 0)
        document.getElementById(IdPrefix + 'spnBox').innerHTML = "Forgot Password";
    if ($('#spnBox').length > 0)
        document.getElementById('spnBox').innerHTML = "Forgot Password";
    
    return false;
}

function ShowFgtPwd1(ObjCntrl) {
    var IdPrefix = ObjCntrl.substring(0, (ObjCntrl.lastIndexOf("_") + 1));
    document.getElementById(IdPrefix + 'lblErrMsgFrgtPwd').innerHTML = "";
    document.getElementById(IdPrefix + 'txtEmail').value = "";
    document.getElementById(ObjCntrl).style.display = "none";
    document.getElementById('tblFrgt1').style.display = "block";
    document.getElementById('spnBox1').innerHTML = "Forgot Password";
    return false;
}


function ValidateFgtPwd1(ObjCntrl)
		{
		  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		  var EmailId=document.getElementById(ObjCntrl).value;
		   var IdPrefix = ObjCntrl.substring(0, (ObjCntrl.lastIndexOf("_") + 1));
		  
		  
		   if(EmailId=="")
		   {
		     document.getElementById(IdPrefix+'lblErrMsgFrgtPwd').innerHTML =" please enter your Email";
		     return false ;
		   }
		   else 
		   {
		       if (!EmailId.match(emailRegex)) {
                document.getElementById(IdPrefix+'lblErrMsgFrgtPwd').innerHTML='You have entered an invalid email.';
                return false;
                }
                else 
                {
                  document.getElementById(IdPrefix+'lblErrMsgFrgtPwd').innerHTML="";                         
                }
		   }
		  return true ;
		}

		function ClearTxt(Id, tdId) {
		    var IdPrefix = Id.substring(0, (Id.lastIndexOf("_") + 1));
		    if ($('#' + IdPrefix + 'pnlSignIn').length == 0) {
		        IdPrefix += 'ContentPlaceHolder1_';
		    }
		    document.getElementById(IdPrefix + 'pnlSignIn').style.display = "block";
		    document.getElementById('tblFrgt').style.display = "none";
		    document.getElementById(IdPrefix + 'lblErrMsg').innerHTML = "";
		    if (!document.getElementById(IdPrefix + 'ChBxRemember').checked) {
		        document.getElementById(IdPrefix + 'txtUserName').value = "";
		        document.getElementById(IdPrefix + 'txtPwd').value = "";
		    }
		    document.getElementById(IdPrefix + 'tdResendVmail').style.display = "none";
		    if (tdId != "") {
		        document.getElementById(tdId).style.display = "none";
		        document.getElementById('spnBox').innerHTML = "Sign In";
		    }
		    else {
		        document.getElementById('spnBox').innerHTML = "Sign In to access results";
		    }
		    return false;
		}

		function ClearTxt1(Id, tdId) {
		    var IdPrefix = Id.substring(0, (Id.lastIndexOf("_") + 1));
		    if ($('#' + IdPrefix + 'pnlSignIn').length == 0) {
		        IdPrefix += 'ContentPlaceHolder1_';
		    }
		    document.getElementById(IdPrefix + 'pnlSignIn').style.display = "block";
		    document.getElementById('tblFrgt1').style.display = "none";

		    document.getElementById(Id).innerHTML = "";
		    if (!document.getElementById(IdPrefix + 'ChBxRemember').checked) {
		        document.getElementById(IdPrefix + 'txtUserName').value = "";
		        document.getElementById(IdPrefix + 'txtPwd').value = "";
		    }
		    document.getElementById(IdPrefix + 'tdResendVmail').style.display = "none";
		    if (tdId != "") {
		        document.getElementById(tdId).style.display = "none";
		        document.getElementById('spnBox1').innerHTML = "Sign In";
		    }
		    else {
		        document.getElementById('spnBox1').innerHTML = "Sign In to access results";
		    }
		    return false;
		}

function  setStatus(lblID)
{
  var IdPrefix = lblID.substring(0, (lblID.lastIndexOf("_") + 1));
  document.getElementById(IdPrefix+'tdResendVmail').style.display = "none";
  document.getElementById(lblID).innerHTML="";
}

 
 
 function ValidateLogin(Id,Mode)
 {
   var Res =null;
   var IdPrefix = Id.substring(0, (Id.lastIndexOf("_") + 1));
   if(document.getElementById(IdPrefix+'txtPwd').value =="" || document.getElementById(IdPrefix+'txtUserName').value =="")
   {
     document.getElementById(IdPrefix+'lblErrMsg').innerHTML ="Please enter Email address & Password to Sign In";
     return false ;
   }
   else 
   {
     document.getElementById(IdPrefix+'lblErrMsg').innerHTML ="";
     document.getElementById(Id).style.display="none";
     if(Mode=='Master')
       document.getElementById('SigninMaster_div').style.display="inline";
     else if(Mode=='Default')
       document.getElementById('SigninDefault_div').style.display="inline";
     else if(Mode=='UCItem')
       document.getElementById('SigninUCItem_div').style.display="inline";  
   }
   return true ;
 }
 
 
function RequestCustomerPage(url) {
  if (window.XMLHttpRequest) {              
    AJAX=new XMLHttpRequest();              
  } else {                                  
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     AJAX.open("GET", url, false);                             
     AJAX.send(null);
     return AJAX.responseText;                                         
  } else {
     return false;
  }                                             
}


function ValidateCode() {
    var VerCode = $("[id$='_txtVerifyCode']").val();
    if (isNaN(VerCode)) {
        $("[id$='_lblErrMsg3']").text("Please enter a valid verification code");
        return false;
    }
    else if (VerCode.length != 4) {
        $("[id$='_lblErrMsg3']").text("Please enter a four digit verification code");
        return false;
    }
    return true;
}

function ValidateMobile() {
    var MobileNo = $("[id$='_txtMobileNo']").val();
    if (MobileNo != "") {
        if (isNaN(MobileNo)) {
            $("[id$='_lblErrMsg2']").text("Please enter a valid phone number")
            return false;
        }
        else {
            if (MobileNo.length <= 7) {
                $("[id$='_lblErrMsg2']").text("Please enter a valid 10 digit phone number");
                return false;
            }
        }
    }
    else {
        $("[id$='_lblErrMsg2']").text("Please enter a valid phone number")
        return false;
    }
        
    return true;
}

function CheckSurName() {
    var type = $("[id$='_rbtFriend'] input:radio:checked").val();
    if (type == '2') {
        $("[id$='_trSurName']").attr('style', 'display:table-row');
        $("[id$='_txtSurName']").text("")
    }
    else {
        $("[id$='_trSurName']").attr('style', 'display:none');
        $("[id$='_txtSurName']").text("")
    }
}

function ValidateSurName() {
    if (!$("[id$='_rbtFriend'] input:radio:checked").val()) {
        $("[id$='_lblErrMsgFr']").text("Please select whose form is this")
        return false;
    }
    else if ($("[id$='_rbtFriend'] input:radio:checked").val() == '2' && $("[id$='_txtSurName']").val() == '') {
        $("[id$='_lblErrMsgFr']").text("Please enter the surname")
        return false;
    }
}

function MissingForm_Validate() {
    if (!$("[id$='_rdbtls_FromType'] input:radio:checked").val()) {
        $("[id$='_lblErrMsg1']").text("Please select the form type")
        return false;
    }

    else if (!$("[id$='_txt_Formno']").val()) {
        $("[id$='_lblErrMsg1']").text("Please enter the form number")
        return false;
    }
    else {
        var type = $("[id$='_rdbtls_FromType'] input:radio:checked").val();
        var FormNo = $("[id$='_txt_Formno']").val();
        if (isNaN(FormNo)) {
            if (type == '1') {
                $("[id$='_lblErrMsg1']").text("Your Vendor Form number is in the top right corner of your Vendor Form and has 6 digits. Please enter your 6 digit Vendor Form number and try again.")
                return false;
            }
            else if (type == '2') {
                $("[id$='_lblErrMsg1']").text("Your Tender Form number is in the top right corner of your Tender Form and has 5 digits. Please enter your 5 digit Tender Form number and try again.")
                return false;
            }
        }
        else {

            if (type == '1' && FormNo.length != 6) {
                $("[id$='_lblErrMsg1']").text("Your Vendor Form number is in the top right corner of your Vendor Form and has 6 digits. Please enter your 6 digit Vendor Form number and try again.")
                return false;
            }
            else if (type == '2' && FormNo.length != 5) {
                $("[id$='_lblErrMsg1']").text("Your Tender Form number is in the top right corner of your Tender Form and has 5 digits. Please enter your 5 digit Tender Form number and try again.")
                return false;
            }
        }
    }
    if ($find('MdlPopEx'))
        $find('MdlPopEx').hide();
    return true;
}

function HideMPopup(Popup_id)
{
  if($find(Popup_id))  
    $find(Popup_id).hide(); 
  
}

function ShowMissingForm()
{
  if($find('MdlPopEx'))  
    $find('MdlPopEx').show(); 
  
}


function SetTabIndexValue(obj)
{
 if($("[id$='_hidTabIndex']")!=null)
   $("[id$='_hidTabIndex']").val(obj);

}

function RemoveTabIndexValue()
{
 if($("[id$='_hidTabIndex']")!=null)
   $("[id$='_hidTabIndex']").val(null);
  
}

function SetTabIndex()
{
 if($("[id$='_hidTabIndex']")!=null)
 var indx=$("[id$='_hidTabIndex']").val()
  if(indx)
  {
     if($('#jtab_div').tabs().find('li').eq(indx))
    $('#jtab_div').tabs().find('li').eq(indx).find('a').trigger('click'); 
  
   }
 if ($("[id$='_HdnMaxDateDiff']").val()) {
     var objid = $("[id$='_collectdate_txt']");
     var txtid = objid[0].id;
     $("#" + txtid).datepicker();
     $("#" + txtid).datepicker("option", "dateFormat", 'dd/mm/yy');
     $("#" + txtid).datepicker("option", "minDate", -0);
     $("#" + txtid).datepicker("option", "maxDate", $("[id$='_HdnMaxDateDiff']").val());
     $("[id$='_collectdate_txt']").val('');
 }
 
}

function SetJTabIndex(hiden_id)
{
  var indx=0;
  if(document.getElementById(hiden_id)!=null)
   indx=document.getElementById (hiden_id).value;
  if($('#jtab_div').tabs().find('li').eq(indx))
    $('#jtab_div').tabs().find('li').eq(indx).find('a').trigger('click'); 
  if($find('PopEx_UCVendor'))  
    $find('PopEx_UCVendor').hide();
  
}

function HidePopup(txtPassword_id,lblMsg_id,PopEx_id)
{  
  if($find(PopEx_id))  
    $find(PopEx_id).hide(); 
    return true ;
}

function LookinCorrect_validation()
{
   if(!$("[id$='_Rdbtn_Reason'] input:radio:checked").val())
   {
        $("[id$='_LblLookMsg']").text("please select the option")
          return false ;
   }
   
   else if(!$("[id$='_txtReason']").val())
   {
      $("[id$='_LblLookMsg']").text("Please enter the reason")
          return false ;
   }
   else 
   {
     if($find('PopEx_UCTform'))
        $find('PopEx_UCTform').hide(); 
   }
   
   return true ;
}



function Tender_Validation()
{
  if(!$("[id$='_txtAmount']").val())
   {
      $("[id$='_lblErrMsg1']").text("Please enter the tender amount")
          return false ;
   }
   else if($("[id$='_txtAmount']").val())
   {
       if(!IsDollar($("[id$='_txtAmount']").val()))
       {
          if($("[id$='_lblErrMsg1']"))
               $("[id$='_lblErrMsg1']").text("Please enter the valid tender amount");         
          return false ; 
       }
   }
    if(!$("[id$='_txtPassword']").val())
   {
       $("[id$='_lblErrMsg1']").text("Please enter your password")
          return false ;
   }
   
   if($find('PopEx_UCTform'))
        $find('PopEx_UCTform').hide(); 
   return true ;     
}


function validateNegotiation(mode)
{ 
  var NegAmt="",BidAmt="",ResAmt="",lblErrMsg="";
  
  if($("[id$='_lblBAmt']").text())  
       BidAmt=$("[id$='_lblBAmt']").text();
       
  if($("[id$='_lblResAmt']").text())  
       ResAmt=$("[id$='_lblResAmt']").text();

   if (mode == 'yesno') {

       if ($("[id$='rbtNeg']").is(':checked')) {

           if ($("[id$='_txtNegAmt']").val())
               NegAmt = $("[id$='_txtNegAmt']").val();
           else {
               $("[id$='_lblErrMsg2']").text("Please enter the Negotiation amount")
               return false;
           }
       }
       else {
           NegAmt = $('.rbtneg :radio:checked').val();
       }

       //end if rbt neg checked

       if (!$("[id$='rbtDoNotNeg']").is(':checked')) {
           if (!$("[id$='_txtNeg_pwd']").val()) {
               $("[id$='_lblErrMsg2']").text("Please enter your password")
               return false;
           }



           if (NegAmt != "" && BidAmt != "" && ResAmt != "") {
               if ($("[id$='_lblErrMsg2']"))
                   $("[id$='_lblErrMsg2']").text(" ");
               if (IsDollar(NegAmt)) {
                   if (parseFloat(NegAmt) >= parseFloat(ResAmt)) {
                       if ($("[id$='_lblErrMsg2']"))
                           $("[id$='_lblErrMsg2']").text("Whoa! That is more than your reserve!");
                       return false;

                   }
                   else if (parseFloat(NegAmt) <= parseFloat(BidAmt)) {

                       if ($("[id$='_lblErrMsg2']"))
                           $("[id$='_lblErrMsg2']").text("Whoa! They offered you more than that!");
                       return false;

                   }
               }
               else {
                   if ($("[id$='_lblErrMsg2']"))
                       $("[id$='_lblErrMsg2']").text("You have entered an invalid negotiation amount");
                   return false;
               }
           }
       }  //end if rbt do not neg checked

   } //end if mode yesno
   else if (mode == 'yes') {
       if ($("[id$='rbtNegotiate']").is(':checked')) {

           if ($("[id$='_txtNegotiableAmt']").val())
               NegAmt = $("[id$='_txtNegotiableAmt']").val();
           else {
               $("[id$='_lblErrMsg3']").text("Please enter the Negotiation amount")
               return false;
           }
       } else {
           NegAmt = $('.rbtneg :radio:checked').val();
       }

       if (!$("[id$='rbtDoNotNegotiate']").is(':checked')) {
           if (!$("[id$='_txtNegotiablePwd']").val()) {
               $("[id$='_lblErrMsg3']").text("Please enter your password")
               return false;
           }



           if (NegAmt != "" && BidAmt != "" && ResAmt != "") {
               if ($("[id$='_lblErrMsg3']"))
                   $("[id$='_lblErrMsg3']").text('');
               if (IsDollar(NegAmt)) {

                   if (parseFloat(NegAmt) >= parseFloat(ResAmt)) {
                       if ($("[id$='_lblErrMsg3']"))
                           $("[id$='_lblErrMsg3']").text('Whoa! That is more than your reserve!');
                       return false;

                   }
                   else if (parseFloat(NegAmt) <= parseFloat(BidAmt)) {
                       if ($("[id$='_lblErrMsg3']"))
                           $("[id$='_lblErrMsg3']").text('Whoa! They offered you more than that!');
                       return false;

                   }
               }
               else {
                   if ($("[id$='_lblErrMsg3']"))
                       $("[id$='_lblErrMsg3']").text('You have entered an invalid negotiation amount');
                   return false;
               }
           }
       } //end if rbt do not neg checked
   }  //end if mode yes 

   if($find('PopEx_UCVendor'))  
    $find('PopEx_UCVendor').hide();
 return true ;
}


function IncreaseBidAmt_validation()
{
  var increaseAmt=0;
  var NegAmt=0; 
     if($("[id$='_lblHiBidAmt']").text())      
       increaseAmt=$("[id$='_lblHiBidAmt']").text();
  
 
    if($("[id$='RdBtnNegAmt_txt']").is(':checked') && $("[id$='_txtNegAmt_YesNo']").val()) 
    { 
       NegAmt=$("[id$='_txtNegAmt_YesNo']").val();
       if (!IsDollar(NegAmt)) {
           $("[id$='_lblErrMsg3']").text('You have entered an invalid negotiation amount');
           return false;
       }
       else {
           if (parseFloat(NegAmt) < parseFloat(increaseAmt)) {
               $("[id$='_lblErrMsg3']").text('Sorry, you need to increase your offer by more than that! Please increase your offer to at least $' + increaseAmt);
               return false;
           }
       }
    }
    else {
        if (!$("[id$='RdBtnNegAmt_75']").is(':checked') && !$("[id$='RdBtnNegAmt_50']").is(':checked') && !$("[id$='RdBtnNegAmt_25']").is(':checked') && !$("[id$='RdBtnNegAmt_no']").is(':checked')) {
            $("[id$='_lblErrMsg3']").text('Please select/enter the Tender Amount');
            return false;
        }
    } 
               
 
if ($find('PopEx_UCTform'))
    $find('PopEx_UCTform').hide(); 
 return true ;
}


var TNeg_clrtm;
var TNotifSucc_clrtm;
var Atten_clrtm;
var Atten;
var TNotifSucc;
var TNeg;
var Flsahtxt=1;
function ChangeTextColor(objID,strType)
{
  if(objID)
  {
     if(strType=='lnkBuyHighWin')
     {
       TNeg=document.getElementById(objID);
         if(TNeg_clrtm)
          clearTimeout(TNeg_clrtm);
       TNeg_setFocus(1)
     }
     else if(strType=='lnkSellAtten')
     {
       Atten=document.getElementById(objID);
         if(Atten_clrtm)
           clearTimeout(Atten_clrtm);
       Atten_setFocus(1) 
     }
     else if(strType=='lnkBuyWon')
     {
       TNotifSucc=document.getElementById(objID);
       if(TNotifSucc_clrtm)
        clearTimeout(TNotifSucc_clrtm);
       TNotifSucc_setFocus(1)
     }
  }
}

function RemoveTextColor()
{  
   if(TNotifSucc_clrtm)
   {
       clearTimeout(TNotifSucc_clrtm);
       if(TNotifSucc)
       {
          TNotifSucc.style.color='#0048E6';
          TNotifSucc=null;
       }
   }
}

function TNeg_setFocus(valu)
{
  if(TNeg)
   {
      if(!TNeg.style.fontWeight || (TNeg.style.fontWeight=='normal'))
       {
         if(valu==1)
          {
             TNeg.style.color='red';
             TNeg_clrtm=setTimeout('TNeg_setFocus(0)',900);
           } 
         else
          {
            TNeg.style.color='#0048E6';
            TNeg_clrtm=setTimeout('TNeg_setFocus(1)',900);
          }
       }
      else 
      {
         if(TNeg_clrtm)
         clearTimeout(TNeg_clrtm);
      }
   }
}


function Atten_setFocus(valu)
{
  if(Atten)
   {
      if(!Atten.style.fontWeight || (Atten.style.fontWeight=='normal'))
       {
         if(valu==1)
          {
             Atten.style.color='red';
             Atten_clrtm=setTimeout('Atten_setFocus(0)',900);
           } 
         else
          {
            Atten.style.color='#0048E6';
            Atten_clrtm=setTimeout('Atten_setFocus(1)',900);
          }
       }
      else 
      {
         if(Atten_clrtm)
         clearTimeout(Atten_clrtm);
      }
   }
}

function SetTNotifSucc_hdfldVal()
{
  if($("[id$='_TNotifSucc_hdfld']"))
    $("[id$='_TNotifSucc_hdfld']").val(1)
}

function TNotifSucc_setFocus(valu)
{
  if($("[id$='_TNotifSucc_hdfld']"))
    if($("[id$='_TNotifSucc_hdfld']").val())
     Flsahtxt=$("[id$='_TNotifSucc_hdfld']").val();
  if(TNotifSucc && Flsahtxt==1)
   {
      if(!TNotifSucc.style.fontWeight || (TNotifSucc.style.fontWeight=='normal'))
       {
         if(valu==1)
          {
             TNotifSucc.style.color='red';
             TNotifSucc_clrtm=setTimeout('TNotifSucc_setFocus(0)',900);
           } 
         else
          {
            TNotifSucc.style.color='#0048E6';
            TNotifSucc_clrtm=setTimeout('TNotifSucc_setFocus(1)',900);
          }
       }
      else 
      {
         if(TNotifSucc_clrtm)
         clearTimeout(TNotifSucc_clrtm);
      }
   }

}

function showHide(bshow) {
    $("[id$='_datecal_div']").attr('style', 'display:' + bshow);
}


function showCollect(StoreID, lastviewdate, datediff, maxdatediff, CloseDate)
{
   
    if ($("[id$='_collectdate_txt']")) {
        var objid = $("[id$='_collectdate_txt']");
        var idPrefix = objid[0].id;
        idPrefix = idPrefix.substring(0, (idPrefix.lastIndexOf("_collectdate_txt") + 1));
        
        document.getElementById(idPrefix + 'collectdate_txt').value = "";
        document.getElementById(idPrefix + 'Today_rdbtn').checked = false;
        document.getElementById(idPrefix + 'Friday_rdbtn').checked = false;
        document.getElementById(idPrefix + 'Saturday_rdbtn').checked = false;
        document.getElementById(idPrefix + 'Laterthansaturday_rdbtn').checked = false;
        document.getElementById(idPrefix + 'Todaydate_hdfld').value = "";
        document.getElementById(idPrefix + 'Fridaydate_hdfld').value = "";
        document.getElementById(idPrefix + 'saturdaydate_shdfld').value = "";
        showHide("none");
        document.getElementById(idPrefix + 'storeid_hdfld').value = "";
        document.getElementById(idPrefix + 'msgCollectdate_div').style.display = "none";
        document.getElementById(idPrefix + 'msgCollectdate_div').innerHTML = "";

        document.getElementById(idPrefix + 'HdnMaxDateDiff').value = maxdatediff;
        document.getElementById(idPrefix + 'HdnCloseDate').value = CloseDate;

        var dateParts = lastviewdate.split("/");
        var lastviewdate = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
        var Fd = new Date();
        var Sd = new Date();
        var Td = new Date();
        Td.setDate(lastviewdate.getDate() + 1);
        Fd.setDate(lastviewdate.getDate() + 2);
        Sd.setDate(lastviewdate.getDate() + 3);
        document.getElementById(idPrefix + 'storeid_hdfld').value = StoreID;
        document.getElementById(idPrefix + 'HdnCollectionType').value = 0;

        if (parseInt(datediff) < 0) {
            if (parseInt(datediff) == -2) {
                $('#Friday_div').attr('style', 'display:none');
                document.getElementById(idPrefix + 'Todaydate_hdfld').value =toShortDateString(Fd);
                document.getElementById(idPrefix + 'saturdaydate_shdfld').value =toShortDateString(Sd);
            }
            else if (parseInt(datediff) == -3) {
                $('#Friday_div').attr('style', 'display:none');
                $('#Saturday_div').attr('style', 'display:none');
                document.getElementById(idPrefix + 'Todaydate_hdfld').value =toShortDateString(Sd); 
            }
            else if (parseInt(datediff) == -1) {
                document.getElementById(idPrefix + 'Todaydate_hdfld').value =toShortDateString(Td);
                document.getElementById(idPrefix + 'Fridaydate_hdfld').value =toShortDateString( Fd);
                document.getElementById(idPrefix + 'saturdaydate_shdfld').value =toShortDateString(Sd);
            }
            else {
                $('#Today_div').attr('style', 'display:none');
                $('#Friday_div').attr('style', 'display:none');
                $('#Saturday_div').attr('style', 'display:none');
                $('#LSaturday_div').attr('style', 'display:none');
                initializeDatepicker();
            }
        }

        if ($find('Collect_UCTform'))
            $find('Collect_UCTform').show();
    }
}

function toShortDateString(dateVal) {
    var dateString = '00/00/0000';
    var dt = dateVal.getDate();
    var mn = dateVal.getMonth() + 1;
    if (dt < 10)
        dt = '0' + dt.toString();
    if (mn < 10)
        mn = '0'+ mn.toString();
    dateString = dt + '/' + mn + '/' + dateVal.getFullYear().toString();
    return dateString;
}

function initializeDatepicker() {
    var objid = $("[id$='_collectdate_txt']");
    var txtid = objid[0].id;
    $("#" + txtid).datepicker();
    $("#" + txtid).datepicker("option", "dateFormat", 'dd/mm/yy');
    $("#" + txtid).datepicker("option", "minDate", -0);
    $("#" + txtid).datepicker("option", "maxDate", $("[id$='_HdnMaxDateDiff']").val());
    showHide("block"); 
}

function ValidateCollectiondate(idPrefix)
{
  var ObjDate=document.getElementById(idPrefix + 'collectdate_txt');
  if (document.getElementById(idPrefix + 'HdnCollectionType').value == 0)
 {
     if (document.getElementById(idPrefix + 'Today_rdbtn').checked == false && document.getElementById(idPrefix + 'Friday_rdbtn').checked == false && document.getElementById(idPrefix + 'Saturday_rdbtn').checked == false && document.getElementById(idPrefix + 'Laterthansaturday_rdbtn').checked == false && ObjDate.value == "")
   {
    document.getElementById(idPrefix+'msgCollectdate_div').style.display="block";
    document.getElementById(idPrefix+'msgCollectdate_div').innerHTML="please select the collection date";
    return false ;
   }
   else if (document.getElementById(idPrefix + 'Laterthansaturday_rdbtn').checked == true && ObjDate.value == "")
   {
      document.getElementById(idPrefix+'msgCollectdate_div').style.display="block";
     document.getElementById(idPrefix+'msgCollectdate_div').innerHTML="please select the collection date";
    return false ;
   }
 }
 else if (ObjDate.value == "")
   {
      document.getElementById(idPrefix+'msgCollectdate_div').style.display="block";
      document.getElementById(idPrefix+'msgCollectdate_div').innerHTML="please select the collection date";
      return false ;
   }
   if (ObjDate.value != "")
   {
       if (!checkDate(ObjDate)) {
             document.getElementById(idPrefix+'msgCollectdate_div').style.display="block";
             document.getElementById(idPrefix+'msgCollectdate_div').innerHTML= 'You have entered an invalid collection date ' ;
            return false;
          }
          else
          {
            var dateParts = ObjDate.value.split("/");
            var cldate=new Date(dateParts[2], (dateParts[1] - 1) ,dateParts[0]);
            var crDate = new Date();
            crDate.setFullYear(crDate.getFullYear());           
            crDate.setHours(0,0,0,0);
            if( cldate < crDate)
           {
              document.getElementById(idPrefix+'msgCollectdate_div').style.display="block";
              document.getElementById(idPrefix+'msgCollectdate_div').innerHTML= 'You have entered an invalid collection date ' ;
              return false;
           }
          }


      }

        if (document.getElementById(idPrefix +'HdnCloseDate').value) {
            var closeDates = document.getElementById(idPrefix +'HdnCloseDate').value.split(",")
          if (closeDates.length > 0 && ObjDate.value!="") {
              if (closeDates.contains(ObjDate.value)) {
                  document.getElementById(idPrefix + 'msgCollectdate_div').style.display = "block";
                  document.getElementById(idPrefix + 'msgCollectdate_div').innerHTML = 'The store will be closed on that date,please select some other day ';
                  return false;
              }

          }
          
      }
  if($find('Collect_UCTform'))  
    $find('Collect_UCTform').hide();
 return true ;
 
 
}

Array.prototype.contains = function(needle) {
    for (i in this) {
        if (this[i] == needle) return true;
    }
    return false;
}

function showChangeCollect(Storeid, MaxDateDiff, CloseDate)
{
    $('#Today_div').attr('style','display:none');
    $('#Friday_div').attr('style','display:none');
    $('#Saturday_div').attr('style','display:none');
    $('#LSaturday_div').attr('style', 'display:none');
    $("[id$='_HdnCollectionType']").val(1);
    $("[id$='_HdnMaxDateDiff']").val(MaxDateDiff);
    $("[id$='_HdnCloseDate']").val(CloseDate);
    $("[id$='_storeid_hdfld']").val(Storeid);
    $("[id$='_msgCollectdate_div']").attr('style', 'display:none');
    $("[id$='_msgCollectdate_div']").text('');
    $("[id$='_collectdate_txt']").val('');
    initializeDatepicker();
  if($find('Collect_UCTform'))  
    $find('Collect_UCTform').show(); 
}
