// JavaScript Document for MagicTrader

/******************************************* General **************************************/

function Inint_AJAX() 
{
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function GetXmlHttpObject() 
{ 
  	var xmlhttp; 
  	if(window.XMLHttpRequest)
  	{ 
    	xmlhttp = new XMLHttpRequest(); 
  	} 
  	else if (window.ActiveXObject)
  	{ 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!xmlhttp)
		{ 
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
	} 
  	return xmlhttp; 
} 

/***************************** Page Manager **********************************/

function page_edit(page,limit)
{	
	var page_id_temp = 0;
	page_id_temp = document.frm_page_mgmt.page_id.value;
	document.frm_page_mgmt.action="page_add.php?page_id="+page_id_temp+"&page="+page+"&limit="+limit;
	document.frm_page_mgmt.submit();
}

/***************************** User Manager **********************************/
function getExtraFields_adm(val)
{	
	if(val == "pro")
	{
		document.getElementById("divProfFields-adm").style.display = 'block';
	}else{
		document.getElementById("divProfFields-adm").style.display = 'none';
	}		
};

function getNFAID_adm(val)
{
	if(val == "yes")
	{
		alert("Please enter your NFA ID#");
		
		document.getElementById("divNFA-adm").style.display = 'block';
	}else{
		document.getElementById("divNFA-adm").style.display = 'none';
	}
}
function getExch_adm(val)
{
	if(val == "yes")
	{
		document.getElementById("divExch-adm").style.display = 'block';
	}else{
		document.getElementById("divExch-adm").style.display = 'none';
	}
}
function getSecOrg_adm(val)
{
	if(val == "yes")
	{
		document.getElementById("divSecOrg-adm").style.display = 'block';
	}else{
		document.getElementById("divSecOrg-adm").style.display = 'none';
	}
}
function getFira_adm(val)
{
	if(val == "yes")
	{
		document.getElementById("divFira-adm").style.display = 'block';
	}else{
		document.getElementById("divFira-adm").style.display = 'none';
	}
}
function getSeriesExam_adm(val)
{
	if(val == "yes")
	{
		document.getElementById("divSeriesExam-adm").style.display = 'block';
	}else{
		document.getElementById("divSeriesExam-adm").style.display = 'none';
	}
}
function user_save()
{
	if (document.frm_user_add.user_first_name.value.length == 0) {
	   alert("Please Enter a First Name.");
	   document.frm_user_add.user_first_name.focus();
	   return false;
	}else if (document.frm_user_add.user_last_name.value.length == 0) {
	   alert("Please Enter Your Last Name.");
	   document.frm_user_add.user_last_name.focus();
	   return false;
	}
	if (document.frm_user_add.user_name.value.length == 0) {
	   alert("Please Enter a User Name.");
	   document.frm_user_add.user_name.focus();
	   return false;
	}
	
	 var password=document.frm_user_add.user_pass;
		
		if(password.value==""){
			alert("Please enter your Password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		
		var pass_string = password.value;		
		var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password contains invalid characters');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="123456789";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password contains only characters. Please enter an alphanumeric	value like -alpha1-');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password contains only numbers. Please enter an alpanumeric value like -alpha1-');
			password.focus();
			return false;
		}
	
 if (document.frm_user_add.user_email_address.value.length == 0) {
	   alert("Please Enter Your Email Address.");
	   document.frm_user_add.user_email_address.focus();
	   return(false);
	}
	else if (document.frm_user_add.user_address.value.length == 0) {
	   alert("Please Enter Your Address.");
	   document.frm_user_add.user_address.focus();
	   return false;
	}else if (document.frm_user_add.user_city.value.length == 0) {
	   alert("Please Enter Your City.");
	   document.frm_user_add.user_city.focus();
	   return false;
	}else if (document.frm_user_add.user_state.value == 'SS') {
	   alert("Please Select A State.\n\nIf outside the US, select Non US / Foreign");
	   document.frm_user_add.user_state.focus();
	   return false;
	}else if (document.frm_user_add.user_zip_code.value.length == 0) {
	   alert("Please Enter Your Zipcode.\n\nIf outside the US, enter '00000'");
	   document.frm_user_add.user_zip_code.focus();
	   return false;
	}
	
	
	document.frm_user_add.action = "user_save.php";
	document.frm_user_add.submit();
} 

function user_edit(user_id,page,limit)
{
	document.frm_user_mgmt.action="user_add.php?user_id="+user_id+"&page="+page+"&limit="+limit;
	document.frm_user_mgmt.submit();
}

function user_delete(user_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_user_mgmt.action="user_delete.php?user_id="+user_id+"&page="+page+"&limit="+limit;
		document.frm_user_mgmt.submit();	
	}
}

