// JavaScript Document

function ShowCountrycodes() {

	Countrycodes_popupwindow=dhtmlmodal.open('CountrycodesWindow', 'ajax', 'index.php?op=countrycodes', '', 'width=470px,height=400px,center=1,resize=0,scrolling=1'); 	

}



function OpenAddNewContactWindow() {

	AddNewContact_popupwindow=dhtmlmodal.open('AddNewContactWindow', 'ajax', 'index.php?op=contactmgr&action=3', '', 'width=570px,height=240px,center=1,resize=0,scrolling=1'); 	

}



function OpenGenealogy_forwardingWindow() {

	Genealogy_popupwindow=dhtmlmodal.open('GenealogyWindow', 'ajax', 'index.php?op=genealogy&action=7', '', 'width=570px,height=240px,center=1,resize=0,scrolling=1'); 	

}



function check_all_checkbox() {	

	if (document.contactlist_frm.contactIDs.length) {

		for(var i=0; i < document.contactlist_frm.contactIDs.length; i++)	{

			if (document.contactlist_frm.selectall.checked) document.contactlist_frm.contactIDs[i].checked = true; else document.contactlist_frm.contactIDs[i].checked = false;

		}

	} else {

		if (document.contactlist_frm.selectall.checked) document.contactlist_frm.contactIDs.checked = true; else document.contactlist_frm.contactIDs.checked = false;

	}

}



function validate_voucher_purchase(val,Voucher_Amount) {

	frm = document.vouchers_purchase_frm;

	if (!IsEmpty(val)) { 

		document.getElementById("errspan").innerHTML = 'Number of Vouchers Should not be Empty';

		frm.mand_voucher_amount.value = 0;

		frm.mand_voucher_count.focus(); return false; 

	} else {

		if (isNumber(val)) {

			frm.mand_voucher_amount.value = parseInt(frm.mand_voucher_count.value) * parseInt(Voucher_Amount);

			document.getElementById("errspan").innerHTML = '';

		} else {

			document.getElementById("errspan").innerHTML = 'Value must be all numberic charcters';

			frm.mand_voucher_amount.value = 0;

			return false;

		}

	}	

}



function Validate_Voucher_verify_Details() {

	frm = document.vouchers_verify_frm;

	var voucher_number = frm.voucher_number.value;

	var voucher_code = frm.voucher_code.value;

	if (!IsValid(voucher_number,'Voucher Number')) { frm.voucher_number.focus(); return false; } 

	if (!IsValid(voucher_code,'Voucher Code')) { frm.voucher_code.focus(); return false; } 

	

	var success = function(t){Validate_Voucher_verify_DetailsComplete(t);}

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=ValidateVoucher&voucher_number=' + voucher_number + '&voucher_code=' + voucher_code;  

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

}





function Validate_Voucher_verify_DetailsComplete(t) {

	var txt = t.responseText;

	document.getElementById("errspan").innerHTML = txt;

}



function ValidateTransactionPwd(frm_label) {

	var frm = document.transaction_password_frm;

	var pwd = frm.transaction_pwd.value;

	if (!IsValid(pwd,'Transaction Password')) { frm.transaction_pwd.focus(); return false; } else { 

		var success = function(t){ValidateTransactionPwdComplete(t,frm_label);}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=ValidateTransactionPwd&password=' + pwd + '&frm_label=' + frm_label;  

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}

}



function ValidateTransactionPwdComplete(t,frm_label) {

	txt = t.responseText;

	alert(txt);

	document.getElementById(frm_label).innerHTML = txt;

}



function ViewMailById(messageId) {

	var success = function(t){ViewMailByIdComplete(t);}

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=ViewMailById&messageId=' + messageId; 

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

}



function ViewMailByIdComplete(t) {

	txt = t.responseText;

	document.getElementById("messageDIV").style.display = 'block';

	document.getElementById("messageListDIV").style.display = 'none';	

	document.getElementById("messageDIV").innerHTML = txt;

}



function ValidateAndDeleteMails(fromto_action) {

	var count=0;	

	contactids = new Array();

	if (document.contactlist_frm.contactIDs.length) {

		for(var i=0; i < document.contactlist_frm.contactIDs.length; i++)	{

			if(document.contactlist_frm.contactIDs[i].checked) contactids[count++] = document.contactlist_frm.contactIDs[i].value;

		}

	} else {

		if(document.contactlist_frm.contactIDs.checked) contactids = document.contactlist_frm.contactIDs.value

	}

	if(contactids.length == 0)	alert("Please select Mails to delete."); 

	else  if (confirm('Are you sure to delete?.')) {

		var success = function(t){ValidateAndDeleteMailsComplete(t,'delete');}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=deletemaildetails&contactids=' + contactids + '&action=' + fromto_action;  

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}

	return false;

}



