function isCharsInBag (s, bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is 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) return(false);
    }
    return true;
}
  
function isValidChar(testingStr, userStr)
{
	var condition = true; 

	for(counter=0; counter < testingStr.length; counter++)
	{
		if(testingStr.indexOf(userStr.charAt(counter)) == -1)
		{
			condition = false;
		}
	}
	
	return condition;
}
function EmailCheck(email){
		
		if(email.value==''){
			alert("Please Enter Email Address");
            email.focus();            
            return false;
		}
		if ( !this.isCharsInBag( email.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@-" ))
		{
		      
            alert("Invalid Email Address");
            email.focus();            
            return false;
		}
	
	if(email.value != '')
	   {
		var str=email.value;	
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var sdot=str.indexOf(dot,ldot+1);

		if (str.indexOf(at)==-1){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		if (str.substring(ldot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.substring(sdot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if(str.lastIndexOf(".") == str.length-1)
		 {
		 	alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
	}//end of else
	return true;
}
function validateCVForm()
{
	var yname = document.frmCV.yname;
	if (yname.value == "")
	{
		alert("Please Fill the 'Your Name' field.");
		yname.focus();
		return false;
	}
	var cv = document.frmCV.cv;
	if (cv.value == "")
	{
		alert("Please Fill the 'Your CV' field.");
		cv.focus();
		return false;
	}
	var comments = document.frmCV.comments;
	if (comments.value == "")
	{
		alert("Please Fill the 'Comments' field.");
		comments.focus();
		return false;
	}
}
function divShowhide(chkDiv)
{
	//alert("abc");
	
	objDiv = document.getElementById(chkDiv);
		
		if (objDiv.style.display == 'none')
		{
			objDiv.style.display = 'inline';
		}
		
		else if (objDiv.style.display == 'inline')
		{
			objDiv.style.display = 'none';
		}
}
var hWnd
function OpenNewWindow( passurl , width, height, left, top)
{
	//var x = screen.availWidth/2-200;
//	var x = (screen.availWidth-width);
//	var y = 150;

	var x = left;
	var y = top;

	enterCalled = true
	window.name = "parent"
	var url = passurl
	if( !hWnd )
	{
		//if no help window is open then open a new help window and give it focus
		hWnd = window.open(url,"popup","width=" + width + ",height=" + height +", left=" + x + ", top=" + y + ", resizable=yes,scrollbars=yes")
		hWnd.focus()
	}
	else if ( hWnd.closed ) 
	{
		//if no help window is open then open a new help window and give it focus
		hWnd = window.open(url,"popup","width=" + width + ",height=" + height +", left=" + x + ", top=" + y + ", resizable=yes,scrollbars=yes")
		hWnd.focus()
	}
	else
	{
		//if the help window is already open then update it and give it focus
		hWnd.location=url
		hWnd.focus()
	}
	// handle Navigator 2, which doesn't have an opener property
	if (!hWnd.opener) { hWnd.opener = window}
}
// my address finder code end  here

function ctbWnd(url)
{
	var width = screen.width;
	var height = screen.height;
	var ctbWnd = window.open(url,"ctbWnd","status=1,resizable=1,width=" + width + ",height=" + height);
	ctbWnd.moveTo(0,0);
}

function Registration()
{
	var name = document.frmyourdetails.txtname;
	var email = document.frmyourdetails.txtemail;
	var postcode = document.frmyourdetails.txtphone;
	if (name.value == "")
	{
		alert("Please Fill the 'Name' field");
		name.focus();
		return false;
	}
	if (postcode.value == "")
	{
		alert("Please Fill the 'Contact Number' field");
		postcode.focus();
		return false;
	}
	if(!this.EmailCheck(email))
	{
		return false ;
	}
	return true;	
}
function UserLogin()
{
	var login = document.frmlogin.txtLogin.value;
	var pass  = document.frmlogin.txtPassword.value;
	if(login=='')
	{
		alert("Please enter user name.");
		document.frmlogin.txtLogin.focus();
		return false;
	}
	if(pass=='')
	{
		alert("Please enter password.");
		document.frmlogin.txtPassword.focus();
		return false;
	}
	return true;
}
function UserLogin2()
{
	
	var login = document.frmlogin2.txtLogin2.value;
	var pass  = document.frmlogin2.txtPassword2.value;
	if(login=='')
	{
		alert("Please enter user name.");
		document.frmlogin2.txtLogin2.focus();
		return false;
	}
	if(pass=='')
	{
		alert("Please enter password.");
		document.frmlogin2.txtPassword2.focus();
		return false;
	}
	return true;
}
readMoreLinks = new Array();
function readNewsMore(id){
	id = 'news'+id;
	document.getElementById(id+'more').style.display = 'block';
	readMoreLinks.push(readMoreLinks.push({'id':id+'moreLink', 'link':document.getElementById(id+'moreLink')}));
	document.getElementById(id).removeChild(document.getElementById(id+'moreLink'));
}
function readNewsLess(id){
	id = 'news'+id;
	document.getElementById(id+'more').style.display = 'none';
	for( itm in readMoreLinks){
		if(id+'moreLink' == readMoreLinks[itm].id){
			document.getElementById(id).appendChild(readMoreLinks[itm].link);
			break;
		}
	}
}