//document.frmaddbusiness.getElementById('disparea').style.display="none";
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}



/*
=============================================================
checkEmail : test and return true/false whether the supplied string is a valid email address or not
=============================================================
*/

function checkMail(email)
{
	var str1=email;
	var arr=str1.split('@');
	var eFlag=true;
	if(arr.length != 2)
	{
		eFlag = false;
	}
	else if(arr[0].length <= 0 || arr[0].indexOf(' ') != -1 || arr[0].indexOf("'") != -1 || arr[0].indexOf('"') != -1 || arr[1].indexOf('.') == -1)
	{
			eFlag = false;
	}
	else
	{
		var dot=arr[1].split('.');
		if(dot.length < 2)
		{
			eFlag = false;
		}
		else
		{
			if(dot[0].length <= 0 || dot[0].indexOf(' ') != -1 || dot[0].indexOf('"') != -1 || dot[0].indexOf("'") != -1)
			{
				eFlag = false;
			}

			for(i=1;i < dot.length;i++)
			{
				if(dot[i].length <= 0 || dot[i].indexOf(' ') != -1 || dot[i].indexOf('"') != -1 || dot[i].indexOf("'") != -1 || dot[i].length > 4)
				{
					eFlag = false;
				}
			}
		}
	}
		return eFlag;	
}


function limitLength(element, maxLength)
{
	if (element.value.length > maxLength)
	{
		element.value = element.value.substring(0, maxLength);
		return 0;
	}
}


function openWindow(url,ht,wt)
{
	window.open(url,'','scrollbars=no,menubar=no,height=ht,width=wt,resizable=yes,toolbar=no,location=no,status=no'); 
}


function validateRegistrationForm()
{
    
        var frm = window.document.frmRegistration;
        if(trim(frm.txtUserName.value) == ""){
		        alert("User Name cannot be empty.");
                frm.txtUserName.focus();
				
                return false;
        }else if(frm.txtPassword.value == ""){
                alert("Password cannot be empty.");
                frm.txtPassword.focus();
                return false;
        }else if(frm.txtPassword.value.length < 6){
                alert("Password should be atleast six characters long.");
                frm.txtPassword.focus();
                return false;
        }else if(frm.txtConfirmPassword.value == ""){
                alert("Confirmation Password cannot be empty.");
                frm.txtConfirmPassword.focus();
                return false;
        }else if(frm.txtConfirmPassword.value != frm.txtPassword.value){
                alert("Password and Confirmation Password should match.");
                frm.txtConfirmPassword.select();
                frm.txtConfirmPassword.focus();
                return false;
        }else if(trim(frm.txtFirstName.value) == ""){
                alert("First Name cannot be empty.");
                frm.txtFirstName.focus();
                return false;
        }else if(trim(frm.txtAddress1.value) == ""){
                alert("Address Line 1 cannot be empty.");
                frm.txtAddress1.focus();
                return false;
        }else if(trim(frm.txtCity.value) == ""){
                alert("City cannot be empty.");
                frm.txtCity.focus();
                return false;
        }else if(trim(frm.txtState.value) == ""){
                alert("State cannot be empty.");
                frm.txtState.focus();
                return false;
        }else if(trim(frm.txtZIP.value) == ""){
                alert("ZIP cannot be empty.");
                frm.txtZIP.focus();
                return false;
        }else if(isNaN(frm.txtZIP.value)){
                alert("Please enter a valid ZIP.");
                frm.txtZIP.focus();
                return false;
        }else if(trim(frm.txtPhone.value) == ""){
                alert("Phone cannot be empty.");
                frm.txtPhone.focus();
                return false;
        }else if(trim(frm.txtEmail.value) == ""){
                alert("Email cannot be empty.");
                frm.txtEmail.focus();
                return false;
        }else if(! checkMail(trim(frm.txtEmail.value))){
                alert("Please enter a valid email.");
                frm.txtEmail.select();
                frm.txtEmail.focus();
                return false;
        }

        return true;
}


