///////////////////TELEPHONE////////

function isSplCharPhone(str)
{
	var spchar, getChar, SpecialChar;	
	spchar="`()(\\~!@^&*+\"|%:=,<>$_";
	getChar='Empty';
	SpecialChar='No';
	var spchars =" ` ( )  \\ ~ ! @ ^ & * + \" | : =  , < > "; 
	for(var i=0; i<str.length; i++)
	{
		for(var j=0; j<spchar.length; j++)
		{
			if(str.charAt(i) == spchar.charAt(j))
			{
				SpecialChar='Yes';
				break;
			}
			else
			{
				if (str.charAt(i)!=' ')
				getChar='Normal';
			}
		}		
	}

	if (SpecialChar == 'Yes')
	{
//		alert('Please do not enter any of the following characters: \n ' + spchars);	
		return true;
	}
	else if (SpecialChar == 'No')
	{
		return false;
	}
}




/////////////Telephone//////////////
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{  
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   	
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhoneForm(){
	var Phone=document.frmContactus.Phone
	
	if ((Phone.value==null)||(Phone.value=="")){
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }


/////////////////spl charter////////
function isSplChar(str)
{
	var spchar, getChar, SpecialChar;	
	spchar="`()(\\~!@#^&*+\"|%:=,<>$.0123456789";
	getChar='Empty';
	SpecialChar='No';
	var spchars =" ` ( )  \\ ~ ! @ ^ & * + \" | : =  , < > "; 
	for(var i=0; i<str.length; i++)
	{
		for(var j=0; j<spchar.length; j++)
		{
			if(str.charAt(i) == spchar.charAt(j))
			{
				SpecialChar='Yes';
				break;
			}
			else
			{
				if (str.charAt(i)!=' ')
				getChar='Normal';
			}
		}		
	}

	if (SpecialChar == 'Yes')
	{
//		alert('Please do not enter any of the following characters: \n ' + spchars);	
		return true;
	}
	else if (SpecialChar == 'No')
	{
		return false;
	}
}



/************************************************************************************************************************************/
/**************************************************** Email ******************************************************/
/************************************************************************************************************************************/
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmContactus.Email
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
/************************************************************************************************************************************/
/**************************************************** limit of characters ******************************************************/
/************************************************************************************************************************************/
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)

document.getElementById('countCompany').innerHTML = obj.value.length;
}
function ismaxlength1(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)

document.getElementById('countAddress').innerHTML = obj.value.length;
}

/************************************************************************************************************************************/
/**************************************************** STARTS: GLOBAL VARIABLES ******************************************************/
/************************************************************************************************************************************/
	var elementDiv = "divErrMsgJS";
	
	var FRM_LABELS = [
		'lblFirstname',
		'lblLastname',
		'lblEmail',
		'lblproject'
	];

	var FRM_CONTROLS = [
		'Firstname',
		'Lastname',
		'Email',
		'project'
	];
	
	var ERR_MESSAGES = [
		'First Name cannot be empty.',
		'Last Name cannot be empty.',
		'Email must be filled out.',
		'Project requirements must be filled out.'
	];
	
/************************************************************************************************************************************/
/**************************************************** END: GLOBAL VARIABLES ******************************************************/
/************************************************************************************************************************************/