/********************* Group Manager ****************************************/

function group_save()
{
	document.group_add.action = "group_save.php";
	document.group_add.submit();	
} 

function group_edit(group_id,page,limit)
{
	document.frm_group_mgmt.action="group_add.php?group_id="+group_id+"&page="+page+"&limit="+limit;
	document.frm_group_mgmt.submit();
}

function group_delete(group_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_group_mgmt.action="group_delete.php?group_id="+group_id+"&page="+page+"&limit="+limit;
		document.frm_group_mgmt.submit();	
	}
}
/********************* Disclaimer Manager ****************************************/

function disclaimer_save()
{
	document.disclaimer_add.action = "disclaimer_save.php";
	document.disclaimer_add.submit();	
} 

function disclaimer_edit(disclaimer_id,page,limit)
{
	document.frm_disclaimer_mgmt.action="disclaimer_add.php?disclaimer_id="+disclaimer_id+"&page="+page+"&limit="+limit;
	document.frm_disclaimer_mgmt.submit();
}

function disclaimer_delete(disclaimer_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_disclaimer_mgmt.action="disclaimer_delete.php?disclaimer_id="+disclaimer_id+"&page="+page+"&limit="+limit;
		document.frm_disclaimer_mgmt.submit();	
	}
}


/********************* Product Manager ****************************************/

function product_save()
{
	document.product_add.action = "product_save.php";
	document.product_add.submit();	
} 

function product_edit(product_id,page,limit)
{
	document.frm_product_mgmt.action="product_add.php?product_id="+product_id+"&page="+page+"&limit="+limit;
	document.frm_product_mgmt.submit();
}

function product_delete(product_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_product_mgmt.action="product_delete.php?product_id="+product_id+"&page="+page+"&limit="+limit;
		document.frm_product_mgmt.submit();	
	}
}
/********************* Formula Manager ****************************************/

function formula_save()
{
	document.formula_add.action = "formula_save.php";
	document.formula_add.submit();	
} 

function formula_edit(formula_id,page,limit)
{
	document.frm_formula_mgmt.action="formula_add.php?formula_id="+formula_id+"&page="+page+"&limit="+limit;
	document.frm_formula_mgmt.submit();
}

function formula_delete(formula_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_formula_mgmt.action="formula_delete.php?formula_id="+formula_id+"&page="+page+"&limit="+limit;
		document.frm_formula_mgmt.submit();	
	}
}
/********************* paid_training Manager ****************************************/

function paid_training_save()
{
	document.paid_training_add.action = "paid_training_save.php";
	document.paid_training_add.submit();	
} 

function paid_training_edit(paid_training_id,page,limit)
{
	document.frm_paid_training_mgmt.action="paid_training_add.php?paid_training_id="+paid_training_id+"&page="+page+"&limit="+limit;
	document.frm_paid_training_mgmt.submit();
}

function paid_training_access(paid_training_id,page,limit)
{
	document.frm_access_mgmt.action="access_add.php?paid_training_id="+paid_training_id+"&page="+page+"&limit="+limit;
	document.frm_access_mgmt.submit();
}