function checkNewPasswordEntered(){
        var frm = window.document.frmChangePassword;
        if(frm.txtNewPassword.value == ""  || frm.txtConfirmNewPassword.value == ""){
                return false;
        }
        return true;
}
function isAnyPasswordEntered(){
        var frm = window.document.frmChangePassword;
        if(frm.txtOldPassword.value != ""  || frm.txtNewPassword.value != ""  || frm.txtConfirmNewPassword.value != ""){
                return true;
        }
        return false;
}
function isNewPasswordsValid(){
        var frm = window.document.frmChangePassword;
        if(frm.txtNewPassword.value.length < 6){
                alert("New Password should be atleast six characters long.");
                frm.txtNewPassword.focus();
                return false;
        }else if(frm.txtConfirmNewPassword.value != frm.txtNewPassword.value){
                alert("New Password and Confirm New Password should match.");
                frm.txtConfirmNewPassword.select();
                frm.txtConfirmNewPassword.focus();
                return false;
        }
        return true;
}
function validateChangePasswordForm(){
        var frm = window.document.frmChangePassword;
        if(isAnyPasswordEntered()){
                if(frm.txtOldPassword.value == ""){
                        alert("Please enter old password.");
                        frm.txtOldPassword.focus();
                        return false;
                }else if(frm.txtOldPassword.value.length < 6){
                        alert("Old Password should be atleast six characters long.");
                        frm.txtOldPassword.focus();
                        return false;
                }else if(! checkNewPasswordEntered()){
                        alert("Please enter New Password and Confirm New Password.");
                        frm.txtNewPassword.focus();
                        return false;
                }else if(!isNewPasswordsValid()){
                        return false;
                }
        }
        return true;
}
function validateProfileForm()
{
        var frm = window.document.frmProfile;

        if(trim(frm.txtFirstName.value) == ""){
                alert("First Name cannot be empty.");
                frm.txtFirstName.focus();
                return false;
        }else if(trim(frm.txtAddress1.value) == ""){
                alert("Address Line 1 cannot be empty.");
                frm.txtAddress1.focus();
                return false;
        }else if(trim(frm.txtCity.value) == ""){
                alert("City cannot be empty.");
                frm.txtCity.focus();
                return false;
        }else if(trim(frm.txtState.value) == ""){
                alert("State cannot be empty.");
                frm.txtState.focus();
                return false;
        }else if(trim(frm.txtZIP.value) == ""){
                alert("ZIP cannot be empty.");
                frm.txtZIP.focus();
                return false;
        }else if(isNaN(frm.txtZIP.value)){
                alert("Please enter a valid ZIP.");
                frm.txtZIP.focus();
                return false;
        }else if(trim(frm.txtPhone.value) == ""){
                alert("Phone cannot be empty.");
                frm.txtPhone.focus();
                return false;
        }else if(trim(frm.txtEmail.value) == ""){
                alert("Email cannot be empty.");
                frm.txtEmail.focus();
                return false;
        }else if(! checkMail(trim(frm.txtEmail.value))){
                alert("Please enter a valid email.");
                frm.txtEmail.select();
                frm.txtEmail.focus();
                return false;
        }
        return true;
}

/*Display Images------*/
/*
 * Program - Link Preview
 * File Name - link_prev.html
 * Author - ShuvoRim
 * Web site - http://www.shuvorim.tk
 * Email - shuvorim@hotmail.com
 * (c)ShuvoRim Pvt. Ltd. 2002 - 04
 * All rights reserved.
 * ------------------------------
 * Visit our web site for free open
 * source Applications, Applets,
 * Scripts and Games. Please tell
 * us whether you liked it or not!
 * Thank you for using our program.
 */

/*****************************************************
THIS FUNCTION WILL GENERATE THE PREVIEW. IT TAKES 5
ARGUMENTS. THE FIRST ARGUMENT IS REQUIRED. OTHERS ARE
OPTIONAL.
******************************************************/
function getFileSize (fileName) {
  //alert("heree");
   
   //fileNamen="file:\\" +fileName;
      var file = new java.io.File(fileName);
	  alert("filename=="+file);
	  alert("length="+file.length());
}
 
/*function showpic(){
    //document.all.employeerow.style.display="";
	 var Parent=new Array;
       <?
   
    $disp="Parent[0]=1";
	echo $disp;
   ?>
   alert(Parent[0]);
	alert("hello");
     document.getElementById('disparea').style.display="none";
}

function showPreview(url, border, width, height, desc)
{

  border = typeof(border) == "undefined" ? 0 : border;
  width = typeof(width) == "undefined" ? 100 : width;
  height = typeof(height) == "undefined" ? 100 : height;
  desc = typeof(desc) == "undefined" ? "" : desc;
document.getElementById('disparea').style.display="";
  document.getElementById("sp").innerHTML = '<img src="' + url + '" border="' + border + '" width="' + width + '" height="' + height + '"><br>' + desc;

}*/


/***************************************************
THIS FUNCTION WILL CLEAR THE GENERATED PREVIEW. IT
DOES NOT TAKE ANY ARGUMENTS.
****************************************************/
/*function clearPreview()
{

  document.getElementById("sp").innerHTML = "Move you mouse over a link to generate a preview.";

}*/

/*----- End of  Display image priview*-----*/

function loadFields(){
        //document.all.employeerow.style.display="none";
        document.getElementById('employeerow').style.display="none";
        var frm = window.document.frmRegistration;
        var country ="<?=htmlentities($ddlCountry)?>";
        var gender ="<?=htmlentities($ddlGender)?>";
        var education = "<?=htmlentities($ddlEducation)?>";
        if(gender == ""){
                gender = "M";
        }
        if(education == ""){
                education = "GP";
        }
        if(country == ""){
                country = "UnitedStates";
        }
        for(i=0;i<frm.ddlCountry.options.length;i++){
            if(frm.ddlCountry.options[i].text == country){
                        frm.ddlCountry.options[i].selected=true;
                        break;
            }
    }
        for(i=0;i<frm.ddlGender.options.length;i++){
            if(frm.ddlGender.options[i].value == gender){
                        frm.ddlGender.options[i].selected=true;
                        break;
            }
    }
        for(i=0;i<frm.ddlEducation.options.length;i++){
            if(frm.ddlEducation.options[i].value == education){
                        frm.ddlEducation.options[i].selected=true;
                        break;
            }
    }
}

