
function chkAEvailability(){
	
	
	if($('altemail').value.trim() != '') 	{
		
		if($('user_name').value == $('altemail').value)
			{
				$('msg_div').innerHTML = "Email Adddress and Alternate Email address cannot be same.";
				$('altemail').focus();
				displayAlert();
				return false;		
				
			}
			else
			
			{
		var url = 'functions.php?event=auavl';
		var pars = 'altemail='+$F('altemail') ;
		var myAjax = new Ajax.Request(
		url, 
		{
			method: 'POST',
			parameters: pars,
			onComplete: post_chk_aemail
		});	
	} }
}

function post_chk_aemail(originalRequest) {
	result = originalRequest.responseText;
	
	if(result == '<font color="red">Email address already exists</font>') {
		document.getElementById('auser_available').value = 1;
		//document.getElementById('altemail').focus();
	} else {
		document.getElementById('auser_available').value = 0;	
	}
	
	document.getElementById('achk').style.display='inline';
	document.getElementById('achk').innerHTML = result;
}

function openProfinfo(){
	if(document.getElementById('prof').style.display == 'none') {
		document.getElementById('prof').style.display = 'inline';
	} else {
		document.getElementById('prof').style.display = 'none';
	}
}
function openCinfo(){
	if(document.getElementById('det1').style.display == 'none') {
		document.getElementById('det1').style.display = 'inline';
	} else {
		document.getElementById('det1').style.display = 'none';
	}
}


function openMessage(){
	//palert(document.getElementById('msg').style.display);
	if(document.getElementById('msg').style.display == 'none') {
		document.getElementById('msg').style.display = 'inline';
	} else {
		document.getElementById('msg').style.display = 'none';
	}
}

function openFriends(){
	//palert(document.getElementById('msg').style.display);
	if(document.getElementById('frnd').style.display == 'none') {
		document.getElementById('frnd').style.display = 'inline';
	} else {
		document.getElementById('frnd').style.display = 'none';
	}
}

function openBinfo(){
	if(document.getElementById('bud1').style.display == 'none') {
		document.getElementById('bud1').style.display = 'inline';
	} else {
		document.getElementById('bud1').style.display = 'none';
	}
}


function openB1info(id){
	
	if(id == 16) {
		document.getElementById('bud2').style.display = 'inline';
		document.getElementById('bud1').style.display = 'inline';
	} else {
		document.getElementById('bud2').style.display = 'none';
		document.getElementById('bud1').style.display = 'none';
	}
}


/* function to check valid file
extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) {
	document.getElementById('alert_div').style.display = 'none';
	document.getElementById('file_type_ok').value = 1;
	document.getElementById('file_type').style.display = 'none';
	document.getElementById('file_type').innerHTML = "";
} else {
	document.getElementById('file_type_ok').value = 0;
	document.getElementById('file_type').style.display = 'inline';
	document.getElementById('file_type').innerHTML = "Please upload valid (gif/jpg) image file.";
	//displayAlert();
	return false;
}
}
*/

function getsubcategory(fid) { 
	
		req.open('get','functions.php?event=bsc&id='+fid);
		req.onreadystatechange = populatesubject;
		req.send(null);
	
}

function populatesubject() {
		if(req.readyState == 4){
			var response = req.responseText;
			var subList = response.split(',');
			
			ClearOptions(document.frm.TR_SUBCategory_name);
			AddToOptionList(document.frm.TR_SUBCategory_name, '', '--Please Select--');
			
			for(i=0; i < subList.length; i++) {
				//alert(subList[i]);
				if(subList[i] != "" ){
					idnamearr = subList[i].split('|'); 
					AddToOptionList(document.frm.TR_SUBCategory_name, idnamearr[0], idnamearr[1].trim());
				}
			}

	   }
	
	  }


function isURL(argvalue) { 
	urlRegEx = /http[s]?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/;
	var testVal = argvalue.trim(); 
	if(testVal.length > 9 && urlRegEx.test(testVal)) { 
		return true;
	} else { 
		return false; 
	}
}


function hidden_change() {

	document.getElementById('clogo').value = 1;
}

