// JavaScript Document

function TrimString(sInString)
{
  sInString = sInString.replace(/^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function CheckBlank(txtElement,fieldName)
{
	if (TrimString(txtElement.value) == "") 
	{
		alert ("Please Enter " + fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

function CheckBlank1(txtElement,fieldName)
{
	if (TrimString(txtElement.value) == "") 
	{
		alert ("Please Answer the " + fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

function CheckEmail(txtElement,fieldName,allowEmpty)
{
	var exclude=/[^@\-\.\w\_]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	var strEmail = txtElement.value
	var email_array=strEmail.split(",");
	
	if(allowEmpty == false && txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus()
		return false;
	}

	if(allowEmpty == true && txtElement.value.length == 0)
	{
		//empty value is allowed
		return true;
	}
	else 
	{
		var email_num=0;
		var CheckEmail;
		while (email_num < email_array.length)
		{
				var trimemail = TrimString(email_array[email_num]);
				//alert("email=" + hello);
				//alert("email=" + email_array[email_num]);
				if(((trimemail.search(exclude) != -1) || 
					(trimemail.search(check)) == -1)   ||	
					(trimemail.search(checkend) == -1))
				{
					CheckEmail = "false";
				}
				else
				{
					CheckEmail = "true";
				}
				//alert(email_array[email_num]);
				email_num++;
				if(CheckEmail == "false")
				{
					alert("Incorrect email address!");
					txtElement.focus()
					return false;
				}
				else 	
					return true;				
		}		
	}
}

function CheckTelephone(str)
{

	var reg = /^\(?\d{3}\)?[-\s.]?\d{3,4}[-\s.]?\d{3,4}$/;
if (str.match(reg) )
 {
   return true;
 }
 else
 {
 alert('"' + str + '"' + " is an invalid phone number!");

 return false;
 }
}


function partnerValidateInput()
{
    var tomatchdigit= /^[0-9]+$/
	var tomatchnumbers= /^[1-9]+$/
	var tomatchchar=/^[a-z A-Z]+$/
	var tomatchurl = /[A-Za-z\.-]{3,}\.[A-Za-z]{3}/
//	var tomatchurl = /^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*))?+$/
	
	var phone=document.getElementById("Telephone").value
	var employees=document.getElementById("Employees").value
	var Clients=document.getElementById("Clients").value
	var NamE=document.getElementById("name").value
	var Desig=document.getElementById("Designation").value
	var Url=document.getElementById("Url").value
	
	if (!CheckBlank(document.form2.pName,'Name')) return false;
			if (!NamE.match(tomatchchar))
	 			{ 
					alert('Please enter Valid Name!');
					return false;
				}
		
	if (!CheckBlank(document.form2.pDesignation,'Designation'))return false;
				if (!Desig.match(tomatchchar))
	 			{ 
					alert('Please enter Valid Designation!');
					return false;
				}
				
	if (!CheckBlank(document.form2.pEmail,'Email'))return false;
	if (!CheckEmail(document.form2.pEmail,'Email'))return false;
	if (!CheckBlank(document.form2.pUrl,'Url'))return false;
				if (!Url.match(tomatchurl))
	 			{ 
					alert('Please enter Valid URL!');
					return false;
				}
				
	if (!CheckBlank(document.form2.pTelephone,'Telephone'))return false;
	//if (!ValidPhone(document.form2.pTelephone,'Telephone'))return false;
	if (!phone.match(tomatchdigit))
	 	{ 
			alert('Please enter valid Phone number!');
			return false;
		}
	if (!employees.match(tomatchnumbers))
	 	{ 
			alert('Please enter Number of Employees!');
			return false;
		}
	if (!Clients.match(tomatchnumbers))
	 	{ 
			alert('Please enter Number of Clients!');
			return false;
		}	
	
	if (
		document.form2.chk_pSearchEngineOptimisation.checked == false &&
		document.form2.chk_pPaidSearchMarketing.checked == false &&
		document.form2.chk_pUsabilityConsulting.checked == false &&
		document.form2.chk_pSocialMediaOptimisation.checked == false &&
		document.form2.chk_pUsabilityManagement.checked == false
		) 
	{
		alert ('Choose any of the Services!');
		return false;
	}
	if (!CheckBlank1(document.form2.pimgid,'Question'))return false;
	 else { 	
		return true;
	}
	
}