function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	 catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	 }
	return xmlHttp;
}

function href(id)
{
	var xx=document.getElementById(id).title;
	xmlHttp_str=GetXmlHttpObject()
	if (xmlHttp_str==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	 
	//var url="http://www.ipwebsitehosting.com/session.php";
	//var url="http://localhost/phrase/session.php";
	var url=main_url+"session.php";
	var str=id.search(/article/i);

	if(str==0)
		url=url+"?art=1&sid="+Math.random();
	else
		url=url+"?sid="+Math.random() ;
	//alert(url);
	xmlHttp_str.onreadystatechange=function() 
	{ 
		if (xmlHttp_str.readyState==4 || xmlHttp_str.readyState=="complete")
		 { 
				 if( xmlHttp_str.responseText ==1)
				 {
					 	window.location=xx;
						
				 }
		 } 
	}
	xmlHttp_str.open("GET",url,true)
	xmlHttp_str.send(null) 
}

// 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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
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){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
/*if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+3)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false*/
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length );
}

function chk_data()
{
		var flag=0;
		var name=document.getElementById('name');
		var email=document.getElementById('email');
		var contactno=document.getElementById('contactno');
		var location=document.getElementById('location');
		var interested=document.getElementById('interested');
		var captcha=document.getElementById('captcha_error');
		
		if(name.value=="")
		{
				name.style.border = "1px solid red";
				flag=1;
		}
		else
				name.style.border = "1px solid #A6A6A6";
		
		if(contactno.value=="")
		{
				contactno.style.border = "1px solid red";
				flag=1;
		}
		else
		{
			if(checkInternationalPhone(contactno.value)==false)
			{
				alert("Please Enter a Valid Contact Number")
				contactno.value='';
				contactno.focus();
				contactno.style.border = "1px solid red";
				flag=1;
			}
			else
				contactno.style.border = "1px solid #A6A6A6";
		}
				
		if(location.value=="")
		{
				location.style.border = "1px solid red";
				flag=1;
		}
		else
				location.style.border = "1px solid #A6A6A6";
		
		if(interested.value=="")
		{
				interested.style.border = "1px solid red";
				flag=1;
		}
		else
				interested.style.border = "1px solid #A6A6A6";
		if(email.value=="")
		{
				email.style.border = "1px solid red";
				flag=1;
		}
		else
		{
		var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		 var address = email.value;
		 if(reg.test(address) == false) {
				email.style.border = "1px solid red";
				alert('Invalid Email Address');
				email.value='';
				email.focus();
				flag=1;
		 }
		 else
				email.style.border = "1px solid #A6A6A6";
		}
			
		if(captcha.value==0)
		{
				document.getElementById('txtCaptcha').style.border = "1px solid red";
				flag=1;
		}
		else
				document.getElementById('txtCaptcha').style.border = "1px solid #A6A6A6";
		
		if(flag==0)
		{
			document.myform.action='mail.php';
			document.myform.submit();
		}
									
}

function setValue()
{
		document.getElementById('val').value=0;
}
