﻿
/*---------------------------------------------------------------
name        : fst_ValidatePasswords
description : 
----------------------------------------------------------------- */
function fst_ValidatePasswords()
{
    fst_HideError('validationerror');
    var pwd = '';
    var pwdrem = '';
    var oldpwd = '';   
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    if($(inputPrefix + 'txtPwd'))
    {
        pwd = $(inputPrefix + 'txtPwd').value;
    }   
    
    if($(inputPrefix + 'txtPwdConfirm'))
    {
        pwdrem = $(inputPrefix + 'txtPwdConfirm').value;
    }

    if($(inputPrefix + 'txtOriginalPwd'))
    {
        oldpwd = $(inputPrefix + 'txtOriginalPwd').value;
    }

    if(!fst_IsPwdCorrectLength(pwd))
    {
        fst_ShowError('validationerror','Password is less than 6 or greather than 50 characters');
        return false;
    }

    if(!fst_DoPasswordsMatch(pwd,pwdrem))
    {
        fst_ShowError('validationerror','Passwords do not match');
        return false;
    }
    
    if(!fst_IsValidPassword(pwd))
    {
        fst_ShowError('validationerror','Invalid password');
        return false;
    }
    if(!fst_IsValidPasswordNumber(pwd))
    {
        fst_ShowError('validationerror','Passwords must contain at least one number and one character.');
        return false;
    }
    if(!fst_IsValidPasswordCharacter(pwd))
    {
       fst_ShowError('validationerror','Passwords must contain at least one number and one character.');
       return false;
    }
    if(!fst_DoPasswordsMatchWithOrignalPassword(oldpwd,pwd))
    {
       fst_ShowError('validationerror','New password should not be same as your original password ');
       return false;
    }
    
    return true;
}
/*---------------------------------------------------------------
name        : fst_IsCorrectPhotoType
description : validation for Image type 
----------------------------------------------------------------- */
function fst_IsCorrectPhotoType(str)
{       
    if(str != '' && str != null)
    {
        if(str.lastIndexOf(".") != -1)
        {
            var ftype = str.substring(str.lastIndexOf(".")+1);

            if(ftype != "JPG" && ftype != "jpg" && ftype != "gif" && ftype != "GIF")
            {
                return false;
            }
        }   
        else
        {
            alert("Unknown File type");
            return false;
        }
    }

    return true;
}
/*---------------------------------------------------------------
name        : fst_IsRequiredField
description : make Required field
----------------------------------------------------------------- */
function fst_IsRequiredField(str)
{       
    if(str.length != 0 && str != null)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/*---------------------------------------------------------------
name        : fst_IsRequiredSelection
description : make Required field for Dropdownbox
----------------------------------------------------------------- */
function fst_IsRequiredSelection(str)
{       
    if(str != 0 && str != null)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/*---------------------------------------------------------------
name        : fst_ValidateEntriesForProfileLink()
description : For Link Profile
----------------------------------------------------------------- */
function fst_ValidateEntriesForProfileLink()
{
    
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    //Make First Name Field as Required
    if(document.getElementById(inputPrefix + 'txtName') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtName').value))
        {
            alert("Please enter a Name");
            document.getElementById(inputPrefix + 'txtName').focus();
            document.getElementById(inputPrefix + 'txtName').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    //Make First URL Field as Required
    if(document.getElementById(inputPrefix + 'txtURL') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtURL').value))
        {
            alert("Please enter a valid URL");
            document.getElementById(inputPrefix + 'txtURL').focus();
            document.getElementById(inputPrefix + 'txtURL').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }

}

/*---------------------------------------------------------------
name        : fst_ValidateEntriesForProfile()
description : For Basic Profile
----------------------------------------------------------------- */
function fst_ValidateEntriesForProfile()
{   
 
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    //Make First Name Field as Required
    if(document.getElementById(inputPrefix + 'txtFirstName') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtFirstName').value))
        {
            alert("Please enter your First Name");
            document.getElementById(inputPrefix + 'txtFirstName').focus();
            document.getElementById(inputPrefix + 'txtFirstName').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    //Make Last Name Field as Required
    if(document.getElementById(inputPrefix + 'txtLastName') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtLastName').value))
        {
            alert("Please enter your Last Name");
            document.getElementById(inputPrefix + 'txtLastName').focus();
            document.getElementById(inputPrefix + 'txtLastName').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    /*
    //Make Company Name Field as Required
    if(document.getElementById(inputPrefix + 'txtCompanyName') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtCompanyName').value))
        {
            alert("Please enter your Company Name");
            document.getElementById(inputPrefix + 'txtCompanyName').focus();
            document.getElementById(inputPrefix + 'txtCompanyName').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    */
    
    //Make Zip/Postal Code Field as Required
    if(document.getElementById(inputPrefix + 'txtZip') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtZip').value))
        {
            alert("You must enter a Zip/Postal Code Name");
            document.getElementById(inputPrefix + 'txtZip').focus();
            document.getElementById(inputPrefix + 'txtZip').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    //Make Country Type Field Required
    if(document.getElementById(inputPrefix + 'ddlCountry') != null)
    {
        if(!fst_IsRequiredSelection(document.getElementById(inputPrefix + 'ddlCountry').value))
        {
            alert("You must select a Country");
            document.getElementById(inputPrefix + 'ddlCountry').focus();
            document.getElementById(inputPrefix + 'ddlCountry').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
}
/*---------------------------------------------------------------
name        : fst_ValidateEntriesForArticles()
description : 
----------------------------------------------------------------- */
function fst_ValidateEntriesForArticles()
{   

    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    if(fst_ValidateRegisterEntries())
    {
    
        //Make Article Title Field Required
        if(document.getElementById(inputPrefix + 'txtTitle') != null)
        {
            if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtTitle').value))
            {
                alert("You must enter a valid Title");
                document.getElementById(inputPrefix + 'txtTitle').focus();
                document.getElementById(inputPrefix + 'txtTitle').style.backgroundColor = '#FFFFCC';
                
                return false;
            }
        }
    }
    else
    {
        return false;
    }
}
/*---------------------------------------------------------------
name        : fst_ValidateEntriesForBlogAndPost()
description : 
----------------------------------------------------------------- */
function fst_ValidateEntriesForBlogAndPost()
{   
    
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    if(fst_ValidateRegisterEntries())
    {
    
        //Make Blog Title Field Required
        if(document.getElementById(inputPrefix + 'txtName') != null)
        {
            if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtName').value))
            {
                alert("You must enter a valid Title");
                document.getElementById(inputPrefix + 'txtName').focus();
                document.getElementById(inputPrefix + 'txtName').style.backgroundColor = '#FFFFCC';
                
                return false;
            }
        }
        
        //Make BlogPost Title Field Required
        if(document.getElementById(inputPrefix + 'txtTitle') != null)
        {
            if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtTitle').value))
            {
                alert("You must enter a valid Title");
                document.getElementById(inputPrefix + 'txtTitle').focus();
                document.getElementById(inputPrefix + 'txtTitle').style.backgroundColor = '#FFFFCC';
                
                return false;
            }
        }
        
         //Make BlogPost Type Field Required
        if(document.getElementById(inputPrefix + 'ddlType') != null)
        {
            if(!fst_IsRequiredSelection(document.getElementById(inputPrefix + 'ddlType').value))
            {
                alert("You must select a Type");
                document.getElementById(inputPrefix + 'ddlType').focus();
                document.getElementById(inputPrefix + 'ddlType').style.backgroundColor = '#FFFFCC';
                
                return false;
            }
        }
    }
    else
    {
        return false;
    }
}

/*---------------------------------------------------------------
name        : fst_ValidateRegisterEntries()
description : 
----------------------------------------------------------------- */
function fst_ValidateRegisterEntries()
{   
    
    fst_HideError("validationerror");
    
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';

    //Validation for Image Type
    if(document.getElementById(inputPrefix + 'filUpload') != null)
    {
        if(!fst_IsCorrectPhotoType(document.getElementById(inputPrefix + 'filUpload').value))
        {
            alert("Invalid File Type. Only JPEG and GIF Image File types are allowed");
            document.getElementById(inputPrefix + 'filUpload').value = '';
            
            return false;
        }
    }
 
    if(document.getElementById(inputPrefix + 'txtEmail') != null)
    {
        if(!fst_ValidateEmail(document.getElementById(inputPrefix + 'txtEmail').value))
        {
            fst_ShowError("validationerror","Invalid email address");
            document.getElementById(inputPrefix + 'txtEmail').focus();
            document.getElementById(inputPrefix + 'txtEmail').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtEmail').style.backgroundColor = '#FFF';
        }
    }
    
    if(document.getElementById(inputPrefix + 'txtFirstName') != null)
    {
        if(!fst_ValidString(document.getElementById(inputPrefix + 'txtFirstName').value,2))
        {
            fst_ShowError("validationerror","Please enter your first name");
            document.getElementById(inputPrefix + 'txtFirstName').focus();
            document.getElementById(inputPrefix + 'txtFirstName').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtFirstName').style.backgroundColor = '#FFF';
        }
    }
    
    if(document.getElementById(inputPrefix + 'txtLastName') != null)
    {
        if(!fst_ValidString(document.getElementById(inputPrefix + 'txtLastName').value,2))
        {
            fst_ShowError("validationerror","Please enter your last name");
            document.getElementById(inputPrefix + 'txtLastName').focus();
            document.getElementById(inputPrefix + 'txtLastName').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtLastName').style.backgroundColor = '#FFF';
        }
    }
       
    if(document.getElementById(inputPrefix + 'txtScreenName') != null)
    {
        if(!fst_ValidString(document.getElementById(inputPrefix + 'txtScreenName').value,5))
        {
            fst_ShowError("validationerror","Please enter a valid screen name. Must be greater than 5 characters");
            document.getElementById(inputPrefix + 'txtScreenName').focus();
            document.getElementById(inputPrefix + 'txtScreenName').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtScreenName').style.backgroundColor = '#FFF';
        }
    }
    
    if(document.getElementById(inputPrefix + 'txtPassword') != null)
    {
        if(!fst_IsPwdCorrectLength(document.getElementById(inputPrefix + 'txtPassword').value))
        {
            fst_ShowError("validationerror","Invalid password length");
            document.getElementById(inputPrefix + 'txtPassword').focus();
            document.getElementById(inputPrefix + 'txtPassword').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtPassword').style.backgroundColor = '#FFF';
        }
        if(!fst_IsValidPasswordNumber(document.getElementById(inputPrefix + 'txtPassword').value))
        {
            fst_ShowError('validationerror','Passwords must contain at least one number and one character.');
            return false;
        }
        if(!fst_IsValidPasswordCharacter(document.getElementById(inputPrefix + 'txtPassword').value))
        {
            fst_ShowError('validationerror','Passwords must contain at least one number and one character.');
            return false;
        }
        
    }
    
    if(document.getElementById(inputPrefix + 'txtPassword') != null && document.getElementById(inputPrefix + 'txtPwdConfirm') != null)
    {
        if(!fst_DoPasswordsMatch(document.getElementById(inputPrefix + 'txtPassword').value,document.getElementById(inputPrefix + 'txtPwdConfirm').value))
        {
            fst_ShowError("validationerror","Passwords do not match");
            document.getElementById(inputPrefix + 'txtPassword').style.backgroundColor = '#FFFFCC';
            document.getElementById(inputPrefix + 'txtPwdConfirm').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'txtPassword').style.backgroundColor = '#FFF';
            document.getElementById(inputPrefix + 'txtPwdConfirm').style.backgroundColor = '#FFF';
        }
    }
    
    if(document.getElementById(inputPrefix + 'chkRegisterTerms') != null)
    {
        if(!document.getElementById(inputPrefix + 'chkRegisterTerms').checked)
        {
            fst_ShowError("validationerror","Please agree terms and conditions");
            document.getElementById(inputPrefix + 'chkRegisterTerms').focus();
            document.getElementById(inputPrefix + 'chkRegisterTerms').style.backgroundColor = '#FFFFCC';
            return false;
        }
        else
        {
            document.getElementById(inputPrefix + 'chkRegisterTerms').style.backgroundColor = '#FFF';
        }
    }
        
    return true;
}

/*---------------------------------------------------------------
name        : fst_ValidateEmailAJAX()
description : 
----------------------------------------------------------------- */
function fst_ValidateEmailAJAX(evt)
{
    if($('ctl00_ctl00_cphContent_cphMainArea_txtEmail'))
    {
        var obj = $('ctl00_ctl00_cphContent_cphMainArea_txtEmail')
        
        if(obj.value.length > 0)
        {
        
            // check it's a valid email address
            if(!fst_ValidateEmail(obj.value))
            {
                var e = $('email-check');
                var i = document.createElement('img');
                
                i.setAttribute('src', FSTPATH + 'images/invalid.gif');
                i.className = 'exists';
                e.innerHTML = '';
                e.appendChild(i);
            }
            else
            {        
                new Ajax.Request(URL_VALIDATEEM,
                {
                  method: 'post',
                  parameters: { email: obj.value },
                  onSuccess: function(transport)
	                {
	                  fst_ActionEmailExists(transport.responseText);
	                },
                  onFailure: function()
	                {
	                  alert('Error checking email address');
	                }
                });	
	        }
	    }
	}
}

/*---------------------------------------------------------------
name        : fst_ValidateScreenNameAJAX()
description : 
----------------------------------------------------------------- */
function fst_ValidateScreenNameAJAX(evt)
{
    if($('ctl00_ctl00_cphContent_cphMainArea_txtScreenName'))
    {
        
        var obj = $('ctl00_ctl00_cphContent_cphMainArea_txtScreenName');
        
        // check it's a valid screen name
        
        if(obj.value.length > 5)
        {        
            // create prototype request
	        new Ajax.Request(URL_VALIDATESN,
	        {
	          method: 'post',
	          parameters: { scrname: obj.value },
	          onSuccess: function(transport)
		        {
		          fst_ActionScreenNameExists(transport.responseText);
		        },
	          onFailure: function()
		        {
		          alert('Error checking screen name');
		        }
	        });	
	    }
	}
}

/*---------------------------------------------------------------
name        : fst_ActionEmailExists()
description : 
----------------------------------------------------------------- */
function fst_ActionEmailExists(retVal)
{
    var e = $('email-check');
    var obj = $('ctl00_ctl00_cphContent_cphMainArea_txtEmail');
        
    var i = document.createElement('img');
    e.innerHTML = '';
    
    if(retVal.toLowerCase() == 'true')
    {
        i.setAttribute('src', FSTPATH + 'images/exists.gif');
        i.className = 'exists';
        e.appendChild(i);
    }
    else
    {
        i.setAttribute('src', FSTPATH + 'images/valid.gif');
        i.className = 'exists';
        e.appendChild(i);
    }
}

/*---------------------------------------------------------------
name        : fst_ActionScreenNameExists()
description : 
----------------------------------------------------------------- */
function fst_ActionScreenNameExists(retVal)
{
    var e = $('screenname-check');
    var obj = $('ctl00_cphMainContent_txtScreenName');
    
    var i = document.createElement('img');
    e.innerHTML = '';
    
    if(retVal.toLowerCase() == 'true')
    {
        i.setAttribute('src', FSTPATH + 'images/exists.gif');
        i.className = 'exists';
        e.appendChild(i);
    }
    else
    {
        i.setAttribute('src', FSTPATH + 'images/valid.gif');
        i.className = 'exists';
        e.appendChild(i);
    }
}


/*---------------------------------------------------------------
name        : fst_ValidateComposedMessage()
description : 
----------------------------------------------------------------- */
function fst_ValidateComposedMessage()
{
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
    
    if(document.getElementById(inputPrefix + "txtSubject") != null && document.getElementById(inputPrefix + "txtSubject") != 'undefined')
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + "txtSubject").value))
        {
            
            alert("Subject field cannot be Empty");
            document.getElementById(inputPrefix + "txtSubject").focus();
            return false;
        }
    }

    if(document.getElementById(inputPrefix + "txtMessage") != null && document.getElementById(inputPrefix + "txtMessage") != 'undefined')
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + "txtMessage").value))
        {
            alert("Message field cannot be Empty");
            document.getElementById(inputPrefix + "txtMessage").focus();
            return false;
        }
    }
}

///*---------------------------------------------------------------
//name        : fst_ValidateEntriesForCompany()
//description : For Basic Company Information
//----------------------------------------------------------------- */
function fst_ValidateEntriesForCompany()
{
    var inputPrefix = 'ctl00_ctl00_cphContent_cphMainArea_';
   
    //Make the Name Field as Required
    if(document.getElementById(inputPrefix + 'txtName') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtName').value.replace(/^\s+|\s+$/g, '')))
        {
            alert("You must enter a Name");
            document.getElementById(inputPrefix + 'txtName').focus();
            document.getElementById(inputPrefix + 'txtName').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    //Make Address Field as Required
    if(document.getElementById(inputPrefix + 'txtAddress1') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtAddress1').value.replace(/^\s+|\s+$/g, '')))
        {
            alert("You must enter the address");
            document.getElementById(inputPrefix + 'txtAddress1').focus();
            document.getElementById(inputPrefix + 'txtAddress1').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
     //Make City Field as Required
    if(document.getElementById(inputPrefix + 'txtCity') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtCity').value.replace(/^\s+|\s+$/g, '')))
        {
            alert("You must enter the city");
            document.getElementById(inputPrefix + 'txtCity').focus();
            document.getElementById(inputPrefix + 'txtCity').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    /*
    //Make State Field as Required
    if(document.getElementById(inputPrefix + 'txtState') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtState').value.replace(/^\s+|\s+$/g, '')))
        {
            alert("You must enter the State/Province");
            document.getElementById(inputPrefix + 'txtState').focus();
            document.getElementById(inputPrefix + 'txtState').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    */
    
    //Make Zip/Postal Code Field as Required
    if(document.getElementById(inputPrefix + 'txtZip') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtZip').value.replace(/^\s+|\s+$/g, '')))
        {
            alert("You must enter a Zip/Postal Code Name");
            document.getElementById(inputPrefix + 'txtZip').focus();
            document.getElementById(inputPrefix + 'txtZip').style.backgroundColor = '#FFFFCC';
            
            return false;
        }        
    }
    //Make Country Type Field Required
    if(document.getElementById(inputPrefix + 'ddlCountry') != null)
    {
        if(!fst_IsRequiredSelection(document.getElementById(inputPrefix + 'ddlCountry').value))
        {
            alert("You must select a Country");
            document.getElementById(inputPrefix + 'ddlCountry').focus();
            document.getElementById(inputPrefix + 'ddlCountry').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    
    /*
    if(document.getElementById(inputPrefix + 'txtTelephone1') != null)
    {
        if(!fst_IsRequiredField(document.getElementById(inputPrefix + 'txtTelephone1').value))
        {
            alert("You must enter a Telephone Number");
            document.getElementById(inputPrefix + 'txtTelephone1').focus();
            document.getElementById(inputPrefix + 'txtTelephone1').style.backgroundColor = '#FFFFCC';
            
            return false;
        }
    }
    */
}

