//Check login form validation

function checkLoginForm(loginform)
{
	  var why = "";

	  why += isEmpty(loginform.username.value,' Email is empty.\n');
	  why += isEmpty(loginform.password.value,' Password is empty.\n');

	  why += checkEmail(loginform.username.value);

          if (why != "")
	  {
	    alert(why);
	    return false;
	  }
	
	  return true;
}




//Check simple search by Profile ID form validation

function checkSearch(homesearchprofile)
{

if(homesearchprofile.pid.value=="" || homesearchprofile.pid.value=="View by Profile ID")
	{
	    alert('ProfileId is empty');
		return false;
	  }
	  return true;
}



//Div hide and show search by profile id and browse Profiles


function showCriterias(res)
{
  var s = res;

  if(s=='gender')
  {
   document.getElementById('profile').style.display = "none"; 
   document.getElementById('gender').style.display = ""; 
  }
  else if(s=='profile')
  {
   document.getElementById('gender').style.display = "none"; 
   document.getElementById('profile').style.display = "";
  }
}

// For any in dropdown

function anyrel(val)
{

if(val==0)
{
document.getElementById('hidecasteid').style.display='none';
}
else
{
document.getElementById('hidecasteid').style.display='';
}
}

//For simple search validation


function checkSearchForm(homesearch)
{
	  var why = "";
	  why += checkDropdown(homesearch.gender.selectedIndex, 'You have not selected gender.\n');		
          if (why != "")
	  {
	    alert(why);
	    return false;
	  }
	
	  return true;
}





//For advance search validation

function checkSearchForm11()
{
	  if(homeSearch.gender.value =="" || homeSearch.gender.value =='0')
	  {
	  
	  
	  var why = "";
	 
	  why += checkDropdown(homeSearch.gender.selectedIndex, 'You have not choosed gender.\n');		
		 	 
          if (why != "")
	  {
	    alert(why);
	    return false;
	  }
}
	    return true;
}

function anyrelAdvancesearch(val)
{

if(val==0)
{
document.getElementById('caste').disabled="disabled";

}
else
{
document.getElementById('caste').disabled="";
}
}

function anycountry(val)
{

if(val==0)
{
document.getElementById('statesid').disabled="disabled";
}
else
{
document.getElementById('statesid').disabled="";
}
}



//Ragistration form validation

function otherHoby(hobyVal)
{
if(hobyVal=='Others')
{
document.getElementById("hobyOther").style.display='';
document.getElementById("texthobby").style.display='';
document.getElementById("hobbies").style.display='';

}
else
{
document.getElementById("texthobby").style.display='none';
document.getElementById("hobyOther").style.display='none';
document.getElementById("hobbies").style.display=''; 
}
}


function removeAllOptions(selectbox)
	{
		var i;
		for(i=selectbox.options.length-1;i>=0;i--){
			//selectbox.options.remove(i)
			selectbox.remove(i);
		}
	}
function addOption(selectbox, value, text )
	{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
	}

