
// fn to modify user details
function checkModUserDetails(){ 

	document.forms[0].emailID.value = trimSpaces(document.forms[0].emailID.value);
        if(!checkEmail(document.forms[0].emailID.value)) 
		  {
			document.forms[0].emailID.focus();
			return false;
	      }
		  
document.forms[0].CompanyName.value = trimSpaces(document.forms[0].CompanyName.value);
        if(document.forms[0].CompanyName.value.length <= 0) {
                alert("Please enter the Company name");
                document.forms[0].CompanyName.focus();
                return false;
        }
		
document.forms[0].firstName.value = trimSpaces(document.forms[0].firstName.value);
        if(document.forms[0].firstName.value.length <= 0) {
                alert("Please enter the first name");
                document.forms[0].firstName.focus();
                return false;
        }
if (!CheckValidity(document.forms[0].firstName.value.length,document.forms[0].firstName.value,'N'))
			   {
					alert("The field 'First Name' should not accept the character [<,>] and Double quotes\nPlease remove it from the field.\n");
					document.forms[0].firstName.focus();
					return false;
		  	   }
	
}

//fn in open a case  -new user

function chkNewUser(){
	//alert("entered");
	document.forms[0].txtUserName.value = trimSpaces(document.forms[0].txtUserName.value);
        if(document.forms[0].txtUserName.value.length <= 0) {
                alert("Please enter the user name");
                document.forms[0].txtUserName.focus();
                return false;
        }
	
	if (!CheckValidity(document.forms[0].txtUserName.value.length,document.forms[0].txtUserName.value,'U'))
			 {
				alert("The field 'User Name' accept characters, numbers,'_','-' and '*' only.");
				document.forms[0].txtUserName.focus();
				return false;
		  	 }
		
	if(document.forms[0].txtUserName.value.length < 5 || document.forms[0].txtUserName.value.length >15 ) {
                alert("Please enter User name which should be atleast 5 letters and not more than 15 letters");
                document.forms[0].txtUserName.focus();
                return false;
        }
		
	  document.forms[0].txtPassword.value = trimSpaces(document.forms[0].txtPassword.value);
        if(document.forms[0].txtPassword.value.length <= 0) {
                alert("Please enter the password");
                document.forms[0].txtPassword.focus();
                return false;
        }
		if(document.forms[0].txtPassword.value.length <6) {
                alert("Password should contain at least 6 letters");
                document.forms[0].txtPassword.focus();
                return false;
        }
		if (!CheckValidity(document.forms[0].txtPassword.value.length,document.forms[0].txtPassword.value,'U'))
			 {
				alert("The field 'Password' accept characters, numbers,'_','-' and '*' only.");
				document.forms[0].txtPassword.focus();
				return false;
		  	 }
       	document.forms[0].txtCompanyName.value = trimSpaces(document.forms[0].txtCompanyName.value);
        if(document.forms[0].txtCompanyName.value.length <= 0) {
                alert("Please enter the Company Name");
                document.forms[0].txtCompanyName.focus();
                return false;
        }
	document.forms[0].txtEmail.value = trimSpaces(document.forms[0].txtEmail.value);
        if(!checkEmail(document.forms[0].txtEmail.value)) {
                document.forms[0].txtEmail.focus();
                return false;
        }

}






