function popcountry()
{
    var c;
    var docF=document.form1;
    for(var i=0;i< docF.elements.length;i++)
    {
    	var element1=docF.elements[i];
    	if(element1.name=="city")
    		break;
    }

    for(var i=0;i< docF.elements.length;i++)
    {
    	var element2=docF.elements[i];
    	if(element2.name=="country")
    		break;
    }

    // country element may not be present in validate form, so we need to check below to ensure that no error occurs
    if(element2.name=="country"){
    if(element1.value != "Other" && element1.value!="")
    {
        var len_course2 = element2.options.length;
        for(var m2=1;m2<len_course2;m2++)
        {
			c = element2.options[m2].value;
			if(c == "INDIA")
			{
        		element2.options[m2].selected = true;
        		//docF.rpisd.value="91";
				//docF.opisd.value="91";
        		return;
			}
			else
			{
				element2.options[m2].selected = false;
			}
        }
	}}
}

function PopSPEC(thisform,element1,element2) 
{
	var docF=document.form1;
	if(trim(thisform.value) != "")
	{
		var c,spec;
		var len_course = docF.elements[element1].options.length;
		for(var m1=0;m1<len_course;m1++) {
		if (docF.elements[element1].options[m1].selected == true) {
		c = docF.elements[element1].options[m1].value;
		}
		}

		docF.elements[element2].options.length = 0;

		var str      =c.split("|X|");
		var spec_val =str[1].split("#");

		for(var k=0;k<spec_val.length;k++) {
		var s = spec_val[k];
		if(s){
		var opt = new Option();
		opt.text=s;
		opt.value=s;
		docF.elements[element2].options[docF.elements[element2].options.length] = opt;
		}}
	}

	return true;
}

function PopSFA(thisform,element1,element2,element3) 
{
	var docF=document.form1;
	if(trim(thisform.value) != "")
	{
   		var subfun, role;
		var i = 0, j = 0;
		var tempsubfun, temprole;
		var c,t,strsub_sfarea = "",strsub_role = "",str,len_sfarea,len_role,i;
		str="";

		len_sfarea = docF.elements[element2].options.length;
		len_role = docF.elements[element3].options.length;
		strsub_sfarea = new Array();
		strsub_role = new Array();

		//collect info of selected sfarea and Deselect selected items
		for(var m1=0;m1<len_sfarea;m1++) {
		if (docF.elements[element2].options[m1].selected == true) {
		strsub_sfarea[i++] = docF.elements[element2].options[m1].text;
		}
		docF.elements[element2].options[m1].selected = false;
		}

		//collect info of selected role and Deselect selected items
		for(var m1=0;m1<len_role;m1++) {
		if (docF.elements[element3].options[m1].selected == true) {
		strsub_role[j++] = docF.elements[element3].options[m1].text;
		}
		docF.elements[element3].options[m1].selected = false;
		}

		//Clear Select Box
		docF.elements[element2].options.length = 0;
		docF.elements[element3].options.length = 0;

		//Add Items related with selected category
		for(var i=0; i< docF.elements[element1].options.length; i++) {
		if(docF.elements[element1].options[i].selected) {
		c=docF.elements[element1].options[i].value;
		t=docF.elements[element1].options[i].text;

		if(c.length > 0 ) {
		var opt = new Option();

		var str    =c.split("|X|");
		var sfarea =str[1].split(",");
		var role    =str[2].split(",");

		//populate optionlist for sfarea
		for(var k=0;k<sfarea.length;k++) {
		var s = sfarea[k];
		if(s){
		tempsfarea = s.split("#");

		var opt = new Option();
		opt.text=tempsfarea[1];
		opt.value=str[0]+"."+tempsfarea[0];
		docF.elements[element2].options[docF.elements[element2].options.length] = opt;
		if(tempsfarea[1]==t) {
		opt.selected=true;
		}}}

		//populate optionlist for role
		for(var k=0;k<role.length;k++) {
		var s = role[k];
		if(s){
		temprole = s.split("#");

		var opt = new Option();
		opt.text=temprole[1];
		if(temprole[2] == "0")
		opt.value="none";
		else
		opt.value=str[0]+"."+temprole[0];
		docF.elements[element3].options[docF.elements[element3].options.length] = opt;
		if(temprole[1]==t) {
		opt.selected=true;
		}}}
		}}}

		//Maintain Previously Selected Item for sfarea
		for(var i = 0; i< docF.elements[element2].options.length;i++) {
		var v = docF.elements[element2].options[i].text;

		for (var l = 0; l < strsub_sfarea.length; l++) {
		if(strsub_sfarea[l]== v) {
		 docF.elements[element2].options[i].selected = true;
		}
		}
		}

		//Maintain Previously Selected Item for role
		for(var i = 0; i< docF.elements[element3].options.length;i++) {
		var v = docF.elements[element3].options[i].text;

		for (var l = 0; l < strsub_role.length; l++) {
		if(strsub_role[l]== v) {
		 docF.elements[element3].options[i].selected = true;
		}
		}
		}
	}
	else
	{
		//Clear Select Box
        docF.elements[element2].options.length = 0;
        docF.elements[element3].options.length = 0;
	}
	return true;
}