function ValidateAndDeleteMailsComplete(t) {

	var txt = t.responseText;

	document.getElementById("mailer_holder").innerHTML = txt;

	document.getElementById("succ_msg").innerHTML = 'Deleted Successfully.';

	

}



function ValidateAndDeleteContacts() {

	var count=0;	

	contactids = new Array();

	if (document.contactlist_frm.contactIDs.length) {

		for(var i=0; i < document.contactlist_frm.contactIDs.length; i++)	{

			if(document.contactlist_frm.contactIDs[i].checked) contactids[count++] = document.contactlist_frm.contactIDs[i].value;

		}

	} else {

		if(document.contactlist_frm.contactIDs.checked) contactids = document.contactlist_frm.contactIDs.value;

	}

	if(contactids.length == 0)	alert("Please select contactIDs to delete."); 

	else if (confirm('Are you sure to delete?.')) {

		var success = function(t){validate_add_contact_frm_detailsComplete(t,'delete');}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=deletecontactdetails&contactids=' + contactids; 

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}

	return false;

}







function ValidateAndDeleteSupports() {

	var count=0;	

	contactids = new Array();

	if (document.contactlist_frm.contactIDs.length) {

		for(var i=0; i < document.contactlist_frm.contactIDs.length; i++)	{

			if(document.contactlist_frm.contactIDs[i].checked) contactids[count++] = document.contactlist_frm.contactIDs[i].value;

		}

	} else {

		if(document.contactlist_frm.contactIDs.checked) contactids = document.contactlist_frm.contactIDs.value;

	}

	if(contactids.length == 0)	alert("Please select Support ID's to delete."); 

	else if (confirm('Are you sure to delete?.')) {

		var success = function(t){validate_add_support_frm_detailsComplete(t,'delete');}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=deletesupportdetails&contactids=' + contactids; 

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}

	return false;

}



function validate_add_support_frm_detailsComplete(t,val) {	

	var txt = t.responseText;

	document.getElementById("messageListDIV1").innerHTML = txt;

	document.getElementById("succ_msg").innerHTML = 'Deleted Successfully.';

	

}















function validate_genealogy_addnew_forwarding_details() {

	var flag = 0;

	var mand_User_Name = document.getElementById("mand_User_Name").value;

	var mand_Total_Entries = document.getElementById("mand_Total_Entries").value;

	

	if (!IsValid(mand_User_Name,'User Name')) { document.getElementById("mand_User_Name").focus(); return false; } else { flag=1; }

	if (!IsValid(mand_Total_Entries,'No. of Entries')) {

		document.getElementById("mand_Total_Entries").focus(); return false; 

	} 

	if (!isNumber(mand_Total_Entries,'No. of Entries')) { alert('Please Enter Only Numeric Values.'); document.getElementById("mand_Total_Entries").focus(); return false;}	

	

	var success = function(t){validate_genealogy_addnew_forwarding_detailsComplete(t);}

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=addforwarddet&mand_User_Name=' + mand_User_Name + '&mand_Total_Entries=' + mand_Total_Entries; 

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

}



function validate_genealogy_addnew_forwarding_detailsComplete(t) {	

	var txt = t.responseText;

	if (txt == 0) {

		document.getElementById("error_msg").innerHTML = 'Invalid User Name';

	} else if (txt == 1) {

		document.getElementById("error_msg").innerHTML = 'Members can\'t forward to themself.';	

	} else {

		dhtmlmodal.close(Genealogy_popupwindow); 		

		document.getElementById("genealogy_forwarding_holder").innerHTML = txt;

	}	

}





function ValidateAndDeleteGenealogy() {

	var count=0;	

	contactids = new Array();

	if (document.contactlist_frm.contactIDs.length) {

		for(var i=0; i < document.contactlist_frm.contactIDs.length; i++)	{

			if(document.contactlist_frm.contactIDs[i].checked) contactids[count++] = document.contactlist_frm.contactIDs[i].value;

		}

	} else {

		if (document.contactlist_frm.contactIDs.checked) contactids = document.contactlist_frm.contactIDs.value;

	}

	if(contactids.length == 0)	alert("Please select Forward Id's to delete."); 

	else if (confirm('Are you sure to delete?.')) {

		var success = function(t){ValidateAndDeleteGenealogyComplete(t);}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=deletegenealogydetails&contactids=' + contactids; 

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}

	return false;

}