//New user sign up
function checkSignup() 
     {
	 	document.forms[0].userName.value = trimSpaces(document.forms[0].userName.value);
          if(document.forms[0].userName.value.length <= 0) 
		  {
           alert("Please enter the user name");
           document.forms[0].userName.focus();
           return false;
          }
		if (!CheckValidity(document.forms(0).userName.value.length,document.forms(0).userName.value,'U'))
		 {
			alert("The field 'User Name' accept characters, numbers,'_','-' and '*' only.");
			document.forms[0].userName.focus();
			return false;
		 }
    	document.forms[0].txtEmail.value = trimSpaces(document.forms[0].txtEmail.value);
        if(!checkEmail(document.forms[0].txtEmail.value)) 
		  {
			document.forms[0].txtEmail.focus();
			return false;
	      }
    	document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
        if(document.forms[0].password.value.length <= 0) 
		  {
           alert("Please enter the password");
           document.forms[0].password.focus();
           return false;
          }
		if (!CheckValidity(document.forms[0].password.value.length,document.forms[0].password.value,'U'))
		   { alert("The field 'Password' accept characters, numbers,'_','-' and '*' only.");
			 document.forms[0].password.focus();
			 return false;
		   }
        document.forms[0].confirmPassword.value = trimSpaces(document.forms[0].confirmPassword.value);
        if(document.forms[0].password.value != document.forms[0].confirmPassword.value) 
		   {
            alert("confirm Password does not match");
            document.forms[0].confirmPassword.focus();
            return false;
           }
		   

}
//Check  subscribe
function checkSubscribe() {

        document.forms(0).username.value = trimSpaces(document.forms(0).username.value);
        if(document.forms(0).username.value.length <= 0) {
                alert("Please enter the user name");
                document.forms(0).username.focus();
                return false;
        }
		if (!CheckValidity(document.forms(0).username.value.length,document.forms(0).username.value,'U'))
			 {
				alert("The field 'User Name' accept characters, numbers,'_','-' and '*' only.");
				document.newUserLogin.username.focus();
				return false;
		  	 }
	document.forms(0).email.value = trimSpaces(document.forms(0).email.value);
        if(!checkEmail(document.forms(0).email.value)) {
                document.forms(0).email.focus();
                return false;
        }
}
//Change Password Form
function checkPassword() {

        document.forms(0).oldPassword.value = trimSpaces(document.forms(0).oldPassword.value);
        if(document.forms(0).oldPassword.value.length <= 0) {
                alert("Please enter the current password");
                document.forms(0).oldPassword.focus();
                return false;
        }
        document.forms(0).newPassword.value = trimSpaces(document.forms(0).newPassword.value);
        if(document.forms(0).newPassword.value.length <= 0) {
                alert("Please enter the new password");
                document.forms(0).newPassword.focus();
                return false;
        }
		if (!CheckValidity(document.forms(0).newPassword.value.length,document.forms(0).newPassword.value,'U'))
			 {
				alert("The field 'New Password' accept  characters, numbers,'_','-' and '*' only.");
				document.forms(0).newPassword.focus();
				return false;
		  	 }
        document.forms(0).confirmPassword.value = trimSpaces(document.forms(0).confirmPassword.value);
        if(document.forms(0).newPassword.value != document.forms(0).confirmPassword.value) {
                alert("Passwords does not match");
                document.forms(0).confirmPassword.focus();
                return false;
        }
		
		

}

//check user details
function checkUserDetails()
  {
		document.forms[0].emailID.value = trimSpaces(document.forms[0].emailID.value);
        if(!checkEmail(document.forms[0].emailID.value)) 
		  { document.forms[0].emailID.focus();
            return false;
          } 
		document.forms[0].txtEmail2.value = trimSpaces(document.forms[0].txtEmail2.value);
		if (document.forms[0].txtEmail2.value.length>0) 
		   { if(!checkEmail(document.forms[0].txtEmail2.value)) 
		       {
                 document.forms[0].txtEmail2.focus();
                 return false;
               } 
		   }

        document.forms[0].firstName.value = trimSpaces(document.forms[0].firstName.value);
        if(document.forms[0].firstName.value.length <= 0) 
		  {
			alert("Please enter your first name");
			document.forms[0].firstName.focus();
			return false;
	      }
		else
		  {
		    if (!CheckValidity(document.forms[0].firstName.value.length,document.forms[0].firstName.value,'N'))
			   {
					alert("The field 'First Name' should not accept the character [<,>] and Double quotes\nPlease remove it from the field.\n");
					document.forms[0].firstName.focus();
					return false;
		  	   }
	  	  }
}
/*****************************************************************************************/
//open subscribe window
function OpenWindow() {

        sWidth = screen.availWidth;
        sHeight = screen.availHeight;

        sTop = (sHeight-400) / 2;
        sLeft = (sWidth-550 ) / 2;

        x = window.open("subScribe.php", "Subscribe", "width=350,height=200,top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=1");
        x.focus();
        return;
}

