﻿
//-----------------javascript to set div position------------------------


function setPosition(divName)
{ 
    
      var objYes = document.getElementById(divName);
      if(divName=="divErrorDisplay")
      {
   
      if(screen.width==1024)
        {
        objYes.style.position="absolute";
        objYes.style.top="330px";
        objYes.style.left="240px";
        }
        else if(screen.width==1280)
        {
        objYes.style.position="absolute";
        objYes.style.top="330px";
        objYes.style.left="368px";
        }
        else
        {
        objYes.style.position="absolute";
        objYes.style.top="330px";
        objYes.style.left="240px";
        }
    }
    if(divName=="divHomePagePreview")
    {
    
         if(screen.width==1024)
        {
        objYes.style.position="absolute";
        objYes.style.top="140px";
        objYes.style.left="240px";
        }
        else if(screen.width==1280)
        {
        objYes.style.position="absolute";
        objYes.style.top="140px";
        objYes.style.left="368px";
        }
        else
        {
        objYes.style.position="absolute";
        objYes.style.top="140px";
        objYes.style.left="240px";
        }
        }
}


//----------------------------------------------------------------------------------------------------------------
//--------------------this function showHide ErrorMessageDIV 'divErrorDisplay' in delete profile page-------------//
function ShowHidedivErrorMSG()
{
  
    var objErrorDiv= document.getElementById('divErrorDisplay');
    if(objErrorDiv != null)
    {
        if(objErrorDiv.style.display=='block')
        {
             objErrorDiv.style.display = 'none';
        }
       else
       {
           objErrorDiv.style.display ='block';
       }       
    }   

}




//-----------------------MasterDiv  Functions-----------------------------------------
function ShowHideMasterDiv()
{
  
    var objDiv= document.getElementById(MasterDivGray);
    if(objDiv != null)
    {
        if(objDiv.style.visibility=='visible')
        {
             objDiv.style.visibility = 'hidden';
        }
       else
       {
           objDiv.style.visibility ='visible';
       }
        SetMasterDivPosition(objDiv);
    }
    
}


function SetMasterDivPosition(objDiv)
{
    //Dhara:added for 
   if (window.innerHeight > 0 && window.scrollMaxY <= 0)
    { //firexox
       
         yWithScroll = window.innerHeight + "px"
         xWithScroll = window.innerWidth + "px";
        
    } 
    else if(window.scrollMaxY > 0)
    { //firexox
       
        yWithScroll = parseInt(window.innerHeight) + parseInt(window.scrollMaxY);
        yWithScroll = yWithScroll + "px";
        xWithScroll = window.innerWidth + "px";
    }
    else if (document.body.scrollHeight > document.documentElement.clientHeight)
    { // all but Explorer Mac  
       
        yWithScroll = document.body.scrollHeight;         
        xWithScroll = document.body.scrollWidth;   
        
    } 
    else 
    { // works in Explorer 6 Strict, Mozilla (not FF) and Safari     
        //alert(document.body.scrollHeight-document.documentElement.clientHeight);
          yWithScroll =  document.documentElement.clientHeight;
           xWithScroll = document.documentElement.clientWidth;     
         
    } 
    //alert(yWithScroll);   
   // alert(yWithScroll);
   // alert(xWithScroll);
    objDiv.style.position="absolute";
    objDiv.style.top="0px";
    objDiv.style.left="0px"; 
    objDiv.style.width=xWithScroll;
    objDiv.style.height=yWithScroll; 
    objDiv.style.overflow="hidden";
}

//------------------prwview homepage ---------------------------------//
function ShowHomePagePreviewDiv(divToShow)
{
    setPosition(divToShow);    
    var objDivShow = document.getElementById(divToShow);
    if(objDivShow != null)
    {
        if(objDivShow.style.display=='none')
        {
            objDivShow.style.display='block'; 
            var objedEdit = GetRadEditor(rHomePage).GetHtml();
            document.getElementById(lblPreviewHomePageBody).innerHTML=objedEdit;    
        }
        else
        {
            objDivShow.style.display='none';
        }
    }
}

function ShowHideStepsFromImage(divtoshow)
{
    var objDivContainer = document.getElementById('StepContainer');
    var objregex = new RegExp("step");
    var strIdName;
    
    if(objDivContainer != null)
    {
        var divList = objDivContainer.getElementsByTagName("div");
        for(var i = 0; i < divList.length; i++)
        {
            strIdName = divList[i].id;
            if(strIdName.match(objregex))
            {
                if(strIdName == divtoshow)
                    document.getElementById(strIdName).style.display = 'block';
                else
                    document.getElementById(strIdName).style.display = 'none';
            }
       }
    }
}