function paid_training_delete(paid_training_id,page,limit)
{
	var ans=confirm("Are you sure want to delete?");
	if(ans==true)
	{
		document.frm_paid_training_mgmt.action="paid_training_delete.php?paid_training_id="+paid_training_id+"&page="+page+"&limit="+limit;
		document.frm_paid_training_mgmt.submit();	
	}
}
/*********************************************** Front Side - Join Us ***************************/

function getExtraFields(val)
{	
	if(val == "pro")
	{
		document.getElementById("divProfFields").style.display = 'block';
	}else{
		document.getElementById("divProfFields").style.display = 'none';
	}
	/*var req = Inint_AJAX();
	req.onreadystatechange = function (){ 
		if (req.readyState==4) {
			if (req.status==200) {
				document.getElementById("divProfFields").innerHTML=req.responseText;
			} 
		}
	};
	req.open("GET", "getProfFields.php"); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
	req.send(null); */	
};

function getNFAID(val)
{
	if(val == "yes")
	{
		alert("Please enter your NFA ID#");
		document.getElementById("divNFA").style.display = 'block';
	}else{
		document.getElementById("divNFA").style.display = 'none';
	}
}
function getExch(val)
{
	if(val == "yes")
	{
		alert("Please list the Exchanges you are registered with and/or a member of");
		document.getElementById("divExch").style.display = 'block';
	}else{
		document.getElementById("divExch").style.display = 'none';
	}
}
function getSecOrg(val)
{
	if(val == "yes")
	{
		alert("Please list the securities organizations that you are currently registered with and/or a member of");
		document.getElementById("divSecOrg").style.display = 'block';
	}else{
		document.getElementById("divSecOrg").style.display = 'none';
	}
}
function getFira(val)
{
	if(val == "yes")
	{
		alert("Please list the financial industry regulatory authorities that you are currently registered with and/or a member of");
		document.getElementById("divFira").style.display = 'block';
	}else{
		document.getElementById("divFira").style.display = 'none';
	}
}
function getSeriesExam(val)
{
	if(val == "yes")
	{
		document.getElementById("divSeriesExam").style.display = 'block';
	}else{
		document.getElementById("divSeriesExam").style.display = 'none';
	}
}
function do_edits() 
{ 

	if (document.regForm.username.value.length == 0) {
	   alert("Please Enter a User Name.");
	   document.regForm.username.focus();
	   return false;
	}
	
	 var password=document.regForm.password;
		
		if(password.value==""){
			alert("Please enter your Password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		
		var pass_string = password.value;		
		var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password contains invalid characters');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="123456789";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password contains only characters. Please enter an alphanumeric	value like -alpha1-');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password contains only numbers. Please enter an alpanumeric value like -alpha1-');
			password.focus();
			return false;
		}
	

	if (document.regForm.firstname.value.length == 0) {
	   alert("Please Enter a First Name.");
	   document.regForm.firstname.focus();
	   return false;
	}else if (document.regForm.lastname.value.length == 0) {
	   alert("Please Enter Your Last Name.");
	   document.regForm.lastname.focus();
	   return false;
	}else if (document.regForm.address.value.length == 0) {
	   alert("Please Enter Your Address.");
	   document.regForm.address.focus();
	   return false;
	}else if (document.regForm.city.value.length == 0) {
	   alert("Please Enter Your City.");
	   document.regForm.city.focus();
	   return false;
	}else if (document.regForm.state.value == 'SS') {
	   alert("Please Select A State.\n\nIf outside the US, select Non US / Foreign");
	   document.regForm.state.focus();
	   return false;
	}else if (document.regForm.zipcode.value.length == 0) {
	   alert("Please Enter Your Zipcode.\n\nIf outside the US, enter '00000'");
	   document.regForm.zipcode.focus();
	   return false;
	}else if (document.regForm.email.value.length == 0) {
	   alert("Please Enter Your Email Address.");
	   document.regForm.email.focus();
	   return(false);
	}else if (document.regForm.email1.value.length == 0) {
	   alert("Please Enter Your Validation Email Address.");
	   document.regForm.email1.focus();
	   return false;
	}else if (document.regForm.email.value !=  document.regForm.email1.value) {
	   alert("Your Email address and Validated Email Address Do Not Match, please RE-ENTER.");
		document.regForm.email1.focus();
	   return false;	
	}else if (document.regForm.phone.value.length == 0) {
	   alert("Please Enter Your Phone Number.");
	   document.regForm.phone.focus();
	   return false;
	}else{
		var elm = document.getElementsByTagName("input");	
		var j=0, rdcount=0, rdname='', rdId='';
	
		for(var i=0; i< elm.length; i++)
		{
			if(elm[i].type.toLowerCase()=="radio")
			{
				j++;	//	alert("j="+j);
				if(j==1)
				{
					rdname = elm[i].name;	 // alert(rdname);
					rdId = elm[i].id;	 // alert(rdId);
				}
				if(elm[i].checked)
				{
					rdcount++;		//  alert(rdcount);
				}
			}
		}
	}
	
	if(document.regForm.exam[0].checked==true)
	{
		if(document.regForm.no_check_box.value == 1)
			{
				if( document.regForm["exam_id[]"].checked==false)
				{
					alert("Please Select At Least One series exam licenses");
					return false;
				}
				
			}
			else
			{
			
				total = document.regForm["exam_id[]"].length;			
				count = 0;
				for(i=0;i<total;i++)
				{
					if(document.regForm["exam_id[]"][i].checked==true)
					{
						count = 1;
					}
				}
				if(count ==0)
				{
					alert("Please Select At Least One series exam licenses");
					return false;
				}
			}
	}
	document.regForm.action="user_save.php";
	document.regForm.submit();
}
/****************************Login Validation**************************************/

