
function isWhiteSpaces(S)
{
	var isNull
	if (S.length == 0 ) 
		isNull = true;
	else
	{
		for (I=0;I < S.length; I++ )
		{
			isNull = S.substring(I,I+1)==" "?true:false
			if (!isNull) break;
		}
	}
	return isNull;
}

function isAlpha(S)
{
	for (var i=0; i<S.length; i++) 
	{
		var ch = S.charAt(i);
		if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' ') && (ch <'0') && (ch >'9')) 
			return false;
	}
	return true;
}

function isNumeric(S)
{
	if (!isNaN(S))	
		return true;	
	return false;
}

function isEmail(email)
{
	var isNullEmail = isWhiteSpaces(email)
	var emailLength = email.length
	var isSPACEexists = email.indexOf(" ") + 1
	var isATexistsFirst = email.indexOf("@")
	var isATexistsLast = email.lastIndexOf("@")
	var isDOTexistsFirst = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext1 = email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext2 
	var isDOTexistsLast = email.lastIndexOf(".")

	if ((emailLength < 8 ) || (isDOTexistsFirst < isATexistsFirst+3) || (isATexistsFirst < 2) ||
   	 	(isDOTexistsLast == emailLength-1) || (isATexistsLast == emailLength-1) ||
    	(isDOTexistsFirst == 0) || (isATexistsFirst == 0) || (isATexistsFirst == isDOTexistsFirst) ||
    	(isATexistsFirst != isATexistsLast) || isSPACEexists || isNullEmail)
	{
		return false;
	}

	while (isDOTexistsNext1 < isDOTexistsLast)
	{
		isDOTexistsNext2 = email.indexOf(".",isDOTexistsNext1+1)
		if (isDOTexistsNext1+1 == isDOTexistsNext2)
		{
			return false;
		}
		isDOTexistsNext1 = isDOTexistsNext2
	}

	return true;
}



function validate ()
{
	
	if (isWhiteSpaces(document.form1.name.value))
	{
		alert("Please Enter Your Name......");
		document.form1.name.focus();
		return false;
	}
	if (document.form1.country.options[document.form1.country.options.selectedIndex].value == " ")
	{
		alert ('Please Select Country.....');
		document.form1.country.focus();
		return false;
	}
	
	if (isWhiteSpaces(document.form1.phone.value))
	{
		alert ('Please Enter Min 8 Digits Contact No......');
		document.form1.phone.focus();
		return false;
	}
	if (!isNumeric(document.form1.phone.value))
	{
		alert ('Please Enter Digits Only......');
		document.form1.phone.focus();
		return false;
	}
	if(document.form1.phone.value.search(/\d{8}/)==-1)
   {
      alert("Please Enter Minimum 8 Digits.....");
	  document.form1.phone.focus();
      return false;
   }
   if (isWhiteSpaces(document.form1.email.value))
	{
		alert ('Please Enter Email Id......');
		document.form1.email.focus();
		return false;
	}
	
	if (!isEmail(document.form1.email.value))
	{
		alert ("Please Enter Email Id in 'abc@xyz.com' Format.......");
		document.form1.email.focus();
		return false;
	}
	
	if (isWhiteSpaces(document.form1.comm.value))
	{
		alert ('Please Enter Your Enquiry......');
		document.form1.comm.focus();
		return false;
	}
	/*if (isWhiteSpaces(document.form1.captchacode.value))
	{
		alert ('Please Enter Image Verification Code......');
		document.form1.captchacode.focus();
		return false;
	}*/
	var reg1 = document.getElementById('project').value;
	if (reg1=='Glitterati, 24 k')
	{
	document.getElementById('sp_email').value="sapna.kanakia@koltepatil.com";
	}
	else
	{
	document.getElementById('sp_email').value="sales@koltepatil.com";
	}			
}