function checkNoselect(thisform)
{
for(var i=0; i< thisform.options.length; i++) {
if(thisform.options[i].selected && thisform.options[i].value == "none") {
alert("You can not select this option.");
thisform.options[i].selected = false;
break;
}
}
}

function checkCat_IT(thisform,limit,element1,element2)
{
var c=0;
var docF=document.form1;
var p=docF.elements[element1].value;
var str=p.split("|X|");
if(str[0] == "24"){
for(var i=0; i< docF.elements[element2].options.length; i++) {
if(docF.elements[element2].options[i].selected) {
c++;
}
}
if(c>limit && limit){
alert("You can choose "+limit+" category only for this particular functional area");
for(var i=0; i< docF.elements[element2].options.length; i++) {
if(docF.elements[element2].options[i].selected) {
docF.elements[element2].options[i].selected = false;
//c++;
}
}
}
}
return true;
}

function checkCat(thisform,limit)
{
var c=0;
for(var i=0; i< thisform.options.length; i++) {
if(thisform.options[i].selected) {
c++;
}
}
if(c>limit && limit){
alert("Please choose "+limit+" categories only !");
//thisform.focus();
}

return true;
}

function validate()
{
	if(trim(document.form1.email.value)!="")
	{
		var str=document.form1.email.value;
		var i;
		var final1,mystr;
		final1=str.length;
		for(i=0;i<=final1;)
		{
			if(str.indexOf(",")!=-1)
			{
				mystr=trim(str.substring(0,str.indexOf(",")));
				i=str.indexOf(",")+1;
				str=str.substring(i);

				if(mystr!="")
				{
					if(!checkemail(mystr,mystr + " is not a valid E-mail Address."))
					{
						return false;
					}
				}
			}
			else
			{
				if(trim(str)!="")
				{
					if(!checkemail(trim(str),trim(str) + " is not a valid E-mail Address."))
					{
						return false;
					}
				}
				break;
			}
		}
	}

	return true;
}