function ValidateAndDeleteGenealogyComplete(t) {

	var txt = t.responseText;

	document.getElementById("genealogy_forwarding_holder").innerHTML = txt;

}







function validate_add_contact_frm_details() {

	var flag = 0;

	var mand_Contact_Name = document.getElementById("mand_Contact_Name").value;

	var mand_Contact_Email = document.getElementById("mand_Contact_Email").value;

	

	if (!IsValid(mand_Contact_Name,'Contact Name')) { document.getElementById("mand_Contact_Name").focus(); return false; } else { flag=1; }

	if (!IsValid(mand_Contact_Email,'Contact Email')) {

		document.getElementById("mand_Contact_Email").focus(); return false; 

	} else if (IsValid(mand_Contact_Email,'Contact Email')) {

		if (!isEmailAddr(mand_Contact_Email,'Email')) { document.getElementById("mand_Contact_Email").focus(); return false;}			

	}else { 

		flag=2; 

	}

	if (flag != 0) {

		var success = function(t){validate_add_contact_frm_detailsComplete(t,'add');}

		var failure = function(t){editFailed(t);}

		var url = global_path+"ajax.php";

		var pars = 'hdAction=addcontactdetails&mand_Contact_Name=' + mand_Contact_Name + '&mand_Contact_Email=' + mand_Contact_Email; 

		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	

	}	

}



function validate_add_contact_frm_detailsComplete(t,val) {	

	var txt = t.responseText;

	document.getElementById("contactlistTPL").innerHTML = txt;

	if (val == 'add') 

		document.getElementById("succ_msg").innerHTML = 'Added Successfully';

	else

		document.getElementById("succ_msg").innerHTML = 'Deleted Successfully';	

	document.getElementById("mand_Contact_Name").value = '';

	document.getElementById("mand_Contact_Email").value = '';

	dhtmlmodal.close(AddNewContact_popupwindow); 		

}



function validateremessaging_frm() {

	var frm = document.messaging_frm;	

	if (!IsValid(frm.username.value,'User Name')) { frm.username.focus(); return false; }

	if (!IsValid(frm.subject.value,'Subject')) { frm.subject.focus(); return false; }

	if (!IsValid(tinyMCE.get('emailMessage').getContent(),'Email Message')) { tinyMCE.get('emailMessage').focus(); return false; }	

//	if (!IsValid(frm.emailMessage.value,'Email Message')) { frm.emailMessage.focus(); return false; }	

	frm.action = 'index.php?op=messaging&action=2';

	frm.submit();

}



function validatesupport_frm() {

	var frm = document.support_frm;	

	if (!IsValid(frm.support_category.value,'Category')) { frm.support_category.focus(); return false; }

	if (!IsValid(frm.support_subject.value,'Subject')) { frm.support_subject.focus(); return false; }

	if (!IsValid(tinyMCE.get('support_message').getContent(),'Message')) { tinyMCE.get('support_message').focus(); return false; }	

	//if (!IsValid(frm.support_file.value,'File')) { frm.support_file.focus(); return false; }

	frm.action = 'index.php?op=support&action=2';

	frm.submit();

}







function compareDates() {

	var date = new Date(document.getElementById('from_date').value);

	var endDate = new Date(document.getElementById('to_date').value);	

	var compareEnd = compareDatesOnly(date, endDate); //  < return 1 *  > return -1 *  = return 0		

	if  (compareEnd < 0) { alert('To Date Should be Greater than From Date.'); return false; } else { return true; } 

}



function validate_change_password_frm_details() {

	var frm = document.change_password_frm;	

	if (!IsValid(frm.old_Password.value,'Old Password')) { frm.old_Password.focus(); return false; }

	if (!IsValid(frm.new_Password.value,'New Password')) { frm.new_Password.focus(); return false; }

	if (!IsValid(frm.confirm_password.value,'Confirm Password')) { frm.confirm_password.focus(); return false; }	

	if (frm.new_Password.value != frm.confirm_password.value) { alert('New Password and Confirm Password Should be same.'); frm.confirm_password.focus();  return false; }

	//frm.action = 'index.php?op=profile&action=3';

	frm.action = '';

	frm.submit();

}





