function subcribe1() 
{ 
	document.getElementById("comNews").innerHTML=""; 
} 

function subcribeNews()
{
	var name=window.document.frmipo.name.value;
	var email=window.document.frmipo.email.value;
	var country=window.document.frmipo.country.value;
	
	if(name=="" || email=="" || country=="")
	{
	 alert("All fields need to be complete in full.");
	 return false;
	}
	if(echeck(email)== false)
	{return false;}
		
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="comnews.php"
url=url+"?name="+name
url=url+"&email="+email
url=url+"&country="+country
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
window.document.frmipo.name.value="";
window.document.frmipo.email.value="";
window.document.frmipo.country.value="";
document.getElementById("comNews").innerHTML=xmlHttp.responseText 
} 
} 

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}



function lsawards()
{
var coid=window.document.frm.coid1.value;
var logo=window.document.frm.logo.value;
   window.open('awards.php?coid='+coid+'&limit='+0+'&logo='+logo,'popupwin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=0,top=0,width=300,height=450');
}

function companyWeb(url)
{
 window.open('http://'+url,'popupwin');
}

function downloads(name,coid)
{
 window.open('http://www.dsi.lk/system/docs/'+coid+'/'+name,'popupwin');
}

function coperateDownloads(name)
{
 window.open('http://www.dsi.lk/system/docs/group/'+name,'popupwin');
}

function cv()
{
 window.open('./pub/cv.dot','popupwin');
}

function nextPass()
{
	var no=window.document.frm.nextOne2.value;
	var coid=window.document.frm.coid1.value;
	var logo=window.document.frm.logo.value;
	location.href = "awards.php?limit="+no+"&coid="+coid+"&logo="+logo;	
	
}

function backPass()
{
	var no=window.document.frm.backOne2.value;
	var coid=window.document.frm.coid1.value;
	var logo=window.document.frm.logo.value;
	location.href = "awards.php?limit="+no+"&coid="+coid+"&logo="+logo;	
}

function closeWindow()
{
	window.close();
}

function search1()
{
 var key=document.frm1.search.value;
 if(key==''){
 return false;
 }else{
 parent.location.href="search.php?key="+key;
 }
}

//---------------------email validation--------------------------------//
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){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 	
	}


//------------------contact details validation-----------------------------------//
function contactValidation()
{
 var var1=  window.document.frm.realname.value;
 var var2=  window.document.frm.address.value; 
 var var3=  window.document.frm.country.value;
 var var4=  window.document.frm.phone.value;
 var var5=  window.document.frm.fax.value;
 var var6=  window.document.frm.email.value;
 var var7=  window.document.frm.cat.value;
 var var8=  window.document.frm.inquiry.value;
 
 if (var1== '' || var2 ==''|| var3 == 'cnty' || var4 ==''||var5 == ''||var6== '' || var7 ==''||var8 == ''){
	alert("Fields marked with * need to be complete in full.");
	return false;
}
if(echeck(var6)){
return true;
}
return false;
}


//------------------contact details validation-----------------------------------//
function contactValidation1()
{
 var var1=  window.document.frm.realname.value;
 var var2=  window.document.frm.address.value; 
 var var3=  window.document.frm.country.value;
 var var4=  window.document.frm.phone.value;
 var var5=  window.document.frm.fax.value;
 var var6=  window.document.frm.email.value;
 var var7=  window.document.frm.cat.value;
 var var8=  window.document.frm.inquiry.value;
 
 if (var1== '' || var2 ==''|| var3 == 'cnty' || var4 ==''||var5 == ''||var6== '' || var7 ==''||var8 == ''){
	alert("Fields marked with * need to be complete in full.");
	return false;
}
if(echeck(var6)==false){
return false;
}
}

//---------------------only typing numbers---------------------//
function validChars(e, goods) {
	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;
 
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
 
	if (goods.indexOf(keychar) != -1)
		return true;
 
	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
		return true;
 
	return false;
}

//----------------career validation---------------------------------//

function careerValidation()
{
	var name    =  window.document.career.name.value;
 	var gender  =  window.document.career.gender.value; 
 	var dob     =  window.document.career.dob.value;
 	var district=  window.document.career.district.value;
 	var email   =  window.document.career.email.value;
 	var userfile    =  window.document.career.userfile.value;
	
	if (name == '' || gender ==''|| dob == '' || district ==''||email == ''|| userfile== ''){
	alert("Fields marked with * need to be complete in full.");
	return false;
 }
 
 if(get_radio_value()==false)
 {
 	return false;
 }
 
 if(echeck(email)==false){
return false;
}
 
 for (var i=0; i < window.document.career.experienced.length; i++)
 {
 	if (window.document.career.experienced[i].checked)
	{
	  var val = window.document.career.experienced[i].value;
	  if(val=="Yes")
	  {
	  	window.document.career.experience.value="Y";
		if(window.document.career.noyears.value=='')
		{
		   alert("Please insert number of experienced years.");
  			 return false;
		}
	  }
	}
 }

}

//----------------get radio button value---------------------//
function get_radio_value()
{
var rad_val;
for (var i=0; i < window.document.career.category.length; i++)
   {
   if (window.document.career.category[i].checked)
      {
      	rad_val = window.document.career.category[i].value;
		window.document.career.warea.value=rad_val;
		if(rad_val == "Management Training")
		{
			var management=window.document.career.management.value;
			if(management=="")
			{
			 alert("Select the area you wish to apply for under Management Training.");
  			  return false;
			}
			else
			{
			 window.document.career.wareacat.value=management;
			  return true;
			}
		}
		if(rad_val == "Support Services")
		{
			var support=window.document.career.support.value;
			if(support=="")
			{
			 alert("Select the area you wish to apply for under Support Services.");
  			 return false;
			}
			else
			{
			 window.document.career.wareacat.value=support;
			 return true;
			}
		}
		if(rad_val == "Manufacturing &Trading")
		{
			var manufacturing=window.document.career.manufacturing.value;
			if(manufacturing=="")
			{
			 alert("Select the area you wish to apply for under Manufacturing & Trading.");
  			 return false;
			}
			else
			{
			 window.document.career.wareacat.value=manufacturing;
			 return true;
			}
		}
		
      }
   }
}
