// JavaScript Document
function showSelected()
{

	var selObj = document.getElementById('countrycombo');
	var txtIndexObj = document.getElementById('txtIndex');
	var txtValueObj = document.getElementById('mcode');
	var txtTextObj = document.getElementById('txtText');
	var selIndex = selObj.selectedIndex;
	txtIndexObj.value = selIndex;
	txtValueObj.value = selObj.options[selIndex].value;
	var country = selObj.options[selIndex].text;
	document.lodhaForm('00N20000001SJmA').value = country;
	document.lodhaForm('00N20000001SJmb').value = txtValueObj.value;
	document.lodhaForm('lcountry').value = txtValueObj.value;
}
	
function isEmpty(s){return ((s == null) || (s.length == 0));}

function isAjay(s){return (s.match("Name"));}

function isAjay1(s){return (s.match("telephone"));}

function isAjay2(s){return (s.match("mobilecode"));}

function isAjayy(s){return (s.match("city"));}

function isLetterAndBlank(s){var i = 0; while( i < s.length ){var c = s.charAt(i); if( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == " ") ){i++; continue;} else return false;} return true; }
function isLetter(c){ if( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) return true; else return false;}
function isDigit (s){var i = 0; while( i < s.length ){var c = s.charAt(i); if((c >= "0") && (c <= "9")){i++; continue;} else return false;} return true;}
function isBlankSpaces(s){var i = 0; while(i < s.length){if(s.charAt(i) == " "){i = i + 1; continue;}else return false;} return true;}
function isZipCode(s){var valid = "0123456789"; var hyphencount = 0; if (s.length!=6) {alert("Please enter your 6 digit Pincode."); return false;}for (var i=0; i < s.length; i++) {temp = "" + s.substring(i, i+1); if (valid.indexOf(temp) == "-1"){alert("Invalid characters in your Pincode.  Please try again."); return false;}} return true;}
function isEmail(){var c = document.getElementById('email').value; var NotValid = "~ \'!#$%^&*()=+|[]{};:<>?/,"; var Status = true; var Dotval = 0; var Atval = 0; for (var i=0; i < c.length; i++) {temp = "" + c.substring(i, i+1); if(NotValid.indexOf(temp) != "-1"){Status = false; alert('Please enter a valid email.'); return Status;}if(temp == "."){Dotval =Dotval + 1;}if(temp == "@"){Atval = Atval + 1;}}if(Status){if(Dotval == 0){alert('Please enter a valid email.');return false;}	else{if(Atval == 0 || Atval >1 ){alert('Please enter a valid email.');return false}}return Status;}}
 
		   	
	function validation()
	{
		var name = document.getElementById('last_name').value;; 
		if(isEmpty(name) || isBlankSpaces(name) || isAjay(name))
		{
			alert('Please enter a valid name.');
			document.getElementById('last_name').focus();
			return false;
		}

		if(!isLetterAndBlank(name))
		{
			alert('Please enter a valid name.');
			document.getElementById('last_name').focus(); 
			return false;
		} 
		if(!isEmail())
		{ 
			document.getElementById('email').focus(); 
			return false; 
		} 
        if(document.getElementById("countrycombo").value=="")
		{
        	 alert('please select the country');
        	 document.getElementById("countrycombo").focus();
        	 return false;        
        }  
        
         //alert(document.lodhaForm('00N20000001SJmA').text);
         var city = document.getElementById('CityR').value;;
         city = city.slice(0,1).toUpperCase() + city.slice(1);
         //alert(city);
      
        if(isEmpty(city) || isBlankSpaces(city) || isAjayy(city))
		{
  			alert('Please enter a valid city.'); 
			document.getElementById('CityR').focus();
			return false;
		}
	  
		if(!isLetterAndBlank(city))
		{
			alert('Please enter a valid city.'); 
			document.getElementById('CityR').focus(); 
			return false;
		}

/********Phone number check**************************/
		
		/*var mobilecode = document.getElementById('00N20000001kyfO1').value;; 
		if((mobilecode.length < 3) || isEmpty(mobilecode) || isBlankSpaces(mobilecode)|| isAjay2(mobilecode))
		{
			alert('Please enter mobile country code.'); 
			document.getElementById('00N20000001kyfO1').focus(); 
			return false;
		} 
		if(!isDigit(mobilecode))
		{
				alert('Please enter mobile country code.');
				document.getElementById('00N20000001kyfO1').focus(); 
				return false;
		}*/

		var telephone = document.getElementById('00N20000001SJmb1').value ;; 
		if((telephone.length < 10) || isEmpty(telephone) || isBlankSpaces(telephone)|| isAjay1(telephone))
		{
		   alert('Please enter a mobile number.'); 
		   document.getElementById('00N20000001SJmb1').focus(); 
		   return false;
		} 
		if(!isDigit(telephone))
		{
		   alert('Please enter a valid Mobile number.');
		   document.getElementById('00N20000001SJmb1').focus(); 
		   return false;
		}
		
        document.lodhaForm('00N20000001SJmA').value;
		var mobc = document.lodhaForm('mcode').value;
		var mob = document.lodhaForm('00N20000001SJmb1').value;		
		var result = mobc + mob;
	
		//document.lodhaForm('00N20000001SJmb').value = result;
		//alert('Mobile number with country code is,' + document.lodhaForm('00N20000001SJmb').value);

/********check for Phone nunbers ends*******/

	   var others = "Others";
       if(document.lodhaForm('00N20000001SJmA').value != "India")
	   {
            var foreigner="Foreigner";
		    document.lodhaForm('00N20000001SJm4').value = foreigner;	
		    document.lodhaForm('00N20000001SJn4').value = city;  	    
          	document.lodhaForm('00N20000001SJm3').value = others;
            document.lodhaForm('00N20000001SJmb').value = result;
			document.lodhaForm('00N20000001SJmA').value;			
  	        //alert(result);
	    }
        else 
        {
         
         if(city == "Mumbai") 
         {
            var mum = "Mumbaiite";
      		document.lodhaForm('00N20000001SJm4').value = mum;
      		document.lodhaForm('00N20000001SJm3').value = city;  
      		document.lodhaForm('00N20000001SJmb').value = mob;
			document.lodhaForm('00N20000001SJmA').value;
            //alert(mob);
         }
         else 
         {
            var otherInd = "Other Indian";
            document.lodhaForm('00N20000001SJm4').value = otherInd;
            if(city!= "Pune" || city!= "Hyderabad") 
            {
        		document.lodhaForm('00N20000001SJn4').value = city; 
        		document.lodhaForm('00N20000001SJm3').value = others; 
        		document.lodhaForm('00N20000001SJmb').value = mob;
				document.lodhaForm('00N20000001SJmA').value; 
				
				//alert(others);
				//alert(mob);   
            }
            else
            {
	  		    //alert(city);
	          	document.lodhaForm('00N20000001SJm3').value = city;  	  
				document.lodhaForm('00N20000001SJmA').value;   	    
            }
         }
		} 
		
		var lccode = document.lodhaForm('lcountry').value;
		var lacode = document.lodhaForm('state').value; 
		var lphone = document.lodhaForm('landline').value;
		var string = lacode.charAt(0);
		if(string==0)
		{
		
		var lccode = document.lodhaForm('lcountry').value;
		
		var lacode = document.lodhaForm('state').value; 
		var lacode = lacode.substr(1);
		
		var lphone = document.lodhaForm('landline').value;
		
		
		//var lacode = lacode.substr(1);
		
		var lresult = lccode + lacode + lphone;
		document.lodhaForm('phone').value = lresult;
		}
		else 
		{
		 if(string!=0)
		  {
			var lccode = document.lodhaForm('lcountry').value;
			var lacode = document.lodhaForm('state').value; 
			var lphone = document.lodhaForm('landline').value;
			var lresult = lccode + lacode + lphone;
		  }
		}
}            
/*var dropdownIndex = document.getElementById('00N20000001SJmA').selectedIndex;
var dropdownValue = document.getElementById('00N20000001SJmA')[dropdownIndex].value;
alert('Value'+ dropdownValue);
return true;*/