function validate_change_trans_password_frm_details() {

	var frm = document.change_trans_password_frm;	

	if (!IsValid(frm.trans_old_Password.value,'Old Password')) { frm.trans_old_Password.focus(); return false; }

	if (!IsValid(frm.trans_new_Password.value,'New Password')) { frm.trans_new_Password.focus(); return false; }

	if (!IsValid(frm.trans_confirm_password.value,'Confirm Password')) { frm.trans_confirm_password.focus(); return false; }	

	if (frm.trans_new_Password.value != frm.trans_confirm_password.value) { alert('New Password and Confirm Password Should be same.'); frm.trans_confirm_password.focus();  return false; }

	//frm.action = 'index.php?op=profile&action=3';

	frm.action = '';

	frm.submit();

}





function validateregistrationfrm() {

	var frm = document.register_step1_frm;	

	if (!IsValid(frm.firstName.value,'First Name')) { frm.firstName.focus(); return false; }

	if (!IsValid(frm.lastName.value,'Last Name')) { frm.lastName.focus(); return false; }

	if (!IsValid(frm.email.value,'Email')) { 

		frm.email.focus(); 

		return false;

	}	else {

		if (!isEmailAddr(frm.email.value,'Email')) { frm.email.focus(); return false;}	

	}

	if (!IsValid(frm.confirn_email.value,'Confirmation Email')) { 

		frm.confirn_email.focus(); 

		return false;

	}	else {

		if (!isEmailAddr(frm.confirn_email.value,'Email')) { 

			frm.confirn_email.focus(); return false;

		}	else { 

			if (frm.confirn_email.value != frm.email.value) { alert('Email and Confirmation Email Should be same.'); frm.confirn_email.focus();  return false; }

		}

	}

	

	if (!IsValid(frm.cellular_phone.value,'Cellular Phone')) { 

		frm.cellular_phone.focus(); return false;

	} else if (IsEmpty(frm.cellular_phone.value)) {

		if (!IsNumber(frm.cellular_phone.value,'Cellular Phone')) { frm.cellular_phone.value = ''; frm.cellular_phone.focus(); return false;}

		if (!IsValid(frm.country_code_2.value,'Cellular Phone Country Code')) { 

			frm.country_code_2.focus();

			return false;

		}	else {

			if (!IsNumber(frm.country_code_2.value,'Cellular Phone Country Code')) { frm.country_code_2.value = '';frm.country_code_2.focus();  return false;}

		}							

	}	

	



	if (!IsValid(frm.address.value,'Address')) { frm.address.focus(); return false;}

	if (!IsValid(frm.city.value,'City')) { frm.city.focus(); return false;} 

	if (!IsValid(frm.state.value,'State')) { frm.state.focus(); return false;} 



	if (!IsEmpty(frm.zip.value)) {

		alert('Zip Number should not be empty');

		frm.zip.focus();

		return false;

	} else {

		if (IsEmpty(frm.zip.value)) {

			if (!IsNumber(frm.zip.value,'Zip Code')) { frm.zip.value = '';frm.zip.focus(); return false; }

		} 

	}

	

	if (!IsValid(frm.country.value,'Country')) {

		frm.country.focus();

		return false;		

	} 

	

	if (!IsValid(frm.verify_box.value,'Verification Code')) {

		frm.verify_box.focus();

		return false;		

	} 

	submitform('register_step1_frm','add_new_member');

//	frm.action = 'index.php';

//	frm.submit();	

}



function validateprofileeditfrm() {

	var frm = document.register_step1_frm;	

	if (!IsValid(frm.firstName.value,'First Name')) { frm.firstName.focus(); return false; }

	if (!IsValid(frm.lastName.value,'Last Name')) { frm.lastName.focus(); return false; }

	if (!IsValid(frm.email.value,'Email')) { 

		frm.email.focus(); 

		return false;

	}	else {

		if (!isEmailAddr(frm.email.value,'Email')) { frm.email.focus(); return false;}	

	}

		

	if (!IsValid(frm.cellular_phone.value,'Cellular Phone')) { 

		frm.cellular_phone.focus(); return false;

	} else if (IsEmpty(frm.cellular_phone.value)) {

		if (!IsNumber(frm.cellular_phone.value,'Cellular Phone')) { frm.cellular_phone.value = ''; frm.cellular_phone.focus(); return false;}

		if (!IsValid(frm.country_code_2.value,'Cellular Phone Country Code')) { 

			frm.country_code_2.focus();

			return false;

		}	else {

			if (!IsNumber(frm.country_code_2.value,'Cellular Phone Country Code')) { frm.country_code_2.value = '';frm.country_code_2.focus();  return false;}

		}							

	}	

	



	if (!IsValid(frm.address.value,'Address')) { frm.address.focus(); return false;}

	if (!IsValid(frm.city.value,'City')) { frm.city.focus(); return false;} 

	if (!IsValid(frm.state.value,'State')) { frm.state.focus(); return false;} 



	if (!IsEmpty(frm.zip.value)) {

		alert('Zip Number should not be empty');

		frm.zip.focus();

		return false;

	} else {

		if (IsEmpty(frm.zip.value)) {

			if (!IsNumber(frm.zip.value,'Zip Code')) { frm.zip.value = '';frm.zip.focus(); return false; }

		} 

	}

	

	if (!IsValid(frm.country.value,'Country')) {

		frm.country.focus();

		return false;		

	} 

	

	submitform('register_step1_frm','add_new_member');

	frm.action = '';

//	frm.submit();	

}



