// Add to Favorites

 function addToFavorites()
 { 
  var urlAddress = "http://www.initechnologies.com";
 var pageName = " INI Technologies Pvt Ltd - Access to the best of technologies";
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName)
  }
  else
  { 
   alert("Sorry! Your browser doesn't support this function.");
  }
 }

/*****************************************************************************************/


/*****************************************************************************************/
// General Functions
/*****************************************************************************************/
function trimSpaces(stringValue) {
        // Checks the first occurance of spaces and removes them
        for(i = 0; i < stringValue.length; i++) {
                if(stringValue.charAt(i) != " ") {
                        break;
                }
        }
        if(i > 0) {
                stringValue = stringValue.substring(i);
        }

        // Checks the last occurance of spaces and removes them
        strLength = stringValue.length - 1;
        for(i = strLength; i >= 0; i--) {
                if(stringValue.charAt(i) != " ") {
                        break;
                }
        }
        if(i < strLength) {
                stringValue = stringValue.substring(0, i + 1);
        }

        // Returns the string after removing leading and trailing spaces.
        return stringValue;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a string is a valid email address.
/////////////////////////////////////////////////////////////////////////////////////////
function checkEmail(emailString) {
        splitVal = emailString.split('@');

        if(splitVal.length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
        if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
                alert("Please enter a valid email address");
                return false;
        }

        splitDomain = splitVal[1].split('.');
        if(splitDomain.length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
        if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
                alert("Please enter a valid email address");
                return false;
        }
		if (!CheckValidity(emailString.length,emailString,'E'))
		 {
			alert("The field 'Email ID' should not accept the character [<,>] and Double quotes.");
			return false;
		 }
        return true;
}


/////////////////////////////////////////////////////////////////////////////////////////
// Checks For the Cross scripting.
/////////////////////////////////////////////////////////////////////////////////////////

function CheckValidity(slen,stext,stype)
	{  
       for (var i = 0; i < slen; i++)
		{      
       var ch = stext.substring(i, i + 1);  
       if (stype=='E')  // for E mail
		  {
		   if (((ch>="a") && (ch<="z")) || ((ch>="A") && (ch<="Z")) ||
			  (ch=="@") || (ch==".") || (ch=="_") || (ch=="-") || ((ch>=0) && (ch<=9)))	
			 {continue;}	
			else
				{return false ;}
           }
		else if ((stype=='N') || (stype=='R'))   // For Name,Country,Profession,City/State 
		  { 
			 if (((ch>="a") && (ch<="z")) || ((ch>="A") && (ch<="Z")) ||
				(ch==' '))	
				{continue ;}
			 else
				{ return false;}
		  }
		else if ((stype=='A') ||  (stype=='M'))  // For Address ,Message,Country
		    { 
			  if ((ch==">") || (ch=="<") || (stext.charCodeAt(i)==34))    
				{return false;}
			  else
				{continue;}
		  }
		else if ((stype=='P') || (stype=='Z')) // For Phone,Zip Code
		  { 
			 if (((ch>="a") && (ch<="z")) || ((ch>="A") && (ch<="Z")) ||
				(ch=="-") || ((ch>=0) && (ch<=9)) || (ch==","))	
				{ continue;}
			 else
				{return false;}
		  }
		else if (stype=='U')  // for username,password
		  {
			if (((ch>="a") && (ch<="z")) || ((ch>="A") && (ch<="Z"))||
				(ch=="_")||	(ch=="-") || (ch=="*") || ((ch>=0) && (ch<=9)))
				{ continue; }
			else
				{ return false; }
		  }
		else if (stype=='L')  // for URL Links
		  {
			 if (((ch>="a") && (ch<="z")) || ((ch>="A") && (ch<="Z")) ||
				(ch=="-") || ((ch>=0) && (ch<=9)) || (ch=="."))	
				{ continue; }
			else
				{ return false; }
		  }
      }	
      return true ;
    }