// JavaScript Document

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function checkMailId(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) 
   {
      return 0;
   }
}

function phoneValidation(strString)
{
   var strValidChars = "0123456789-+ ";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			return 0;
         }
      }
}

function FindLength(strString,len)
{
	if(strString.length<len)
	{
		return 0;
	}
}

function validateRadioCheckbox(strString) 
{ 
	var total=""
	for(var i=0; i < strString.length; i++)
	{
	if(strString[i].checked)
	total +=strString[i].value + "\n"
	}
	if(total=="")
	{
	return 0;
	}
}


function SubmitCheckForm(chkThis)
	{
	frmCheckform	= chkThis;
	// assigh the name of the checkbox;
	var chks = document.getElementsByName('services[]');

	var hasChecked = false;
	// Get the checkbox array length and iterate it to see if any of them is selected
	for (var i = 0; i < chks.length; i++)
	{
		if (chks[i].checked)
		{
		        hasChecked = true;
			break;
		}
	}
	// if ishasChecked is false then throw the error message
	if (!hasChecked)
	{
		/*alert("Please select at least one Service.");
		chks[0].focus();
		return false;*/
		return 0;
	}
		
}



function DomainVal(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');//list of domain extensions

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	return 0;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	return 0;
		 	 }
		  }
		else	
		  {
		  	 return 0;
		  }
		}
	}
}
else
{
return 0;
}	
}


function contactformVal()
{
	if(trim(document.formcontact.fname.value)==0)
	{
		alert("Please enter your name");
		document.formcontact.fname.focus();
		return false;
	}
	
	if(trim(document.formcontact.email.value)==0)
	{
		alert("Please enter your email address");
		document.formcontact.email.focus();
		return false;
	}
	
	result=checkMailId(document.formcontact.email.value)
	
	if(result==0)
	{
		alert("Invalid email address");
		document.formcontact.email.focus();
		return false;
	}
	
	result=phoneValidation(document.formcontact.phone.value)
	
	if(result==0)
	{
		alert("Invalid phone number");
		document.formcontact.phone.focus();
		return false;
	}
	if(trim(document.formcontact.comments.value)==0)
	{
		alert("Please enter your message");
		document.formcontact.comments.focus();
		return false;
	}
	if(trim(document.formcontact.userdigit.value)==0)
	{
		alert("Please enter security code");
		document.formcontact.userdigit.focus();
		return false;
	}
	

	document.getElementById("loader").style.display="block";
	document.getElementById("loader").innerHTML='<img  src="http://www.techwyseintl.com/images/loading.gif" align="center" alt="" />';
	
	document.formcontact.submit();
	
}


function requestInfo_speakSomeone()
{	
	if(trim(document.contactus_form.fname.value)==0)
	{
		alert("Please enter your name");
		document.contactus_form.fname.focus();
		return false;
	}
	if(trim(document.contactus_form.phone.value)==0)
	{
		alert("Please enter phone number");
		document.contactus_form.phone.focus();
		return false;
	}
	result=phoneValidation(document.contactus_form.phone.value)
	
	if(result==0)
	{
		alert("Invalid phone number");
		document.contactus_form.phone.focus();
		return false;
	}
	if(trim(document.contactus_form.email.value)==0)
	{
		alert("Please enter email address");
		document.contactus_form.email.focus();
		return false;
	}
	result=checkMailId(document.contactus_form.email.value)
	
	if(result==0)
	{
		alert("Invalid email address");
		document.contactus_form.email.focus();
		return false;
	}
	
	/*if(trim(document.contactus_form.domain.value)==0)
	{
		alert("Please enter domain");
		document.contactus_form.domain.focus();
		return false;
	}
	
	result=DomainVal(document.contactus_form.domain.value)
	
	if(result==0)
	{
		alert("Invalid entry of domain");
		document.contactus_form.domain.focus();
		return false;
	}
	if(trim(document.contactus_form.budget.value)==0)
	{
		alert("Please enter your budget");
		document.contactus_form.budget.focus();
		return false;
	}*/
	if(trim(document.contactus_form.comments.value)==0)
	{
		alert("Please enter comments");
		document.contactus_form.comments.focus();
		return false;
	}
	
	result=SubmitCheckForm(document.contactus_form)
	
	if(result==0)
	{
		alert("Select atleast one service");
		return false;
	}
	document.contactus_form.submit();
}

function captcha_refresh()
{
document.getElementById("button_div").src='button.php?'+Math.random();
return false;
}