///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateLostPasswordForm(type)
{
	if (!isNonEmpty(document.form.username)) 
	{
		alert("Invalid username");		
		document.form.username.focus();
		return false;
	}
	
	if (!isNonEmpty(document.form.email)) 
	{
		alert("Invalid email");
		document.form.email.focus();
		return false;
	}
	else
	{
		// -------------------------------------------------------------------------------------
		if (!validateEmail(document.form.email.value)) {
			alert("Invalid email");
			document.form.email.focus();
			return false;
		}
	}
	
	var url = 'lostpassword.php?action=submit&email=' + document.form.email.value +
									'&username=' + document.form.username.value	+
									'&type=' + type;
	
	//alert(url);
	
	window.location=url;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateOwnerLogin()
{
	if (!isNonEmpty(document.ownerlogin.owner)) 
	{
		alert("Invalid owner name");		
		document.ownerlogin.owner.focus();
		return false;
	}
	
	if (!isNonEmpty(document.ownerlogin.password)) 
	{
		alert("Invalid owner password");		
		document.ownerlogin.password.focus();
		return false;
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ChkFormAboutus() 
{
	if (!isNonEmpty(document.form.name)) 
	{
		alert("Invalid name");		
		document.form.name.focus();
		return false;
	}
	
	if (!validateEmail(document.form.email.value)) 
	{
		alert("Invalid email");		
		document.form.email.focus();
		return false;
	}
	
	if (!isNonEmpty(document.form.comment)) 
	{
		alert("Please fill comment");		
		document.form.comment.focus();
		return false;
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateAddress(addr)
{	
	var geo = new GClientGeocoder(); 
	// ====== Perform the Geocoding ======        
    geo.getLocations(addr, function (result)
      { 
        // If that was successful
        if (result.Status.code == G_GEO_SUCCESS) {          
          
		  document.getElementById("addErr").innerHTML = "Address has found (Click here to review)";
		  document.getElementById("addErr").style.cursor ="pointer";
		  
		  
		  //document.getElementById("addErr").innerHTML = "Address has found. <span id=\"addView\" style=\"color:#0000FF; font-weight:bold; cursor:pointer; display:none;\" onclick=\"ViewAddress();\">View</span>";
		  addressStatus = 3;
		  // Loop through the results, placing markers
          for (var i=0; i<result.Placemark.length; i++) {
			var p = result.Placemark[i].Point.coordinates;
			document.form.latitude.value = p[1];
			document.form.longitude.value = p[0];
            break; // show only first
          }		  
        }
        // ====== Decode the error status ======
        else {
          document.getElementById("addErr").innerHTML = "Invalid address.";
		
		  addressStatus = 2;
		    document.form.latitude.value = "";
			document.form.longitude.value = "";
        }
      }
    );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function NavigateFormCommunity(currPart, direction) 
{
	//alert("NavigateFormCommunity");
	var nextEle = "";
	var backEle = "";
	var currEle = ""

	if(currPart == 1)
	{			
		nextEle = "detailinfo";		
		backEle = "";
		currEle = "generalinfo";
		if(direction == 1)
		{
			// General info
			if (!isNonEmpty(document.form.communityName)) 
			{
				alert("Invalid community name");		
				document.form.communityName.focus();
				return false;
			}
		
			// -------------------------------------------------------------------------------------
			if (!isAlphaSpace(document.form.contactName)) 
			{
				alert("Invalid contact name");
				document.form.contactName.focus();
				return false;
			}	
			
			if(document.form.zip.value.trim() != "")
			{
				// -------------------------------------------------------------------------------------
				if (!isZIP(document.form.zip)) {
					alert("Invalid zip code");
					document.form.zip.focus();
					return false;
				}
			}
		
			
			// -------------------------------------------------------------------------------------
			if (!isAddress(document.form.address)) 
			{
				alert("Invalid address");
				document.form.address.focus();
				return false;
			}
			
			//addressErr - Invalid Address
			//addressStatus - 0			
			if(addressStatus == 0) // not check before
			{
				addressStatus = 1 // Move to checking status
				//document.getElementById("addErr").innerHTML = "Validating address...";
				//alert("Validate address");
				var addr = document.form.address.value + ' ' + 
						   document.form.city.value + ' ' + 
						   document.form.state.value + ' ' + 
						   document.form.zip.value + ' ' + 
						   document.form.country.value;
				//alert(addr);
				ValidateAddress(addr);
				return false;
			}
			else if (addressStatus == "1") // Checking)
			{
				alert("Address is being validated... please wait a munite.");
				return false;
			}
			else if (addressStatus == "2") // Invalid)
			{
				alert("Invalid address...");
				return false;
			}
			else
			{
				// Valid...				
			}
			
			// -------------------------------------------------------------------------------------
			if (!isValidNumber(document.form.telephone.value)) {
				alert("Invalid telephone");
				document.form.telephone.focus();
				return false;
			}
			
			// -------------------------------------------------------------------------------------
			if(document.form.fax.value.trim() != "")
			{
				if (!isValidNumber(document.form.fax.value)) 
				{
					alert("Invalid fax");
					document.form.fax.focus();
					return false;
				}
			}
			
			// -------------------------------------------------------------------------------------
			if (!validateEmail(document.form.email.value)) {
				alert("Invalid email");
				document.form.email.focus();
				return false;
			}
		}
	} else if (currPart == 2) 
	{
		nextEle = "imageupload";
		backEle = "generalinfo";
		currEle = "detailinfo";
		if(direction == 1)
		{
			// Detail info
			if (!isNonEmpty(document.form.general_community_bio))
			{
				alert("Invalid general community bio");
				document.form.general_community_bio.focus();
				return false;
			}
			if (document.form.general_community_bio.value.length > 3000)
			{
				alert("General community bio length is between 0 - 3000");
				document.form.general_community_bio.focus();
				return false;
			}						
			
			if (!isNonEmpty(document.form.common_life))
			{
				alert("Invalid common life");
				document.form.common_life.focus();
				return false;
			}
			if (document.form.common_life.value.length > 3000)
			{
				alert("Common life length is between 0 - 3000");
				document.form.common_life.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.community_members))
			{
				alert("Invalid community members");
				document.form.community_members.focus();
				return false;
			}
			if (document.form.community_members.value.length > 3000)
			{
				alert("Community members length is between 0 - 3000");
				document.form.community_members.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.history))
			{
				alert("Invalid history");
				document.form.history.focus();
				return false;
			}
			if (document.form.history.value.length > 3000)
			{
				alert("History length is between 0 - 3000");
				document.form.history.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.sharevision))
			{
				alert("Invalid Shared Values and Vision");
				document.form.sharevision.focus();
				return false;
			}
			if (document.form.sharevision.value.length > 3000)
			{
				alert("Shared Values and Vision length is between 0 - 3000");
				document.form.sharevision.focus();
				return false;
			}
			
			
			if (document.form.yourConform.value.length > 3000)
			{
				alert("Our Visitor Policy length is between 0 - 3000");
				document.form.yourConform.focus();
				return false;
			}
			
			if (document.form.visitorsInfo.value.length > 3000)
			{
				alert("Visitors Info length is between 0 - 3000");
				document.form.visitorsInfo.focus();
				return false;
			}
			
			if (document.form.other.value.length > 3000)
			{
				alert("Other length is between 0 - 3000");
				document.form.other.focus();
				return false;
			}
			
			if (document.form.references.value.length > 3000)
			{
				alert("References length is between 0 - 3000");
				document.form.references.focus();
				return false;
			}
		}
	} else 
	{
		nextEle = "";
		backEle = "detailinfo";
		currEle = "imageupload";
		if(direction == 1)
		{

			// image upload
			if (!isNonEmpty(document.form.photo_1)) 
			{
				alert("Invalid photo image name");
				document.form.photo_1.focus();
				return false;
			}
						
			// -------------------------------------------------------------------------------------
			if (!isNonEmpty(document.form.owner)) 
			{
				alert("Invalid Owner");
				document.form.owner.focus();
				return false;
			}
			// -------------------------------------------------------------------------------------
			if (!isNonEmpty(document.form.password) || !isNonEmpty(document.form.password_rt)) 
			{
				alert("Invalid Password");
				document.form.password_rt.value = "";
				document.form.password.focus();
				return false;
			}
			
			if (document.form.password.value.trim() != document.form.password_rt.value.trim()) 
			{
				alert("Invalid Password");
				document.form.password.value = "";
				document.form.password_rt.value = "";
				document.form.password.focus();
				return false;
			}
						
			if(ownerStatus == 0) // not check before
			{
				ownerStatus = 1 // Move to checking status
				//document.getElementById("ownerErr").innerHTML = "Checking onwer...";
				var ownername = document.form.owner.value.trim();
				ValidateOwner(ownername);
				return false;
			}
			else if (ownerStatus == "1") // Checking)
			{
				alert("Owner name is being validated... please wait a munite.");
				return false;
			}
			else if (ownerStatus == "2") // Invalid)
			{
				alert("Invalid Owner...");
				return false;
			}
			else
			{
				// Valid...
			}
			
			document.getElementById("notice").style.display ="block";
		}
	}	
	
	if(direction == 0) // back
	{
		if(backEle != "")
		{
			//alert (currEle + "-" + backEle);
			// hide current
			document.getElementById(currEle).style.display = "none";
			
			// show current
			document.getElementById(backEle).style.display = "block";
		}
	}
	else
	{
		if(currPart != 3)
		{
			if(nextEle != "")
			{
				//alert (currEle + "-" + nextEle);
				
				// hide current
				document.getElementById(currEle).style.display = "none";
				
				// show current
				document.getElementById(nextEle).style.display = "block";
			}
		}
	}	
	
	return true;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function NavigateFormCommunityEditPage(currPart, direction) 
{
	//alert("NavigateFormCommunity");
	var nextEle = "";
	var backEle = "";
	var currEle = ""

	if(currPart == 1)
	{			
		nextEle = "detailinfo";		
		backEle = "";
		currEle = "generalinfo";
		if(direction == 1)
		{
			// General info
			
			// -------------------------------------------------------------------------------------
			if (!isNonEmpty(document.form.password) || !isNonEmpty(document.form.password_rt)) 
			{
				alert("Invalid Password");
				document.form.password_rt.value = "";
				document.form.password.focus();
				return false;
			}
			
			if (document.form.password.value.trim() != document.form.password_rt.value.trim()) 
			{
				alert("Invalid Password");
				document.form.password.value = "";
				document.form.password_rt.value = "";
				document.form.password.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.communityName)) 
			{
				alert("Invalid community name");		
				document.form.communityName.focus();
				return false;
			}
		
			// -------------------------------------------------------------------------------------
			if (!isAlphaSpace(document.form.contactName)) 
			{
				alert("Invalid contact name");
				document.form.contactName.focus();
				return false;
			}	
			
			if(document.form.zip.value.trim() != "")
			{
				// -------------------------------------------------------------------------------------
				if (!isZIP(document.form.zip)) {
					alert("Invalid zip code");
					document.form.zip.focus();
					return false;
				}
			}
		
			
			// -------------------------------------------------------------------------------------
			if (!isAddress(document.form.address)) 
			{
				alert("Invalid address");
				document.form.address.focus();
				return false;
			}
			
			//addressErr - Invalid Address
			//addressStatus - 0			
			if(addressStatus == 0) // not check before
			{
				addressStatus = 1 // Move to checking status
				//document.getElementById("addErr").innerHTML = "Validating address...";
				//alert("Validate address");
				var addr = document.form.address.value + ' ' + 
						   document.form.city.value + ' ' + 
						   document.form.state.value + ' ' + 
						   document.form.zip.value + ' ' + 
						   document.form.country.value;
				//alert(addr);
				ValidateAddress(addr);
				return false;
			}
			else if (addressStatus == "1") // Checking)
			{
				alert("Address is being validated... please wait a munite.");
				return false;
			}
			else if (addressStatus == "2") // Invalid)
			{
				alert("Invalid address...");
				return false;
			}
			else
			{
				// Valid...				
			}
			
			// -------------------------------------------------------------------------------------
			if (!isValidNumber(document.form.telephone.value)) {
				alert("Invalid telephone");
				document.form.telephone.focus();
				return false;
			}
			
			// -------------------------------------------------------------------------------------
			if(document.form.fax.value.trim() != "")
			{
				if (!isValidNumber(document.form.fax.value)) 
				{
					alert("Invalid fax");
					document.form.fax.focus();
					return false;
				}
			}
			
			// -------------------------------------------------------------------------------------
			if (!validateEmail(document.form.email.value)) {
				alert("Invalid email");
				document.form.email.focus();
				return false;
			}
		}
	} else if (currPart == 2) 
	{
		nextEle = "imageupload";
		backEle = "generalinfo";
		currEle = "detailinfo";
		if(direction == 1)
		{
			// Detail info
			if (!isNonEmpty(document.form.general_community_bio))
			{
				alert("Invalid general community bio");
				document.form.general_community_bio.focus();
				return false;
			}
			if (document.form.general_community_bio.value.length > 3000)
			{
				alert("General community bio length is between 0 - 3000");
				document.form.general_community_bio.focus();
				return false;
			}						
			
			if (!isNonEmpty(document.form.common_life))
			{
				alert("Invalid common life");
				document.form.common_life.focus();
				return false;
			}
			if (document.form.common_life.value.length > 3000)
			{
				alert("Common life length is between 0 - 3000");
				document.form.common_life.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.community_members))
			{
				alert("Invalid community members");
				document.form.community_members.focus();
				return false;
			}
			if (document.form.community_members.value.length > 3000)
			{
				alert("Community members length is between 0 - 3000");
				document.form.community_members.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.history))
			{
				alert("Invalid history");
				document.form.history.focus();
				return false;
			}
			if (document.form.history.value.length > 3000)
			{
				alert("History length is between 0 - 3000");
				document.form.history.focus();
				return false;
			}
			
			if (!isNonEmpty(document.form.sharevision))
			{
				alert("Invalid Shared Values and Vision");
				document.form.sharevision.focus();
				return false;
			}
			if (document.form.sharevision.value.length > 3000)
			{
				alert("Shared Values and Vision length is between 0 - 3000");
				document.form.sharevision.focus();
				return false;
			}
			
			
			if (document.form.yourConform.value.length > 3000)
			{
				alert("Our Visitor Policy length is between 0 - 3000");
				document.form.yourConform.focus();
				return false;
			}
			
			if (document.form.visitorsInfo.value.length > 3000)
			{
				alert("Visitors Info length is between 0 - 3000");
				document.form.visitorsInfo.focus();
				return false;
			}
			
			if (document.form.other.value.length > 3000)
			{
				alert("Other length is between 0 - 3000");
				document.form.other.focus();
				return false;
			}
			
			if (document.form.references.value.length > 3000)
			{
				alert("References length is between 0 - 3000");
				document.form.references.focus();
				return false;
			}
		}
	} else 
	{
		nextEle = "";
		backEle = "detailinfo";
		currEle = "imageupload";
		if(direction == 1)
		{

			
		}
	}	
	
	if(direction == 0) // back
	{
		if(backEle != "")
		{
			//alert (currEle + "-" + backEle);
			// hide current
			document.getElementById(currEle).style.display = "none";
			
			// show current
			document.getElementById(backEle).style.display = "block";
		}
	}
	else
	{
		if(currPart != 3)
		{
			if(nextEle != "")
			{
				//alert (currEle + "-" + nextEle);
				
				// hide current
				document.getElementById(currEle).style.display = "none";
				
				// show current
				document.getElementById(nextEle).style.display = "block";
			}
		}
	}
	return true;
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isValidPassword(element){
	var noSpace = /^[0-9a-zA-Z\_\.\!\@\$\%\^\&\*\(\)\-\+\=]+$/
	//var noSpace = /^[\s]+$/;
	if (element.value.match(noSpace)){
       return true;
        }
    }

function isNonEmpty(element){
	if(element.value.trim()!=""){
		return true;
	}
	else return false;
}

function isNonEmptyAlphaSpace(element){
	if(element.value.trim()!="" & isAlphaSpace(element) ){
		return true;
	}
	else return false;
}

function isNonEmptyAlphaNumSpace(element){
	if(element.value.trim() !="" & isAlphaNumSpace(element))return true;
	return false;	
}

function isNonEmptyAlphaNumSpaceHiphen(element){
	if(element.value.trim()!="" & isAlphaNumSpaceHiphen(element)) return true;
	return false;
}	

function isNonEmptyAlphaNumUnderscoreDot(element){
 if(element.value.trim()!=""){	
	var alphaExp = /^[0-9a-zA-Z\_\.]+$/;
   if (element.value.match(alphaExp)) {
   	return true;
   }
   else {
   	return false;
   }
 }
 	return false;
}

function validateEmail(email) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.trim())) {
        return true;
    }
    return false;
}