function validate(identifier, params) {
    var fldid = identifier;
    var idname = identifier+"_id";
    var elem = document.getElementById(idname);
    var fld = document.getElementById(fldid);

    var valAjax =  {
    	      handleSuccess: function(o) {
            this.processResult(o);
        },

     handleFailure: function(o) {
     elem.innerHTML = "<font style='font-size: 10pt;' color='#990000'>Validation not working. Please contact support</font>"; 
    },

    processResult: function(o) {
     if (o.responseText !== undefined) {
       eval("var result = "+ o.responseText);
       if (result['status']) {
          var e = result['element'];

          if(e == 'state'){
	    removeAllOptions(document.regform.statesid);
	    addOption(document.regform.statesid, "0",'--Select State--');
  //	    alert(result['message'].length);
            for(i = 0; i< result['message'].length; i++){
              addOption(document.regform.statesid,result['message'][i][0], result['message'][i][1]);
	    }
          }
          if(e == 'sector'){
	    removeAllOptions(document.regform.occupation_sector);
	    addOption(document.regform.occupation_sector, "0",'--Select Occupation Sector--');
  //	    alert(result['message'].length);
            for(i = 0; i< result['message'].length; i++){
              addOption(document.regform.occupation_sector,result['message'][i][0], result['message'][i][1]);
	    }
          }
          if(e == 'caste'){
	    removeAllOptions(document.regform.caste);
	    addOption(document.regform.caste, "0",'--Select Sect--');
  //	    alert(result['message'].length);
            for(i = 0; i< result['message'].length; i++){
              addOption(document.regform.caste,result['message'][i][0], result['message'][i][1]);
	    }
          }
          if(e == 'subcaste'){
	    removeAllOptions(document.regform.sub_caste);
	    addOption(document.regform.sub_caste, "0",'--Select SubSect--');
  //	    alert(result['message'].length);
            for(i = 0; i< result['message'].length; i++){
              addOption(document.regform.sub_caste,result['message'][i][0], result['message'][i][1]);
	    }
          }
          
        
	//elem.innerHTML = "<font style='font-size: 8pt; font-weight: bold;' color='#009900'>" + result['message2'] + "</font>";
       } else {
          elem.innerHTML = "<font style='font-size: 8pt; font-weight: bold;' color='#990000'>" + result['message'] + "</font>";
      }
     }
  },

       startRequest: function() {
           sURL = "http://{/literal}{$smarty.server.HTTP_HOST}:{$smarty.server.SERVER_PORT}/{$section}/validator?id="+identifier+"&"+getPart;{literal}
	    var request = YAHOO.util.Connect.asyncRequest('GET', sURL, callback);
        }
    };

    var callback =
    {
	success: valAjax.handleSuccess,
        failure: valAjax.handleFailure,
        scope: valAjax,
	argument: [],
	timeout: 5000
    };

    getPart = "";
    for (key in params) {
	getPart += key+"="+params[key]+"&";
    };
    valAjax.startRequest();
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=768,left = 270,top = 0');");
}





///////////////////packagedetail in home


function paymentModeSelect()
{
if ((document.upgradePackage.modeP[0].checked == false) && (document.upgradePackage.modeP[1].checked == false))
{
alert('Please Choose a Payment Option');
return false;
}
}




function paymentModeSelect()
{
if(document.upgradePackage.subscription_id[0].checked == false && document.upgradePackage.subscription_id[1].checked == false && document.upgradePackage.subscription_id[2].checked == false && document.upgradePackage.subscription_id[3].checked == false)
{
alert('Please Choose a Payment Option');
return false;
}

else if(document.upgradePackage.subscription_id[1].checked == true)
{
	if((document.upgradePackage.modeP[0].checked == false) && (document.upgradePackage.modeP[1].checked == false))
	{
	alert('Please Choose a Payment Option');
	return false;
	}
}

else if(document.upgradePackage.subscription_id[2].checked == true)
{
	if((document.upgradePackage.modeP[0].checked == false) && (document.upgradePackage.modeP[1].checked == false))
	{
	alert('Please Choose a Payment Option');
	return false;
	}
}

else if(document.upgradePackage.subscription_id[3].checked == true)
{
	if((document.upgradePackage.modeP[0].checked == false) && (document.upgradePackage.modeP[1].checked == false))
	{
	alert('Please Choose a Payment Option');
	return false;
	}
}

else if(document.upgradePackage.subscription_id[4].checked == true)
{
	if((document.upgradePackage.modeP[0].checked == false) && (document.upgradePackage.modeP[1].checked == false))
	{
	alert('Please Choose a Payment Option');
	return false;
	}
}
return true;
}

function shownotFree(getvalue)
{

if(getvalue==1)
{
document.getElementById('free').style.display="none"
}
else
{
document.getElementById('free').style.display=""

}
}



//For userpage after login

function showsearch_basic_id()
{
document.getElementById('bysearchopen_basic_id').style.display="none";
document.getElementById('bysearchclose_basic_id').style.display="";
document.getElementById('basic_id').style.display="";
}


function closesearch_basic_id()
{
document.getElementById('bysearchopen_basic_id').style.display="";
document.getElementById('bysearchclose_basic_id').style.display="none";
document.getElementById('basic_id').style.display="none";
}
/* End For basic */


/* For education */
function showsearch_education_id()
{
document.getElementById('bysearchopen_education_id').style.display="none";
document.getElementById('bysearchclose_education_id').style.display="";
document.getElementById('education_id').style.display="";
}

