﻿/*
/*****************-********************************************************************
* Copyright (c) 2007-2008 Performance Fibers
* All Rights Reserved.
* This work contains trade secrets and confidential material of
* Performance Fibers, and its use or disclosure in whole or in
* part without explicit written permission of Performance Fibers is prohibited.
*
* Company                   : Performance Fibers
* Project Name              : Performance Fibers Internet Site
* Name                      : Validation.js
* Description               : Js file contains generic menu and utility Functions.
* Version Number            : 0.01
* Modification History      :
* Date			Version No.		Modified by 	Modification
* 13-Feb-2009    0.01           Caritor     Initial Version for E-Mail Action
* 17-Dec-2009    1.01           Keane       Modified for SR_9355
/***************************************************************************************
*/
//Added for SR_9355 - Starts
/*
This method is to check Valid Phone Number
*/
function isValidPhoneNum(strPhone)
{
    //var regexpPhone = /^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$/
    var regexpPhone = /^\+{0,1}[\-\(\) 0-9]{1,}$/
    if(regexpPhone.test(trim(strPhone)))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function isDropDownSelect(strVal)
{
    if(strVal == "None")
    {
        return false;
    }
    return true;
}
//Added for SR_9355 - Ends

/*
This method is to check for valid mailid
@param ? strEmail - Email ID
@return ? True - If Email id is Valid
		  False - If Email id is InValid			
*/
function isValidMailId(strEmail)
{
// Test if valid email address, must have @ and .
    var emailReg =
    			/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (emailReg.test(strEmail))
    {
    	return true;
    }
    else 
    {
    	//alert('Please Enter an Valid Email ID');
    	return false;
    }
}

/*
This method is perform to left trim
@param ? strValue - Input String
@return ? strValue - Left trimed String 
*/
function ltrim(strValue) 
{
    while (1)
    {
        if ((strValue.substring(0, 1)) != " ")
        {
        	break;
        }
        strValue = strValue.substring(1, strValue.length);
    }
    return strValue;
}

/*
This method is perform to Right trim
@param ? strValue - Input String
@return ? strValue - Right trimed String 			
*/
function rtrim(strValue)
{    
    while (1) 
    {
        if ((strValue.substring(strValue.length - 1, strValue.length)) != " ")
        {
        	break;
        }
        strValue = strValue.substring(0, strValue.length - 1);
    }
    return strValue;
}
/*
This method is Invokes both Left and Right trim
@param ? strValue - Input String
@return ? strTmp - Left and Right trimed String 			
*/
function trim(strValue) 
{
    var strTmp = ltrim(strValue);
    return rtrim(strTmp);
}
/*
This method is Perform to validate the Null string
@param ? strValue - Input String
@return ? ture if strValue is null else false
*/
function isNull(strValue) 
{
    var strTmp = trim(strValue);
    var subLength = strTmp.length;
    if ( subLength > 0 ) 
   {
    	return false;
   }
   else 
   {
   		return true;
   }
}

function goHome(strValue) 
{     
    var path = ''; 
    var homeRemoved = '';
    path = location.pathname;
    
    if (strValue == 'English')
    {
        if (path.search('default') == -1)
        {   
            homeRemoved = path.replace(path.substr(path.lastIndexOf('/'), path.length - path.lastIndexOf('/')), '');                    
            window.location.href = homeRemoved.replace(homeRemoved.substr(homeRemoved.lastIndexOf('/') + 1, homeRemoved.length - homeRemoved.lastIndexOf('/')), '') + "default.html" 
        }
        else
        {     
            window.location.href = location.href;                  
        }
    }
    else
    {    
        if((strValue == 'Chinese') || (strValue == 'Spanish') || (strValue == 'German') || (strValue == 'French'))
        {
            if (path.search('default') == -1)
            {   
                homeRemoved = path.replace(path.substr(path.lastIndexOf('/'), path.length - path.lastIndexOf('/')), '');        
                window.location.href = homeRemoved.replace(homeRemoved.substr(homeRemoved.lastIndexOf('/') + 1, homeRemoved.length - homeRemoved.lastIndexOf('/')), '') + strValue+ "/home.html" 
            }
            else
            {           
                window.location.href = path.replace((path.substr(path.lastIndexOf('/')+1, path.lastIndexOf('.')- path.lastIndexOf('/')-1 )), strValue+ "/home") ;    
            }
        } 
        else
        {
            document.getElementById('LanguagePopup').style.display='block'; 
            ; 
        }
    }    
}