function ShowHideStepsWithButton(divToValidate, divtoshow)
{
    var isPageValid = Page_ClientValidate(divToValidate);
    if(!isPageValid)
        return false;
    ShowHideStepsFromImage(divtoshow);
}

function CheckAllValidationForRegistration(btnId, divStep1, divStep2, divStep3, divStep4)
{
    var isPageValid = Page_ClientValidate(divStep1);
    if(!isPageValid)
    {
        ShowHideStepsFromImage(divStep1);
        return false;
    }
    
    isPageValid = Page_ClientValidate(divStep2);
    if(!isPageValid)
    {
        ShowHideStepsFromImage(divStep2);
        return false;
    }
    
    isPageValid = Page_ClientValidate(divStep3);
    if(!isPageValid)
    {
        ShowHideStepsFromImage(divStep3);
        return false;
    }
    isPageValid = Page_ClientValidate(divStep4);
    if(!isPageValid)
    {
        ShowHideStepsFromImage(divStep4);
        return false;
    }    
    HideRegClickedControl(btnId);
    return true;
}

function HideRegClickedControl(ctrlID)
{
    setTimeout("HideRegControl('" + ctrlID.id + "');", 0);  
}

function HideRegControl(ctrlID)
{
    ctrlID = document.getElementById(ctrlID);
    ctrlID.disabled = true;
}

function CheckUserName(sender, args) 
 {
    //debugger;
    if(args.Value != '')
    {
        var re = new RegExp(document.getElementById('username_regex').value);
        if (re.exec(args.Value) != null)
            args.IsValid = true;
        else 
             args.IsValid = false;
    }
}

function CheckFirstLastName(sender, args)
{
    if(args.Value != '')
    {
        var re = new RegExp(document.getElementById('fistname_regex').value);
        if (re.exec(args.Value) != null)
            args.IsValid = true;
        else 
            args.IsValid = false;
    }
}

function ShowHideFileUpload() {
    //debugger;
    var docType = $('#' + ddlSpecifyDocument).val();
    //var obj = document.getElementById(ddlSpecifyDocument);
    $('#dvSpecifyDocumentHeader').hide();
    $('#dvDocumentByPDFHeader').hide();
    $('#dvDocumentByFaxHeader').hide();
    $('#dvDocumentByEmailHeader').hide();

    $('#dvSpecifyDocument').hide();
    $('#dvDocumentByPDF').hide();
    $('#dvDocumentByFax').hide();
    $('#dvDocumentByEmail').hide();

    document.getElementById('tdFileUpload').style.visibility = 'hidden';

    if (docType == "-1") { // No document
        $('#dvSpecifyDocumentHeader').show();
        $('#dvSpecifyDocument').show();
    }
    else if (docType == "1") {    // PDF
        $('#dvDocumentByPDFHeader').show();
        $('#dvDocumentByPDF').show();
        document.getElementById('tdFileUpload').style.visibility = 'visible';
    }
    else if (docType == "2") {  // Fax
        $('#dvDocumentByFaxHeader').show();
        $('#dvDocumentByFax').show();
    }
    else if (docType == "3") {  //Email
        $('#dvDocumentByEmailHeader').show();
        $('#dvDocumentByEmail').show();
    }
    
//    if (docType == '1')//PDF file
//        document.getElementById('tdFileUpload').style.visibility = 'visible';
//    //else//Fax or Email
        
}

function EnabledRegistrationButton(chkId, regId)
{
    regId = document.getElementById(regId);
    if (!chkId.checked) {
        regId.disabled = true;
        //regId.attr('disabled', true);
        $('#' + regId.id).removeClass("buttonlink").addClass("buttonlink_disable");
    }
    else {
        regId.disabled = false;
        //regId.attr('disabled', false);
        $('#' + regId.id).removeClass("buttonlink_disable").addClass("buttonlink");
    }
    //regId.disabled = !chkId.checked;    
}

function DisabledRegButton(regId)
{
    regId = document.getElementById(regId);
    regId.disabled = true;
    //regId.attr('disabled', true);
    $('#' + regId.id).removeClass("buttonlink").addClass("buttonlink_disable");   
    
}




//---function to check textbox's maxlength.

// Keep user from entering more than maxLength characters
function doKeypress(control) {
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if (maxLength && value.length > maxLength - 1) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
    }
}
// Cancel default behavior
function doBeforePaste(control) {
    maxLength = control.attributes["maxLength"].value;
    if (maxLength) {
        event.returnValue = false;
    }
}
// Cancel default behavior and create a new paste routine
function doPaste(control) {
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if (maxLength) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}