function closesearch_education_id()
{
document.getElementById('bysearchopen_education_id').style.display="";
document.getElementById('bysearchclose_education_id').style.display="none";
document.getElementById('education_id').style.display="none";
}
/* End For education */

/* For family */
function showsearch_family_id()
{
document.getElementById('bysearchopen_family_id').style.display="none";
document.getElementById('bysearchclose_family_id').style.display="";
document.getElementById('family_id').style.display="";
}

function closesearch_family_id()
{
document.getElementById('bysearchopen_family_id').style.display="";
document.getElementById('bysearchclose_family_id').style.display="none";
document.getElementById('family_id').style.display="none";
}
/* End For family */


/* For location */
function showsearch_location_id()
{
document.getElementById('bysearchopen_location_id').style.display="none";
document.getElementById('bysearchclose_location_id').style.display="";
document.getElementById('location_id').style.display="";
}

function closesearch_location_id()
{
document.getElementById('bysearchopen_location_id').style.display="";
document.getElementById('bysearchclose_location_id').style.display="none";
document.getElementById('location_id').style.display="none";
}
/* End For location */

/* For social */
function showsearch_social_id()
{
document.getElementById('bysearchopen_social_id').style.display="none";
document.getElementById('bysearchclose_social_id').style.display="";
document.getElementById('social_id').style.display="";
}

function closesearch_social_id()
{
document.getElementById('bysearchopen_social_id').style.display="";
document.getElementById('bysearchclose_social_id').style.display="none";
document.getElementById('social_id').style.display="none";
}
/* End For social */

/* For astro */
function showsearch_astro_id()
{
document.getElementById('bysearchopen_astro_id').style.display="none";
document.getElementById('bysearchclose_astro_id').style.display="";
document.getElementById('astro_id').style.display="";
}

function closesearch_astro_id()
{
document.getElementById('bysearchopen_astro_id').style.display="";
document.getElementById('bysearchclose_astro_id').style.display="none";
document.getElementById('astro_id').style.display="none";
}
/* End For astro */

/* For astro */
function showsearch_astro_id()
{
document.getElementById('bysearchopen_astro_id').style.display="none";
document.getElementById('bysearchclose_astro_id').style.display="";
document.getElementById('astro_id').style.display="";
}

function closesearch_astro_id()
{
document.getElementById('bysearchopen_astro_id').style.display="";
document.getElementById('bysearchclose_astro_id').style.display="none";
document.getElementById('astro_id').style.display="none";
}
/* End For astro */


/* For contact */
function showsearch_contact_id()
{
document.getElementById('bysearchopen_contact_id').style.display="none";
document.getElementById('bysearchclose_contact_id').style.display="";
document.getElementById('contact_id').style.display="";
}

function closesearch_contact_id()
{
document.getElementById('bysearchopen_contact_id').style.display="";
document.getElementById('bysearchclose_contact_id').style.display="none";
document.getElementById('contact_id').style.display="none";
}
/* End For contact */

/* For other */
function showsearch_other_id()
{
document.getElementById('bysearchopen_other_id').style.display="none";
document.getElementById('bysearchclose_other_id').style.display="";
document.getElementById('other_id').style.display="";
}

function closesearch_other_id()
{
document.getElementById('bysearchopen_other_id').style.display="";
document.getElementById('bysearchclose_other_id').style.display="none";
document.getElementById('other_id').style.display="none";
}
/* End For contact */



function closetable(idd)
{
document.getElementById(idd).style.display="none";

}


function closethisid(id)
{
document.getElementById(id).style.display="none";
document.getElementById('accountsummarycloseid').style.display="";
document.getElementById('accountsummaryopenidtable').style.display="none";

}

function openthisidd(id)
{
document.getElementById(id).style.display="none";
document.getElementById('accountsummaryopenid').style.display="";
document.getElementById('accountsummaryopenidtable').style.display="";

}

function composeValidate()
{
if(document.composemessage.id.value=="")
{
alert( "Please enter an id." );
document.composemessage.id.focus();	
return false;
}

if(document.composemessage.id.value=="")
{
alert('Please enter an id');	
return false;
}
if(document.composemessage.message.value=="")
{
document.composemessage.message.focus();	
alert('Please enter some text');
return false;
}
else
{
return true;	
}
	
}