/************************************************************************************************************************************/
/************************************************* STARTS: FORM LEVEL VALIDATIONS ***************************************************/
/************************************************************************************************************************************/
	function validate_form(frmLabels, frmControls, errMessages) {
		// don't check old browsers on client side
		if (!document.body || !document.body.innerHTML)
			return true;
		
		clear_displayMessage(FRM_LABELS);
		a_errors = [];

		for (var i = 0; i < frmControls.length; i++) {
			control = document.getElementById(frmControls[i]);
			if (!control.value || control.value==0)		// This checks whether the Control(textbox) contains some value or not
				a_errors[a_errors.length] = {'t': errMessages[i],  'f': frmLabels[i], 'i': frmControls[i]};
				
				/*
			else if (control.id == 'txtUsername' && !isValidEmail(control.value))
				a_errors[a_errors.length] = {'t': 'Invalid Email Address.', 'f': 'lblUsername', 'i': 'txtUsername'};
				*/
				
				else if (isSplChar(control.value) && control.id == 'Firstname' )
				a_errors[a_errors.length] = {'t': 'Invalid Name.', 'f': 'lblFirstname', 'i': 'Firstname'};
				
				else if (isSplChar(control.value) && control.id == 'Lastname' )
				a_errors[a_errors.length] = {'t': 'Invalid Last Name.', 'f': 'lblLastname', 'i': 'Lastname'};
				
				else if (!echeck(control.value) && control.id == 'Email' )
				a_errors[a_errors.length] = {'t': 'Please Enter a Valid Email', 'f': 'lblEmail', 'i': 'Email'};
				
				else if (isSplCharPhone(control.value) && control.id == 'Phone' )
				a_errors[a_errors.length] = {'t': 'Please Enter a Valid Phone Number', 'f': 'lblPhone', 'i': 'Phone'};
				
		}
	
		if (a_errors.length) {							// display error messages
			display_Message_box(a_errors);
			return false;
		}
	}
	
	function clear_displayMessage(frmLabels) {
		var errorboxes = ['divErrMsgJS', 'divErrMsgPHP'];
		for (var index = 0; index < errorboxes.length; index++) {
			e_errbox = get_element(errorboxes[index]);
	
			if (!e_errbox)
				continue;
			
			if (e_errbox && e_errbox.innerHTML) {
				e_errbox.style.display = 'none';
				e_errbox.innerHTML = '';
			}
		}
	
		for (var i = 0; i < frmLabels.length; i++) {
			e_caption = get_element(frmLabels[i]);
			if (!e_caption)
				continue;
			e_caption.className = 'normal';
		}
	}

	function display_Message_box (a_errors) {
		e_errbox = get_element('divErrMsgJS');
		s_message = '';
	
		// set focus
		document.getElementById(a_errors[0]['i']).focus();
	
		s_message = '<table border=0 width=94% cellspacing=0 cellpadding=0><tr><td valign="top" style="padding-top:2px; font-size: 11px; color: red; text-align: left;"><b>Errors: </b></td> <td><ul style="margin-left: 0px; display: inline;">';
		for (n_i = 0; n_i < a_errors.length; n_i++)	{
			s_message += '<li style="color: red; text-align: left;">' + a_errors[n_i]['t'] + '</li>';
		}
		s_message += '</ul></td></tr></table>';
		
		if (e_errbox && e_errbox.innerHTML != null)	{
			e_errbox.innerHTML = 
			  '<table cellpadding="0" cellspacing="0" width="96%" style="border:1px #CCCCCC solid;">'
			+ '<tr><td bgcolor="#CCCC33">'
			+ '<table cellpadding="0" cellspacing="0" border="0" width="100%">'
			+ '<tr><td bgcolor="#FFFFCC" style="color: red; padding-left:4px;">'
			+ '<div style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 51px">' + s_message + '</div>'
			+ '</td></tr>'
			+ '</table>'
			+ '</td></tr>'
			+ '</table>';
			e_errbox.style.display = 'inline';
			elementDiv = "divErrMsgJS";
			setTimeout("delayer()", 10000);
		}
		for (n_i = 0; n_i < a_errors.length; n_i++)
			if (a_errors[n_i]['f'])	{
				e_caption = get_element(a_errors[n_i]['f']);
				if (!e_caption)
					continue;
				e_caption.className = 'error';
			}
	}
	
	function get_element(s_id) {
		return (document.all ? document.all[s_id] : (document.getElementById ? document.getElementById(s_id) : null));
	}
	function delayer() {
		document.getElementById(elementDiv).style.display = 'none';
	}
/************************************************************************************************************************************/
/*************************************************** END: FORM LEVEL VALIDATIONS ****************************************************/
/************************************************************************************************************************************/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}