function validateregistration_step2() {

	var frm = document.register_step2_frm;	

	var uname = frm.member_name.value;

	if (!IsValid(frm.member_name.value,'User Name')) { 

		frm.member_name.focus(); return false; 

	}	else {

		if (uname.length <= parseInt(4)) {

			alert('User Name length should be minimum 5 charecters.');

			frm.member_name.focus(); return false; 

		} 		

		if (!IsValidUserName(frm.member_name.value,'User Name')) {

			frm.member_name.focus(); return false; 

		} else {

			ValidateExistingUsername(frm.member_name.value,frm.MemberID.value);	

		}

	}



	

	if (!IsValid(frm.password.value,'Password')) { 

		frm.password.focus(); return false; 

	} else {

		var pwd = frm.password.value;

		if (pwd.length <= parseInt(5)) {

			alert('Password length should be minimum 6 charecters.');

			frm.password.focus(); return false; 

		} 

	}



	if (!IsValid(frm.verify_Lpassword.value,'Verify Password')) { 

		frm.verify_Lpassword.focus(); return false; 

	} else {

		var pwd = frm.verify_Lpassword.value;

		if (pwd.length <= parseInt(5)) {

			alert('Password length should be minimum 6 charecters.');

			frm.verify_Lpassword.focus(); return false; 

		}

	}



	if (frm.password.value != frm.verify_Lpassword.value) {

		alert('Password and Confirm password should be the same.');

		frm.verify_Lpassword.focus();

		return false;

	}



	submitform('register_step2_frm','add_new_member_acct');

}



function validate_register_step3_frm() {

	var frm = document.register_step3_frm;	

	if (!IsValid(frm.voucher_number.value,'Voucher Number')) { 

		frm.voucher_number.focus(); return false; 

	}

	if (!IsValid(frm.voucher_code.value,'Voucher Code')) { 

		frm.voucher_code.focus(); return false; 

	}

	submitform('register_step3_frm','add_member_pay');

}



function submitform(FormName,op) {

	var mod_rewrite = mod_rewrite;

	if (mod_rewrite == '0')

		document.getElementById(FormName).action = current_page;

	else 

		document.getElementById(FormName).action = global_path+op

	document.getElementById(FormName).submit();

}





function ValidateExistingUsername(member_name,MemberID) {

	var frm = document.register_step2_frm;	

	if (!IsValid(frm.member_name.value,'User Name')) { 

		frm.member_name.focus(); return false; 

	}	else {

		if (!IsValidUserName(frm.member_name.value,'User Name')) {

			frm.member_name.focus(); return false; 

		} else {

			var success = function(t){ValidateExistingUsernameComplete(t);}

			var failure = function(t){editFailed(t);}

			var url = global_path+"ajax.php";

			var pars = 'hdAction=validateusername&searchfor=' + member_name + '&MemberID=' + MemberID; 

			var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});

		}

	}

}



function ValidateExistingUsernameComplete(t) {

	var txt = t.responseText;

	if (txt != '0') {

		document.getElementById('msg').innerHTML = ' '+ txt;

		document.getElementById('member_name').value = '';

		document.getElementById('member_name').focus(); 
		

	} else {

		document.getElementById('msg').innerHTML = '';

	}

}



function ValidateExistingSponsersUsername(sponsername) {

	var frm = document.sponsers_frm;	

	if (!IsValid(frm.sponsers_name.value,'Sponsers Name')) { 

		frm.sponsers_name.focus(); return false; 

	}	else {

		if (!IsValidUserName(frm.sponsers_name.value,'Sponsers Name')) {

			frm.sponsers_name.focus(); return false; 

		} else {

			var success = function(t){ValidateExistingSponsersUsernameComplete(t);}

			var failure = function(t){editFailed(t);}

			var url = global_path+"ajax.php";

			var pars = 'hdAction=validatesponsername&searchfor=' + sponsername; 

			var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});

		}

	}

}