function isExistSpecialChars(strSource){
	var s="";
    var i=0;
    var strSpecCharList = "~`!@#$%^&*";
    for (i=0;i<strSpecCharList.length;i++){
        s = strSpecCharList.charAt(i);       
        if(strSource.indexOf(s) == 0){
            return true;
		}
    }	
	return false;
}

function requiredField(strFrm,strField,alerttxt){
	var a=trim(eval('document.'+strFrm+'.' + strField +'.value'));
	var b=a.length;
	if (a==""||eval('document.'+strFrm+'.' + strField +'.value')==null||b==0) {
		alert(alerttxt);
		eval('document.'+strFrm+'.' + strField).focus();
		return false;
	}
	else{
		return true;
	}
}

function isAlphaNum(element) {
	var alphaExp = /^[0-9a-zA-Z]+$/;
	
	if (element) {
		if (element.value.match(alphaExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
}
function isAlphaNumSpace(element) {
	var alphaExp = /^[0-9a-zA-Z\s]+$/;
	
	if (element) {
		if (element.value.match(alphaExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
}
function isAlphaNumSpaceHiphen(element) {
	var alphaExp = /^[0-9a-zA-Z\-\s]+$/;
	
	if (element) {
		if (element.value.match(alphaExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
}
function isAlphabet(element) {
	var alphaExp = /^[a-zA-Z]+$/;
	
	if (element) {
		if (element.value.match(alphaExp)) {
			return true;
		}
		else { 
			return false;
		}
	}

	return true;
}

function isAlphaSpace(element) {
	var alphaExp = /^[a-zA-Z\s]+$/;
	
	if (element) {
		if (element.value.match(alphaExp)) {
			return true;
		}
		else { 
			return false;
		}
	}

	return true;
}

function isAlphaNumVal(element){
if(element.value.trim()!= ""){
	var addrExp = /^[0-9a-zA-Z\s]+$/;
	
	if (element.value.match(addrExp)) {
		return true;
	}
	else {
		return false;
	}

	return true;
	}
}

function isText(element){
	var textExp=/^[0-9a-zA-Z;,.:!\s]+$/;
	if (element) {
		if (element.value.match(textExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
}

function isValidTimeAvailabilty(element){
 if(element.value.trim() !=""){
   var timeExp = /^[0-9a-zA-Z\s\-\.\:\/]+$/;
    if(element){
    	if(element.value.match(timeExp)){
    	return true;
    	}
    	else{
    	 return false;
    	    }
    	}
    	 return true;
   }
}
function isAddress(element) {
 if(element.value.trim()!=""){
	var addrExp = /^[0-9a-zA-Z,.\s\/\#\-]+$/;
	
	if (element) {
		if (element.value.match(addrExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
	}
}

function isZIP(element) {
	var val;

	if (element) {	
		val = element.value;
		regZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if(val.length > 5)
		{
			if(val.length > 10)
			{
				return false;
			}
		}
		else
		{
			if (!regZip.test(val)) {
				  //alert("Zip Code Is Not Valid");
				  //element.focus();
				  return false;
			 }
		}
	}
	return true;
}

function isHourlyRate(element) {
	var val;
	if (element) {
	
		val = element.value;
		if(element.value.trim()!=""){
		
		if (isNaN(val)==true) {
			
			return false;
		}
		else if (val<0) {
			return false;
		}
	}
	
	return true;
}
	return false;
}

/* Check validation for Number of Sessions field */
function isValidNOS(element) {
	var val;
	
	if (element) {
		val = element.value;
		
		if (CheckInt(val)) {
			if ((val>0) && (val<101)) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;	
		}
	}
	
	return true;
}

function isValidSubj(element) {
	if(element.value.trim()!=""){
	var subjExp = /^[a-zA-Z,\s\,\.\;]+$/;
	
	if (element) {
		if (element.value.trim().match(subjExp)) {
			return true;
		}
		else {
			return false;
		}
	}
	return true;
	}
}

function isValidNumber(theNumber){
     if (theNumber.trim()=="")
	 {
        return false;
     }
     var limitChar= "0123456789.+()-";
     var i = 0;
     for (i=0; i<=(theNumber.length -1);i++) 
	 {
         if (limitChar.indexOf(theNumber.charAt(i)) == -1)
		 {
            return false;
         }
     } 	 
     return true;
}

function isInteger(theNumber){
     if (theNumber.trim()==""){
        return false;
     }
     var limitChar= "0123456789";
     var i = 0;
     for (i=0; i<=(theNumber.length -1);i++) {	 	      
         if (limitChar.indexOf(theNumber.charAt(i)) != -1){
            return true;
         }
     } 	 
     return false;
}	

function CheckInt(theNumber)
{
     if (theNumber.trim()==""){
        return false;
     }
     var limitChar= "0123456789";
     var i = 0;
     for (i=0; i<=(theNumber.length -1);i++) {
         if (limitChar.indexOf(theNumber.charAt(i))==-1){
            return false;
         }
     }
 	 if(parseInt(theNumber) <= 0)	return false;
     return true;
}
String.prototype.trim = function() {
	return this.replace(/(^\s+)|\s+$/g, "");
};

String.prototype.trimEnd = function() {
	return this.replace(/\s+$/g, "");
};

function checkDate(day,month,year)
{
	var err = 0;
	var i;
	var leap=0;

	year = parseInt(year,10);
	month = parseInt(month,10);
	day = parseInt(day,10);
		
	/* year is wrong if year <= 0000 */
	if (year <= 0) return false;	
    
	/* Validation of month*/
	if ((month < 1) || (month > 12)) return false;
	
	/* Validation of day*/
	if (day < 1) return false;

	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0))	{
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)){
		return false;
	}
	if ((month == 2) && (leap != 1) && (day > 28)){
		return false;
	}
	/* Validation of other months */
	if ((day > 31) && ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)))	{
		return false;
	}
	if ((day > 30) && ((month == 4) || (month == 6) || (month == 9) || (month == 11))){
		return false;
	}
	return true;
}

function removeDefaultMessage(obj,DefaultMessage) {
	if (obj.value == DefaultMessage) {
		obj.value = "";
		//obj.select();
	}
}

function ValidatePath(formName,filePath)
{	
	var validExtensions=new Array("jpeg", "jpg", "png","gif","png");
	var fileInput = eval("formName."+filePath);
	
	var full_filename = fileInput.value;
	//alert(full_filename);
	if (full_filename.trim()){
		//alert(full_filename.trim());
		var isValidExtension = false;
		var fileArray = full_filename.split('.');

		//alert(full_filename.trim());
		var filename1;
		
		if (fileArray.length<2) {
			return false;
		}
		else {
			var regExp=/^[0-9a-zA-Z\_\-\s]+$/;
			var validFileName=true;
			for(var j=0;j<fileArray.length-1;j++){
				filename1 = fileArray[j].toLowerCase();
				filename1 = filename1.replace(/\:\\/g,"");
				filename1 = filename1.replace(/\:\//g,"");
				filename1 = filename1.replace(/\//g,"");
				filename1 = filename1.replace(/\\/g,"");
	            //alert (filename1+"good");
	            
				if (!filename1.match(regExp)) {
					//alert (filename1+"bad");
					validFileName=false;
					break;
				}
			}
			//alert("end validName");	
			if(!validFileName)
				return validFileName;					
		}
		
        var fileExtension = fileArray[fileArray.length-1].toLowerCase();
        //alert('fileExtension : ' + fileExtension);
        var i = 0;
		var extName;
		for (i=0;i<validExtensions.length;i++) {
			extName = validExtensions[i];
			//alert(extName);
			if(extName == fileExtension){
				isValidExtension = true;
				break;
			}
		}
		//alert(isValidExtension);
		return isValidExtension;     
	}
	else{
		//alert("Empty fileName");
		return false;		
	}	
}

function ValidatePath_ActXObject(formName,filePath){    
	var validExtensions=new Array("gif", "jpeg", "png");       
	var msgError = "Invalid file path";
	var msgErrorInvalidFile = "File name is not existing";
	var msgErrorInvalidExt = "Invalid file type.  Please choose a file with extension " + validExtensions.toString();
	if(filePath.value.trim() != ""){  
	   if((filePath.value.indexOf('//') != -1) || (filePath.value.indexOf('\\\\') != -1) 
	   || (filePath.value.indexOf('/\\') != -1)|| (filePath.value.indexOf('\\/') != -1)){
			alert(msgError);
			filePath.focus(); 
			return false;	
	   }
	   else {  
			var fso = new ActiveXObject("Scripting.FileSystemObject");   
			var extName = fso.GetExtensionName(filePath.value).toLowerCase();			
			if(fso.GetParentFolderName(filePath.value) != ""){  
				if(!fso.FolderExists(fso.GetParentFolderName(filePath.value))){   
					alert(msgError);     
					filePath.focus();  
					return false;					
				}else if(!findExtendsion(extName,validExtensions)){
					alert(msgErrorInvalidExt);                
					filePath.focus();
					return false;
				}else{   
					if(!fso.FileExists(filePath.value)){
						alert(msgErrorInvalidFile);
						return false;
					}                                               
				}    
			}else{                    
				alert(msgError);
				filePath.focus();
				return false;
			}
	   }
	}else{
		alert("Please select a file.");
		return false; 
	   filePath.focus();           
	}         
	 fso = null;          
}        

function findExtendsion(extName,arrExt){
	for(var i = 0; i < arrExt.length ; i++){
		if(arrExt[i] == extName){
			return true;
		}
	}
	return false;
}