function login_validate(frmpara)
{
	if(document.Memarea.username.value == ""){
		alert("Please enter User Name");
		document.Memarea.username.focus();
		return false;
	}else{
		
		var password=document.Memarea.password;
		
		if(password.value==""){
			alert("Please enter your Password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		
		var pass_string = password.value;		
		var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password contains invalid characters');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="123456789";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password contains only characters. Please enter an alphanumeric	value like -alpha1-');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password contains only numbers. Please enter an alphanumeric value like -alpha1-');
			password.focus();
			return false;
		}
	}
		
	document.Memarea.action="login_validate.php?frmpara="+frmpara;
	document.Memarea.submit();	
	
}

function forgot_validate()
{
	if(document.Forgotpass.username.value == ""){
		alert("Please Enter Your Username");
		document.Forgotpass.username.focus();
		return false;
	}else{
		document.Forgotpass.action ="forgot_password_result.php";
		document.Forgotpass.submit();	
	}
}
/***************************** My Account (Edit_personal_detail && Edit_login_detail) *******************************/

function edit_profile()
{
	if (document.frm_edit_personal.username.value.length == 0) {
	   alert("Please Enter a User Name.");
	   document.frm_edit_personal.username.focus();
	   return false;
	}else if (document.frm_edit_personal.password.value.length == 0) {
	   alert("Please Enter a Password.");
	   document.frm_edit_personal.password.focus(); 
	   return false;
	}else if (document.frm_edit_personal.firstname.value.length == 0) {
	   alert("Please Enter a First Name.");
	   document.frm_edit_personal.firstname.focus();
	   return false;
	}else if (document.frm_edit_personal.lastname.value.length == 0) {
	   alert("Please Enter Your Last Name.");
	   document.frm_edit_personal.lastname.focus();
	   return false;
	}else if (document.frm_edit_personal.address.value.length == 0) {
	   alert("Please Enter Your Address.");
	   document.frm_edit_personal.address.focus();
	   return false;
	}else if (document.frm_edit_personal.city.value.length == 0) {
	   alert("Please Enter Your City.");
	   document.frm_edit_personal.city.focus();
	   return false;
	}else if (document.frm_edit_personal.state.value == 'SS') {
	   alert("Please Select A State.\n\nIf outside the US, select Non US / Foreign");
	   document.frm_edit_personal.state.focus();
	   return false;
	}else if (document.frm_edit_personal.zipcode.value.length == 0) {
	   alert("Please Enter Your Zipcode.\n\nIf outside the US, enter '00000'");
	   document.frm_edit_personal.zipcode.focus();
	   return false;
	}else if (document.frm_edit_personal.email.value.length == 0) {
	   alert("Please Enter Your Email Address.");
	   document.frm_edit_personal.email.focus();
	   return(false);
	}else if (document.frm_edit_personal.email1.value.length == 0) {
	   alert("Please Enter Your Validation Email Address.");
	   document.frm_edit_personal.email1.focus();
	   return false;
	}else if (document.frm_edit_personal.email.value !=  document.frm_edit_personal.email1.value) {
	   alert("Your Email address and Validated Email Address Do Not Match, please RE-ENTER.");
		document.frm_edit_personal.email1.focus();
	   return false;
	}else if (document.frm_edit_personal.alternate_email.value.length == 0) {
	   alert("Please Enter Your Alternate Email Address.");
	   document.frm_edit_personal.alternate_email.focus();
	   return false;
	}else if (document.frm_edit_personal.phone.value.length == 0) {
	   alert("Please Enter Your Phone Number.");
	   document.frm_edit_personal.phone.focus();
	   return false;
	}else if (document.frm_edit_personal.coupon_code.value.length == 0) {
	   alert("Please Enter Your Coupon Code/Promotional Code.");
	   document.frm_edit_personal.coupon_code.focus();
	   return false;
	}else if (document.frm_edit_personal.referered_by.value.length == 0) {
	   alert("Please Enter Your Referered By.");
	   document.frm_edit_personal.referered_by.focus();
	   return false;
	}
	document.frm_edit_personal.action="myaccount_save.php?type=personal";
	document.frm_edit_personal.submit();		
}
function login_detail()
{
	var password=document.frm_edit_login.password;
		if(password.value==""){
			alert("Please enter your password");
			password.focus();
			return false;
		}else if(password.value.length < 6){
			alert("Your password should contain minimum 6 characters");
			password.focus();
			return false;
		}
		var pass_string = password.value;		
		var valid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for (var i=0; i<pass_string.length; i++) {
        	if (valid.indexOf(pass_string.charAt(i)) < 0) {
            	alert('Your password should contain both letters and numbers');
				password.focus();
            	return false;
        	}
    	}
		
		var alphaCount=0
 		var numCount=0

		var num_valid="1234567890";
		
		for (var i=0; i<pass_string.length; i++) {
			if (num_valid.indexOf(pass_string.charAt(i)) < 0) {
			 numCount++;
			}
		}
		if(numCount==pass_string.length){
			alert('Your password should contain both letters and numbers');
			password.focus();
			return false;
		}
		
		var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for (var i=0; i<pass_string.length; i++) {
			if (alph_valid.indexOf(pass_string.charAt(i)) < 0) {
				alphaCount++;
			}
		}
		if(alphaCount==pass_string.length){
			alert('Your password should contain both letters and numbers');
			password.focus();
			return false;
		}
		document.frm_edit_login.action="myaccount_save.php?type=login";
		document.frm_edit_login.submit();		
}

/************************** Search Page *********************/

function search_text()
{	
	if(document.frmSearch.txtsearch.value == "")
	{
		alert("Please Enter any word for Searching Purpose");
		document.frmSearch.txtsearch.focus();
		return false;
	}
	document.frmSearch.action = "search.php";
	document.frmSearch.submit();
}

/************************** Search Page *********************/

function winPop()
{
	my_window = window.open ("","mywindow","location=1,status=1,scrollbars=1,width=300,height=200"); 
	my_window.document.write('<H1>Popup Test!</H1>');
}