function ValidateExistingSponsersUsernameComplete(t) {

	var txt = t.responseText;

	if (txt == '0') {

		document.getElementById('msg').innerHTML = ' Sponsers Name Does not Exist. Enter valid sponsers name.';

	} else {

		document.getElementById('CurrentTpl-wrapper').innerHTML = txt;

	}

}



function validatememberlogindetails() {

	/*var frm = document.memberlogin_frm;

	var member_name = frm.member_name.value;		

	var password = frm.password.value;	

	if (!IsValid(member_name,'User Name')) { 

		frm.member_name.focus(); return false; 

	}	

	if (!IsValid(password,'Password')) { 

		frm.password.focus(); return false; 

	}*/	

	

   if(document.getElementById('member_name').value==""){

		document.getElementById('member_name_msg').style.display="block";

		document.getElementById('member_name_msg').style.display="Username should not be empty";

		document.getElementById('member_name').focus();

		var error="Error";

		return false;

   }else if(document.getElementById('member_name').value!=""){

    	document.getElementById('member_name_msg').style.display="none";

		var error=""; 

   }

   if(document.getElementById('password').value==""){

    	document.getElementById('password_msg').style.display="block";

		document.getElementById('password_msg').innerHTML="Password should not be empty";

		document.getElementById('password').focus();

		var error="Error";

		return false;

   }else if(document.getElementById('password').value!=""){

    	document.getElementById('password_msg').style.display="none";

		var error=""; 

   }

  if(error==""){

	var Make=document.getElementById('member_name').value+"|"+document.getElementById('password').value; 

    var Values  = "";

    var success = function(t){validatememberlogindetailsComplete(t);}

    var failure = function(t){editFailed(t, Values);}

    var url     = 'ajax.php';

    var pars    = 'M='+Make;

    var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure}); 

  }	

	

	

	

	

	/*var success = function(t){validatememberlogindetailsComplete(t);}

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=memberlogin&member_name=' + member_name + '&password=' + password; alert(pars);

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});*/		

}



function validatememberlogindetailsComplete(t) {

	var txt = t.responseText;

	if(t.responseText){

		document.getElementById("member_name").value = "";

		document.getElementById("password").value = "";

	}

}



function SendForgotPasswordMail() {

	var success = function(t){SendForgotPasswordMailComplete(t);}

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=getforgotpwdtpl'; 

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

}



function SendForgotPasswordMailComplete(t) {

	var txt = t.responseText;

	document.getElementById("CurrentTpl-wrapper").innerHTML = txt;

}



function ValidateForgotPasswordMail(username) { 

	if (!IsValid(username,'User Name')) {

		document.forgot_pwd_frm.username.focus();  

		return false;	

	}	 

	return true;

} 



function usernameexist() {

	var frm = document.register_step2_frm;	

	if (!IsValid(frm.member_name.value,'User Name')) { 

		frm.member_name.focus(); return false; 

	}	else {

		if (!IsValidUserName(frm.member_name.value,'User Name')) {

			frm.member_name.focus(); return false; 

		}

	}	

	//Ajax function to validate existing member name

	alert('do ajax function here');		

}



function validatecontactus() {

	var frm = document.contactus;	

	if (!IsValid(frm.name.value,'User Name')) { 

		frm.name.focus(); return false; 

	}

	if (!IsValid(frm.email.value,'User E-mail')) { 

		frm.email.focus(); return false; 

	}

	if (!IsValid(frm.country.value,'Country')) { 

		frm.country.focus(); return false; 

	}

	if (!IsValid(frm.subject.value,'Subject')) { 

		frm.subject.focus(); return false; 

	}	

	if (!IsValid(frm.verify_box.value,'Verification Image')) { 

		frm.verify_box.focus(); return false; 

	}

	if (!IsValid(frm.message.value,'Message')) { 

		frm.message.focus(); return false; 

	}

}



function loadcountryimage(countrycode) {

	var countrycode = countrycode.toLowerCase();

	document.getElementById('countryflag').src = global_path+'images/flags/'+countrycode+'.gif'

}