function checkemail(emailadd,name)
{
	var result = false
  	var theStr = new String(emailadd)
  	var index = theStr.indexOf("@");
  	if (index > 0)
  	{
    	var pindex = theStr.indexOf(".",index);
    	if ((pindex > index+1) && (theStr.length > pindex+2))
		result = true;
  	}
  	if (!result)
  		alert(name);

  	return result;
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function changePhoneIsd()
{
	var docF=document.form1;
	if(docF.country.value=="INDIA")
	{
		docF.rpisd.value="91";
		docF.opisd.value="91";
	}
}

function checkOneIT()
{
	var e,k=0;
	for(var i=0;i<document.form1.elements.length;i++)
	{
		e=document.form1.elements[i];
		if(e.name=="subfun[]")
			break;
	}
	
	for(var j=0;j<e.options.length;j++)
	{
		if(e.options[j].selected)
			k++;
	}
	
	if(k>1)
	{
		alert("You can choose one category only for this particular functional area");
		for(var j=0;j<e.options.length;j++)
		{
			e.options[j].selected=false;
		}
		return false;
	}
	
	return true;
}

function Validator(theForm)
{
  if (theForm.loginname.value == "")
  {
    alert("Please enter Username.");
    theForm.loginname.focus();
    return (false);
  }
  if(VerifyEmailAddress(theForm.loginname.value))
		{
		}
		else
		{
			
			theForm.loginname.focus();
			 return (false); 
		}

  if (theForm.password.value == "")
  {
    alert("Please enter Password.");
    theForm.password.focus();
    return (false);
  }
  if (theForm.password.value != theForm.confirm_password.value)
  {
  	alert("Password and Confirm Password do not match...!!!");
	theForm.password.focus();
	return(false);
  }
  if (theForm.confirm_password.value == "")
  {
    alert("Please Confirm Password.");
    theForm.confirm_password.focus();
    return (false);
  }
  if (theForm.CurIndustryGroup.value == "")
  {
    alert("Please Select Current Industry Group.");
    theForm.CurIndustryGroup.focus();
    return (false);
  }
  if (theForm.DesIndustryGroup.value == "")
  {
    alert("Please Select Desired Industry Group.");
    theForm.DesIndustryGroup.focus();
    return (false);
  }
  if (theForm.headline.value == "")
  {
    alert("Please enter Resume Headline");
    theForm.headline.focus();
    return (false);
  }
    return (true);
}
function Validator1(theForm)
{ 
 if (theForm.firstname.value == "")
  {
    alert("Please enter First Name.");
    theForm.firstname.focus();
    return (false);
  }
   // if (theForm.email1.value == "")
  //{
  //  alert("Please enter E-Mail1.");
   // theForm.email1.focus();
    //return (false);
 // }
  if (theForm.ugcourse.value == "Select")
  {
    alert("Please Select Graduation.");
    theForm.ugcourse.focus();
    return (false);
  }
  if (theForm.total_exp.value == "")
  {
    alert("Please enter Total Experience.");
    theForm.total_exp.focus();
    return (false);
  }
  if (theForm.key_skills.value == "")
  {
    alert("Please enter Key Skills.");
    theForm.key_skills.focus();
    return (false);
  }
 var n=0;
  var otherThanFirstSelected = false;
  var theOptions = theForm.DesCategory.options;
  for (n = 0; n < theOptions.length; n++)
  {  
     if (theOptions[n].selected == true)
	{
		otherThanFirstSelected = true;
		n = theOptions.length;						      
	}
  }
  if (otherThanFirstSelected == false) 
  {
        alert("Please select Desired Category");
		return false;
  }
  
  var n=0;
  var otherThanFirstSelected = false;
  var theOptions = theForm.desired_joblocation.options;
  for (n = 0; n < theOptions.length; n++)
  {  
     if (theOptions[n].selected == true)
	{
		otherThanFirstSelected = true;
		n = theOptions.length;						      
	}
  }
  if (otherThanFirstSelected == false) 
  {
        alert("Please select Desired Job Location");
		return false;
  }
 /*alert(theForm.DesCategory.value);
  if (theForm.DesCategory.options.value == "")
  {
    alert("Please Select Desired Job Category.");
    theForm.DesCategory.focus();
    return (false);
  }
  alert(theForm.desired_joblocation.value)
  if (theForm.desired_joblocation.selectedIndex==-1)
  {
    alert("Please Select Desired Job Location.");
    theForm.desired_joblocation.focus();
    return (false);
  }*/
 
  return (true);
}

function EditResume(theForm)
{ 
 if (theForm.firstname.value == "")
  {
    alert("Please enter First Name.");
    theForm.firstname.focus();
    return (false);
  }
  if (theForm.birthdate.value == "")
  {
    alert("Please enter Birthdate.");
    theForm.birthdate.focus();
    return (false);
  }
   if (theForm.CurIndustryGroup.value == "")
  {
    alert("Please Select Current Industry Group.");
    theForm.CurIndustryGroup.focus();
    return (false);
  }
  if (theForm.DesIndustryGroup.value == "")
  {
    alert("Please Select Desired Industry Group.");
    theForm.DesIndustryGroup.focus();
    return (false);
  }
  if (theForm.headline.value == "")
  {
    alert("Please enter Resume Headline");
    theForm.headline.focus();
    return (false);
  }	
 return (true);
}
function EditResume1(theForm)
{
  if (theForm.ugcourse.value == "Select")
  {
    alert("Please Select Graduation.");
    theForm.ugcourse.focus();
    return (false);
  }
  if (theForm.total_exp.value == "")
  {
    alert("Please enter Total Experience.");
    theForm.total_exp.focus();
    return (false);
  }
  if (theForm.key_skills.value == "")
  {
    alert("Please enter Key Skills.");
    theForm.key_skills.focus();
    return (false);
  }
 var n=0;
  var otherThanFirstSelected = false;
  var theOptions = theForm.DesCategory.options;
  for (n = 1; n < theOptions.length; n++)
  {  
     if (theOptions[n].selected == true)
	{
		otherThanFirstSelected = true;
		n = theOptions.length;						      
	}
  }
  if (otherThanFirstSelected == false) 
  {
        alert("Please select Desired Category");
		return false;
  }
  
  var n=0;
  var otherThanFirstSelected = false;
  var theOptions = theForm.desired_joblocation.options;
  for (n = 1; n < theOptions.length; n++)
  {  
     if (theOptions[n].selected == true)
	{
		otherThanFirstSelected = true;
		n = theOptions.length;						      
	}
  }
  if (otherThanFirstSelected == false) 
  {
        alert("Please select Desired Job Location");
		return false;
  }
 /*alert(theForm.DesCategory.value);
  if (theForm.DesCategory.options.value == "")
  {
    alert("Please Select Desired Job Category.");
    theForm.DesCategory.focus();
    return (false);
  }
  alert(theForm.desired_joblocation.value)
  if (theForm.desired_joblocation.selectedIndex==-1)
  {
    alert("Please Select Desired Job Location.");
    theForm.desired_joblocation.focus();
    return (false);
  }*/
 
  return (true);
}


function VerifyEmailAddress(checkStr)
{
  var Reason  = "Your Email Address appears incorrect.  \n\nPlease check. \n\nReason:";
  var Success = "Email Address entered Correctly!";
  //var checkStr = document.purchase.bemail.value;
  var ix = (checkStr.length - 4)
  var RC = true;
  var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = RL = 0;
  for (i = 0;  i < checkStr.length;  i++)
  {
    if (checkStr.charAt(i) == '@')
      AtSignValid++;
    else if (checkStr.charAt(i) == '.')
    {
      if (x == (i-1))
        DoublePeriod++;
      else
      {
        x = i;
        PeriodValid++;
      }
    }
    else if (checkStr.charAt(i) == ' ')
      SpaceValid ++;
  }
  if (checkStr.indexOf(".com", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".edu", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".net", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".org", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".gov", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".mil", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".cc", ix) > -1)
    ExtValid++;
  RL = Reason.length;
  if (AtSignValid != 1)
    Reason += "\nOnly one '@' allowed, " + AtSignValid + " found.";
  if (PeriodValid == 0)
    Reason += "\nAddress must contain at least one period.";
  if (SpaceValid > 0)
    Reason += "\nNo Spaces allowed. Address contains " + SpaceValid + " space";
  if (SpaceValid > 1)
    Reason += "s.";
  if (checkStr.length > 120)
    Reason += "\nPlease limit the Email Address to 120 characters.";

  if (RL != Reason.length)
  {
 alert(Reason);
 return false;
  }
  return true;
}