function saveForm() {
	document.getElementById('rmsg').style.display = 'none';
	
	if($('first_name').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter First Name.";
		displayAlert();
		document.getElementById('det').style.display = 'inline';
		$('first_name').focus();
		return false;
	}
	if($('last_name').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Last Name.";
		$('last_name').focus();
		displayAlert();
		return false;
	}
	
	
	if($('altemail').value.trim() != '') {
		var reAEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if($('altemail').value.length > 5 && reAEmail.test($('altemail').value)) {
		} else {
			$('msg_div').innerHTML = "Please enter valid Alternate Email address.";
			$('altemail').focus();
			displayAlert();
			return false;
		}
	}
	
	
	
	if($F('dd') != '' || $F('mm') != '' || $F('yy') != '') 	{ 
		var dob = $F('yy') + '-' + $F('mm') + '-' + $F('dd');
		if(!IsValidDate(dob)) {
			$('msg_div').innerHTML = "Please enter valid Date Of Birth.";
			$('dd').focus();
			displayAlert();
			return false;
		}
	}
	
	
	
	if($F('gender') == '') 	{ 
		$('msg_div').innerHTML = "Please select school Type.";
		$('gender').focus();
		displayAlert();
		return false;
	}
	
	if($('roll').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Roll No. .";
		$('roll').focus();
		displayAlert();
		return false;
	}
	
	
	if($('pass_year').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Year you joined school.";
		$('pass_year').focus();
		displayAlert();
		return false;
	}
	
	if($F('year_of_passing') == '') 	{ 
		$('msg_div').innerHTML = "Please select Year of Passing.";
		$('year_of_passing').focus();
		displayAlert();
		return false;
	}
	
	if($F('batch_of_passing') == '') 	{ 
		$('msg_div').innerHTML = "Please select Batch of Passing.";
		$('batch_of_passing').focus();
		displayAlert();
		return false;
	}
	
	if($('last_house').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Last House.";
		$('last_house').focus();
		displayAlert();
		return false;
	}
	
	
	var married_choice = false;
	
	for (counter = 0; counter < document.frm.married.length; counter++)
	{
	
	if (document.frm.married[counter].checked)
		married_choice = true; 
		
	}
	
	if (!married_choice)	{
		$('msg_div').innerHTML = "Please choose marital status.";
		displayAlert();
		return (false);
	}
		
	
	if($F('add') != '' || $F('amm') != '' || $F('ayy') != '') 	{ 
		var dob = $F('ayy') + '-' + $F('amm') + '-' + $F('add');
		if(!IsValidDate(dob)) {
			$('msg_div').innerHTML = "Please enter Valid Anniversary.";
			$('add').focus();
			displayAlert();
			return false;
		}
	}
	
	/*if($F('profession') == '') 	{ 
		$('msg_div').innerHTML = "Please select Profession.";
		document.getElementById('prof').style.display = 'inline';
		$('profession').focus();
		displayAlert();
		return false;
	}*/
	
	
	
	//Business directory validation
	
	
	if($F('TR_Category_name') != '') 	{ 
		if($F('TR_SUBCategory_name') == '') 	{ 
					$('msg_div').innerHTML = "Please select Sub Category Name.";
					document.getElementById('bud1').style.display = 'inline';
					
					$('TR_SUBCategory_name').focus();
					displayAlert();
					return false;
		}
	}
	
	
	if($F('TR_Business_description') != '') 	{ 
		if($F('TR_Business_description').length > 250)	{
						$('msg_div').innerHTML = "Description maximum 250 characters.";
						document.getElementById('bud1').style.display = 'inline';
						
						$('TR_Business_description').focus();
						displayAlert();
						return false;
		}
	}
	
	
	if($F('TR_Bus_Email') != '') {
				var reEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
				if($F('TR_Bus_Email').length > 5 && reEmail.test($F('TR_Bus_Email'))) {
				} else {
					$('msg_div').innerHTML = "Please enter valid Business Email address.";
					document.getElementById('bud1').style.display = 'inline';
					
					$('TR_Bus_Email').focus();
					displayAlert();
					return false;
				}
	}
	
	if($F('TR_Url') != '')	{
				if(!isURL($F('TR_Url'))){
					$('msg_div').innerHTML = "Please enter valid Url";
					$('TR_Url').focus();
					displayAlert();
					return false;
				}
	}
	
	if($F('TR_image') != '')	{
				if(!ValidateImageExtension($F('TR_image'))){
					document.getElementById('bud1').style.display = 'inline';
					
					$('msg_div').innerHTML = "Only jpg and gif files are allowed";
					displayAlert();
					return false;
				}
		}
		
		if($F('address') != '' && $F('address').length > 250) 	{ 
		$('msg_div').innerHTML = "Address can not be more than 250 characters.";
		$('address').focus();
		displayAlert();
		return false;
	}
	
	if(!IsOnlyNumbers($F('zip')) ) 	{

		$('msg_div').innerHTML = "Please enter valid Zip/Pin code.";
		$('zip').focus();
		displayAlert();
		return false;
	}
	
	
	if($F('taddress') != '' && $F('taddress').length > 250) 	{ 
		$('msg_div').innerHTML = "Temporary Address can not be more than 250 charactera.";
		$('taddress').focus();
		displayAlert();
		return false;
	}
	
	if(!IsOnlyNumbers($F('tzip')) ) 	{
		$('msg_div').innerHTML = "Please enter valid Zip/Pin code.";
		$('tzip').focus();
		displayAlert();
		return false;
	}
	
	if($('phone').value.trim() != '') 	{ 
		if(!ValidatePhone($F('phone')) ) 	{
			$('msg_div').innerHTML = "Please enter valid Phone number.";
			$('phone').focus();
			displayAlert();
			return false;
		}
	}
	
	if($('fax').value.trim() != '' && !ValidatePhone($F('fax'))) 	{ 
		$('msg_div').innerHTML = "Please enter valid Fax.";
		$('fax').focus();
		displayAlert();
		return false;
	}
	
	
	/*if($F('user_image') != '' && $F('file_type_ok') == 0) 	{ 
		$('msg_div').innerHTML = "Please upload valide (gif/jpg) image file.";
		$('user_image').focus();
		displayAlert();
		return false;
	}*/
	
	if($F('user_image') != '')	{
				if(!ValidateImageExtension($F('user_image'))){
					$('msg_div').innerHTML = "Only jpg and gif files are allowed";
					$('user_image').focus();
					displayAlert();
					return false;
				}
		}
	
	/*if($F('profession') == 16) 	{ 
	
			if($F('TR_Category_name') == '') 	{ 
				$('msg_div').innerHTML = "Please enter Category Name.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Category_name').focus();
				displayAlert();
				return false;
			}
			
			
			if($F('TR_SUBCategory_name') == '') 	{ 
				$('msg_div').innerHTML = "Please enter Sub Category Name.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_SUBCategory_name').focus();
				displayAlert();
				return false;
			}
			
			
			if($F('TR_Package_name') == '') 	{ 
				$('msg_div').innerHTML = "Please select Package Name.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Package_name').focus();
				displayAlert();
				return false;
			}
			
				
			if($F('TR_Company_name') == '') 	{ 
				$('msg_div').innerHTML = "Please enter Company Name.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Company_name').focus();
				displayAlert();
				return false;
			}
			
			if($F('TR_Business_description') == '') 	{ 
				$('msg_div').innerHTML = "Please enter Description.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Business_description').focus();
				displayAlert();
				return false;
			}
			
			
			if($F('TR_Business_description').length > 250)	{
				$('msg_div').innerHTML = "Description maximum 250 characters.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Business_description').focus();
				displayAlert();
				return false;
			}
			
			
			
			if($('TR_Contact_name').value.trim() == '')	{
				$('msg_div').innerHTML = "Please enter Contact Person.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Contact_name').focus();
				displayAlert();
				return false;
			}
			
			if($('TR_Bus_Email').value.trim() == '') 	{
				$('msg_div').innerHTML = "Please enter Business Email address.";
				document.getElementById('bud1').style.display = 'inline';
				document.getElementById('bud2').style.display = 'inline';
				$('TR_Bus_Email').focus();
				displayAlert();
				return false;
			}
			
			if($F('TR_Bus_Email') != '') {
				var reEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
				if($F('TR_Bus_Email').length > 5 && reEmail.test($F('TR_Bus_Email'))) {
				} else {
					$('msg_div').innerHTML = "Please enter valid Business Email address.";
					document.getElementById('bud1').style.display = 'inline';
					document.getElementById('bud2').style.display = 'inline';
					$('TR_Bus_Email').focus();
					displayAlert();
					return false;
				}
			}
			
			
			
			if($F('TR_Url') != '')	{
				if(!isURL($F('TR_Url'))){
					$('msg_div').innerHTML = "Please enter valid Url";
					$('TR_Url').focus();
					displayAlert();
					return false;
				}
			}
			
			
			if($('clogo').value == 0) 	{
				$('msg_div').innerHTML = "Please upload company logo.";
				
				//$('TR_image').focus();
				displayAlert();
				return false;
			}
				
			
					
			if($F('TR_image') != '')	{
				if(!ValidateImageExtension($F('TR_image'))){
					document.getElementById('bud1').style.display = 'inline';
					document.getElementById('bud2').style.display = 'inline';
					$('msg_div').innerHTML = "Only jpg and gif files are allowed";
					displayAlert();
					return false;
				}
			}	
	
	
	}
	
	//end here
	
	
	
	if($('address').value.trim() == '') 	{ 
		document.getElementById('det1').style.display = 'inline';
		$('msg_div').innerHTML = "Please enter Address.";
		$('address').focus();
		displayAlert();
		return false;
	}
	
	if($F('address') != '' && $F('address').length > 100) 	{ 
		$('msg_div').innerHTML = "Address can not be more then 100 character.";
		$('address').focus();
		displayAlert();
		return false;
	}
	

	
	if($('city').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter City.";
		$('city').focus();
		displayAlert();
		return false;
	}
	
	if($('state').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter State.";
		$('state').focus();
		displayAlert();
		return false;
	}
	
	if($('zip').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Zip/Pin.";
		$('zip').focus();
		displayAlert();
		return false;
	}
	
	if(!IsOnlyNumbers($F('zip')) ) 	{
		$('msg_div').innerHTML = "Please enter valid Zip/Pin code.";
		$('zip').focus();
		displayAlert();
		return false;
	}
	
	if($F('country') == '') 	{ 
		$('msg_div').innerHTML = "Please select Country.";
		$('country').focus();
		displayAlert();
		return false;
	}
	
	if($('taddress').value.trim() == '') 	{ 
		document.getElementById('det1').style.display = 'inline';
		$('msg_div').innerHTML = "Please enter Temporary Address.";
		$('taddress').focus();
		displayAlert();
		return false;
	}
	
	//alert( $F('address').length);
	if($F('taddress') != '' && $F('taddress').length > 100) 	{ 
		$('msg_div').innerHTML = "Temporary Address can not be more than 100 character.";
		$('taddress').focus();
		displayAlert();
		return false;
	}
	
	if($('tcity').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter City.";
		$('tcity').focus();
		displayAlert();
		return false;
	}
	
	if($('tstate').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter State.";
		$('tstate').focus();
		displayAlert();
		return false;
	}
	
	if($('tzip').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Zip/Pin.";
		$('tzip').focus();
		displayAlert();
		return false;
	}
	
	
	if($('phone').value.trim() == '') 	{ 
		$('msg_div').innerHTML = "Please enter Phone.";
		$('phone').focus();
		displayAlert();
		return false;
	}
	
	if(!ValidatePhone($F('phone')) ) 	{
		$('msg_div').innerHTML = "Please enter valid Phone .";
		$('phone').focus();
		displayAlert();
		return false;
	}
	
	if($('fax').value.trim() != '' && !ValidatePhone($F('fax'))) 	{ 
		$('msg_div').innerHTML = "Please enter valid Fax.";
		$('fax').focus();
		displayAlert();
		return false;
	}
	*/
	document.frm.submit();
	//var url = 'member.php?event=update';
	
	//youliveAjaxUpload(document.frm, url, '','Error in upload', 'main_action_div', 'temp_div');
	
}


function countdescChar(fobj,id) {
	
	var total = 250;
	var used = fobj.value.length;
	if(total >= used) {
		document.getElementById("dsc_cnt"+id).innerHTML = total - used;
	} else {
		fobj.value = fobj.value.substring(0, total);
	}
}