function validate_security_code(security_code) {

	var success = function(t){validate_security_codeComplete(t);}	

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=Validate_security_code&security_code=' + security_code; 	

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

	document.getElementById("ErrorSpan").style.display = 'block';

	document.getElementById("ErrorSpan").innerHTML = '<img src="'+global_path+'images/dots-white.gif">';

	

}



function validate_security_codeComplete(t) {

	var txt = t.responseText;

	document.getElementById("ErrorSpan").style.display = 'block';

	document.getElementById("ErrorSpan").innerHTML = txt;

}



function EnterKeyPressed(e) {

	var characterCode = ''; // literal character code will be stored in this variable



	if(e && e.which){ //if which property of event object is supported (NN4)

		e = e

		characterCode = e.which //character code is contained in NN4's which property

	}	else	{

		e = event

		characterCode = e.keyCode //character code is contained in IE's keyCode property

	}

	

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)

		switch(action) {

			case 'memberlogin': 

				validatememberlogindetails();

				break;

		}

		return false;

	} else {

		return true;

	}	

}



function validate_new_visitor(this_form)

{

	with(this_form)

	{

		if(!IsEmpty(vname.value))

		{

			alert("Please enter your Name");

			vname.focus();

			return false;

		}

		if(!IsEmpty(email.value))

		{

			alert("Please enter your Email");

			email.focus();

			return false;

		}

		else if(!isEmailAddr(email.value,"Email"))

		{

			email.focus();

			return false;

		}

		if(!IsEmpty(phone.value))

		{

			alert("Please enter your Phone Number");

			phone.focus();

			return false;

		}

		

		if(country.value == "0")

		{

			alert("Please enter your Country");

			country.focus();

			return false;

		}

		

		submitform("new_visitor","add_new_visitor");

	}

}







/*______________________________________Common Functions___________________________________________________*/

function editFailed(t) {

	alert('ajax function failed'+t.responseText);

}





function IsEmpty(Val) {

    if(trim(Val)=="")

    {

        return false;

    }

    return true;	

}



function IsValid(Val,Label)

{

    if(trim(Val)=="")

    {

        alert(Label+" Should Not be Empty");

        return false;

    }

    return true;

}



var trim = function(Val)

{

    while(''+Val.charAt(0)==' ')

    Val=Val.substring(1,Val.length);

    return Val;

}



function IsNumber(sText,Label)

{

   var ValidChars = "0123456789-";

   var IsNumber=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsNumber == true; i++)     

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsNumber = false;

      }

   }

   if(!IsNumber)

       alert(Label+ " Must Be numeric")

   return IsNumber;

}





var IsVaildNumber = function(sText)

{

   var ValidChars = "0123456789-";

   var IsNumber=true;

   var Char;

   if(sText=="") 

   {

       IsNumber = false;

    }else{

       for (i = 0; i < sText.length && IsNumber == true; i++)     

       { 

          Char = sText.charAt(i); 

          if(ValidChars.indexOf(Char) == -1) 

          {

             IsNumber = false;

          }

       }

    }

    return IsNumber;

}

function IsAmount(sText)

{

   var ValidChars = "0123456789.";

   var IsAmount=true;

   var Char;

   if(sText=="") return false

   for (i = 0; i < sText.length && IsAmount == true; i++)     

   { 

         Char = sText.charAt(i); 

         if (ValidChars.indexOf(Char) == -1) 

         {

             IsAmount = false;

         }

   }

   return IsAmount;

}



function IsValidAmount(sText,Label)

{

    if(!IsAmount(sText))

    {

        alert("Invalid "+Label+".. "+Label+" Must Have Numeric Values")

        return false;

    }

    AmtArray = sText.split(".")

    if(AmtArray.length>2)

    {

        alert("Invalid "+Label+".. "+Label+" Must have single Period for Float")

        return false;

    }

    if(AmtArray.length>1)

    {

        FloatAmt = AmtArray[1];

        if(FloatAmt.length>2)

        {

            alert("Invalid "+Label+"..  Float Value must have two Digits")

            return false;

        }

    }

    return true

}



function isEmailAddr(email,Label) {

    

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){

return (true)

}

alert("Invalid "+Label+" Address! Please re-enter.")

return (false)

}





function IsValid(Val,Label)

{

    if(trim(Val)=="")

    {

        alert(Label+" Should Not be Empty");

        return false;

    }

    return true;

}



var trim = function(Val)

{

    while(''+Val.charAt(0)==' ')

    Val=Val.substring(1,Val.length);

    return Val;

}



function IsAlpha(sText,Label)

