var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var dig = '1234567890';
var space= ' ';
var symbol='-';

function isValid(parm,val) 
{
  for (i=0; i<parm.length; i++) 
  {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}


function isEmpty(textvalue) {
	textvalue=textvalue.replace(/\s/g,"");
	if(textvalue.length>0)
		return false;
	else
		return true;
}
function validateEmail(email)
{
	
	if (email == ""){
		return false;
	}
	badStuff = ";:/,' \"\\";
	for (i=0; i<badStuff.length; i++){
		badCheck = badStuff.charAt(i)
		if (email.indexOf(badCheck,0) != -1){
			return false;
		}
	}
	posOfAtSign = email.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email.length){
		return false;
	}
	return true
}
function callback()
{
	
	if (isEmpty(document.getElementById('txt_callname').value)) 
	{
		alert("Please enter you Name.");
		document.getElementById('txt_callname').focus();
		return false;
	}	

	if (!isValid(document.getElementById("txt_callname").value,lwr+upr+space))
	 {
	 alert("Enter only alphabets in your Name");
	 document.getElementById('txt_callname').focus();
	 return false;
	 }
	 if (isEmpty(document.getElementById('txt_callphone').value)) 
	{
		alert("Please enter your Phone Number.");
		document.getElementById('txt_callphone').focus();
		return false;
	}	
	if (!isValid(document.getElementById("txt_callphone").value,dig+symbol))
	 {
	 alert("Enter valid Phone Number.");
	 document.getElementById('txt_callphone').focus();
	 return false;
	 }
	if (isEmpty(document.getElementById('txt_callmobile').value)) 
	{
		alert("Please enter your Mobile Number.");
		document.getElementById('txt_callmobile').focus();
		return false;
	}	
	if (!isValid(document.getElementById("txt_callmobile").value,dig+symbol))
	 {
	 alert("Enter valid Mobile Number.");
	 document.getElementById('txt_callmobile').focus();
	 return false;
	 }
	if (isEmpty(document.getElementById('txt_callemail').value)) 
	{
		alert("Please enter your Email Address.");
		 document.getElementById('txt_callemail').focus();
		return false;
	}
	
	if(!validateEmail(document.getElementById('txt_callemail').value)) 
	{
		alert("Please enter valid Email Address.");
		document.getElementById('txt_callemail').focus();
		return false;
	}
	
	if (document.getElementById('sel_callday').value=='0') 
	{
		alert("Please select Day on which we can call.");
		 document.getElementById('sel_callday').focus();
		return false;
	}
	
	if (document.getElementById('sel_calltime').value=='0') 
	{
		alert("Please select Time duration.");
		 document.getElementById('sel_calltime').focus();
		return false;
	}
}

function validate_callleft()
{
	if(document.getElementById('sel_callday').value=='Tomorrow')
	{
		for(i=0;i<14;i++)
		{
			if(document.getElementById('sel_calltime').options[i].value=='Now')
			{
			document.getElementById('sel_calltime').options[i] = null;
			document.getElementById('sel_calltime').options.selectedIndex = 0; 
			}
		}
	}
	if(document.getElementById('sel_callday').value=='Today')
	{
  		if(!(document.getElementById('sel_calltime').options[0].value=='Now'))
		{
			AddItemleft('Now','Now');
		}
	}
}

function AddItemleft(Text,Value)
    {
        var opt = document.createElement("option");
        document.getElementById("sel_calltime").options.add(opt);
        opt.text = Text;
        opt.value = Value;
    }