{

   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function IsAlphaNumeric(sText,Label)

{

   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function IsValidUserName(sText,Label)

{

   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function checkEnterValidateExistingSponsersUsername(e,sponsername){ //e is event object passed from function invocation

	var characterCode = ''; // literal character code will be stored in this variable



	if(e && e.which){ //if which property of event object is supported (NN4)

		e = e

		characterCode = e.which //character code is contained in NN4's which property

	}	else	{

		e = event

		characterCode = e.keyCode //character code is contained in IE's keyCode property

	}

	

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)

		if (sponsername.length < 4) return false;

		ValidateExistingSponsersUsername(sponsername); //submit the form

		return false;

	} else {

		return true;

	}

}



/*

 * Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or

 * they're the same, taking only the dates, not the time into account.

 * In other words, different times on the same date returns equal.

 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal

 */



function compareDatesOnly(date1, date2) {

	var year1 = date1.getYear();

	var year2 = date2.getYear();

	var month1 = date1.getMonth();

	var month2 = date2.getMonth();

	var day1 = date1.getDate();

	var day2 = date2.getDate();



	if (year1 > year2) {

		return -1;

	}

	if (year2 > year1) {

		return 1;

	}



	//years are equal

	if (month1 > month2) {

		return -1;

	}

	if (month2 > month1) {

		return 1;

	}



	//years and months are equal

	if (day1 > day2) {

		return -1;

	}

	if (day2 > day1) {

		return 1;

	}



	//days are equal

	return 0;



	/* Can't do this because of timezone issues

	var days1 = Math.floor(date1.getTime()/Date.DAY);

	var days2 = Math.floor(date2.getTime()/Date.DAY);

	return (days1 - days2);

	*/

}



function isNumber(val) {	

	var re = /^[0-9-'.'-',']*$/;

	if (!re.test(val)) return false; else return true;

}



function OpenAddSupport_queryWindow(ticketid) {

	AddNew_popupwindow=dhtmlmodal.open('AddNewSupportQueryWindow', 'ajax', 'index.php?op=supportView&action=newQuery&ticketId='+ticketid, '', 'width=580px,height=370px,center=1,resize=0,scrolling=1'); 	

}



function validatesupport_frm1(objform)

{

	alert("hi");

   /* var valid=true;

	var st1=document.new_queryticket.query_message.value;

	if(st1=='')

	{

	  alert("Message Should Not Empty");

	  document.new_queryticket.query_message.focus();

	  valid=false;

	}

	return valid;*/

 }

function LoadTinyEditor() {

	tinyMCE.init({

	// General options

	mode : "textareas",

	theme : "simple",

	 

	// Example content CSS (should be your site CSS)

	content_css : "css/example.css",

	 

	// Drop lists for link/image/media/template dialogs

	template_external_list_url : "js/template_list.js",

	external_link_list_url : "js/link_list.js",

	external_image_list_url : "js/image_list.js",

	media_external_list_url : "js/media_list.js",

	 

	// Replace values for the template plugin

	template_replace_values : {

	username : "Some User",

	staffid : "991234"

	}

	});

	

}



function validate_queryWindow() {

	var frm = document.new_queryticket;	

	if (!IsValid(tinyMCE.get('query_message').getContent(),'Message')) { tinyMCE.get('query_message').focus(); return false; }	

}



function validate_adminreplay()

{

  	if (!IsValid(tinyMCE.get('query_message').getContent(),'Message')) { tinyMCE.get('query_message').focus(); return false; }

}
function validate_representative_voucher() {

	var frm = document.rep_frm;	
	if (!IsValid(frm.email.value,'Email')) { 
		frm.email.focus(); 
		return false;
		}	else {
			if (!isEmailAddr(frm.email.value,'Email')) { frm.email.focus(); return false;}	
		}
	if (!IsValid(frm.confirn_email.value,'Confirmation Email')) { 
		frm.confirn_email.focus(); 
		return false;
		}	else {
		if (!isEmailAddr(frm.confirn_email.value,'Email')) { 
			frm.confirn_email.focus(); return false;
		}	else { 
			if (frm.confirn_email.value != frm.email.value) { alert('Email and Confirmation Email Should be same.'); frm.confirn_email.focus();  return false; }

		}

	 }
    if (!IsValid(frm.firstName.value,'First Name')) { frm.firstName.focus(); return false; }
    if (!IsValid(frm.lastName.value,'Last Name')) { frm.lastName.focus(); return false; }
	if (!IsValid(frm.amount.value,'Amount')) { frm.amount.focus(); return false;}

//	frm.submit();	

}





