// Mail Validation;
var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
function checkEmail(fieldvalue)
{
	if(remail.test(fieldvalue))
	{
		return false;
	} else {
		return true;
	}
}

function sign_up_validation(frm)
{
	
	var err;
	var ecount = 0;
	txt_email  = frm.newEmail.value;
	txt_fname  = frm.newName.value;
	txt_postal = frm.newPostal.value;
	txt_password = frm.newPassword1.value;
	txt_password2 = frm.newPassword2.value; 
	err="";
	
	if(txt_email=="")
    {
		ecount++;
		err=ecount+". Please enter E-mail!<br> ";
    }
	 if(checkEmail(txt_email) && txt_email != '')
	{
		ecount++;
		err+=ecount+". Please enter correct E-mail! <br>";		 
	}

	 if(txt_fname=="")
	{
		ecount++;
		err+=ecount+". Please enter full name! <br>";
		    
    }
	 if(txt_postal=="")
	{
		ecount++;
		err+=ecount+". Please enter postal code! <br>";
	  }
	
	 if(txt_password=="")
	{
		ecount++;
		err+=ecount+". Please enter password! <br>";
    }
	 if(txt_password2=="")
	{
	     ecount++;
		err+=ecount+".Please enter comfirm password! <br>";
		
    }
	
	 if(txt_password != txt_password2 && txt_password!="" )
	{
		ecount++;
		err+=ecount+". Password and Repeat Password not match! <br>";
	
    }
    
	if(err == "")
	{
		 if (window.XMLHttpRequest) {
					xmlhttp21 = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp21 = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action  ='register';
					/*var url = "<?php echo HTTP_SERVER;?>" + "/includes/modules/ajaxed_category_subscripts_call.php"*/
					var url ="pages/ajax/login.php";
					var posturl = "?rands="+ran_number+"&action="+action+"&email="+txt_email+"&pass="+txt_password+"&fname="+txt_fname+"&postal="+txt_postal;
					
					
					xmlhttp21.open("POST",url,true);
					xmlhttp21.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp21.send(posturl);
					xmlhttp21.onreadystatechange=function()
					 {
								
							 if(xmlhttp21.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp21.responseText != ''){
							    document.getElementById('signUp').innerHTML = xmlhttp21.responseText;
								document.getElementById('signupSubmit').innerHTML = '';
								
								} 								/* if(trim(xmlhttp.responseText)!="") */
						  }	 /* if(xmlhttp.readyState == 4) */
					 } //end function /* end ajax */
	}else{
		 
		document.getElementById('error_notification').innerHTML = err;
		return false;
	}

}



function changeFocus(id){

var val = document.getElementById(id).innerHTML;
document.getElementById('stepdesc').innerHTML = val;
}

function login_validation(frm)
{
	
	var err="";
	var ecount = 0;
	txt_email = frm.email.value;
	txt_password = frm.password.value;
		
	if(txt_email=="")
    {
		ecount++;
		err=ecount+'.Enter e-mail! <br>';
	}
	 if(checkEmail(txt_email) && txt_email != '')
	{
		ecount++;
		err+=ecount+".Enter correct e-mail!<br>"; 
	}
	 if(txt_password=="")
	{
		ecount++;
		err+=ecount+".Enter password!<br>";
	}
	if(err == "")
	{
		frm.submit();		 

	}else{
		document.getElementById('login_error').innerHTML = err;
		return false;
		
	}

}

function chapter_call(menu_id){
	//chapter_id = menu_id+'chapter';
	//topic_id = menu_id+'topics';
	//alert(topic_id);
	var check = document.getElementById(menu_id).style.display;
	//var check = document.getElementById(chapter_id).style.display;
	//var tcheck = document.getElementById(topic_id).style.display;
	//alert(tcheck);
	if (menu_id != ''){
		if(check == 'none' || check==''){
		document.getElementById(menu_id).style.display = 'block';
		}else{
		document.getElementById(menu_id).style.display = 'none';
			}
	} /*if(topic_id != ''){
			if(tcheck == 'none' || tcheck == ''){
		document.getElementById(topic_id).style.display = 'block';
		}else{
			document.getElementById(topic_id).style.display = 'none';
		}
	}*/
	
	}
	

function reset_pass(fr){
	
	var email = document.getElementById('fpass').value;
	var er='';
	var eco=0;
	if(email=="")
    {
		eco++;
		er=eco+'.Enter e-mail! <br>';
	}
	 if(checkEmail(email) && email != '')
	{
		eco++;
		er+=eco+".Enter correct e-mail!<br>"; 
	}
	
	if(er == "")
	{
		
		if (window.XMLHttpRequest) {
					xmlhttp2 = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp2 = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action  ='reset_pass';
					/*var url = "<?php echo HTTP_SERVER;?>" + "/includes/modules/ajaxed_category_subscripts_call.php"*/
					var url ="pages/ajax/login.php";
					var posturl = "?rands="+ran_number+"&action="+action+"&cmail="+email;
					
					
					xmlhttp2.open("POST",url,true);
					xmlhttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp2.send(posturl);
					xmlhttp2.onreadystatechange=function()
					 {
								
							 if(xmlhttp2.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp2.responseText != ''){
							    document.getElementById('forgot_content').innerHTML = xmlhttp2.responseText;
															
								} 								/* if(trim(xmlhttp.responseText)!="") */
						  }	 /* if(xmlhttp.readyState == 4) */
					 } //end function /* end ajax */

	} else{
		document.getElementById('fpass_error').innerHTML = er;
		return false;
		
	}
	
}

function listCurrentProduct(){
	
	if (window.XMLHttpRequest) {
					xmlhttp_listproduct_user = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp_listproduct_user = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action  ='list_product';
					var url ="pages/ajax/login.php";
					//var posturl = "?rands="+ran_number+"&action="+action+"&product_name="+product_name+"&amount="+amount+"&discount="+discount;
					var posturl = "?rands="+ran_number+"&action="+action;
					
					xmlhttp_listproduct_user.open("POST",url,true);
					xmlhttp_listproduct_user.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp_listproduct_user.send(posturl);
					xmlhttp_listproduct_user.onreadystatechange=function()
					 {
								
							 if(xmlhttp_listproduct_user.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp_listproduct_user.responseText != ''){
								 document.getElementById('its_grid_client').style.display  = 'block';
								 document.getElementById('its_grid_client').innerHTML = xmlhttp_listproduct_user.responseText;
								} 								
						  }	
					 }
	
	
}

function listMyCurrentDownload(){
	
	var myid = document.getElementById('myid').value;
		if (window.XMLHttpRequest) {
					xmlhttp_listproduct_user = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp_listproduct_user = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action  ='list_mydownload';
					var url ="pages/ajax/login.php";
					//var posturl = "?rands="+ran_number+"&action="+action+"&product_name="+product_name+"&amount="+amount+"&discount="+discount;
					var posturl = "?rands="+ran_number+"&action="+action+"&myid="+myid;
					
					xmlhttp_listproduct_user.open("POST",url,true);
					xmlhttp_listproduct_user.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp_listproduct_user.send(posturl);
					xmlhttp_listproduct_user.onreadystatechange=function()
					 {
								
							 if(xmlhttp_listproduct_user.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp_listproduct_user.responseText != ''){
								 document.getElementById('its_grid_client').style.display  = 'block';
								 document.getElementById('its_grid_client').innerHTML = xmlhttp_listproduct_user.responseText;
								} 								
						  }	
					 }
	
	
}

	
function contentList(proid){
	
	
	
	  if (window.XMLHttpRequest) {
					xmlhttp_listproduct_user = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp_listproduct_user = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action         = 'contentList';
					var url ="pages/ajax/login.php";
					//var posturl = "?rands="+ran_number+"&action="+action+"&product_name="+product_name+"&amount="+amount+"&discount="+discount;
					var posturl = "?rands="+ran_number+"&action="+action+"&contentid="+proid;
					
					xmlhttp_listproduct_user.open("POST",url,true);
					xmlhttp_listproduct_user.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp_listproduct_user.send(posturl);
					xmlhttp_listproduct_user.onreadystatechange=function()
					 {
								
							 if(xmlhttp_listproduct_user.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp_listproduct_user.responseText != ''){
								 document.getElementById('main').innerHTML  = '';
								 document.getElementById('main').innerHTML = xmlhttp_listproduct_user.responseText;
								} 	
								else{
									document.getElementById('main').innerHTML  = '';
								// document.getElementById('main').innerHTML = 'Content Not Available';
									}
						  }	
					 }
	
}
	
	function addComments(its)
	{
		var err ='';
		txt_mail    = its.cemail.value;
		txt_name    = its.cname.value;
		txt_comment = its.comment.value;
		txt_title   = its.title.value;
		txt_its     = its.titleits.value;
				
		er=0;
		if(txt_its !="its"){
				if(txt_name =="")
				{
					er++;
					err =er+'.Enter Full Name! <br>';
				}
					if(txt_mail=="")
				{
					er++;
					err += er+'.Enter e-mail! <br>';
				}
				 if(checkEmail(txt_mail) && txt_mail != '')
				{
					er++;
					err += er+".Enter correct e-mail format!<br>"; 
				}
				
		} else {
			    if(txt_title =="")
				{
					er++;
					err =er+'.Enter Title ! <br>';
				}
			}
				if(txt_comment =="")
				{
					er++;
					err += er+'.Enter Comments! <br>';
				}
	if(txt_comment.length > 2000)
    {
		er++;
		err += er+'.Maximum 2000 character Only ! <br>';
	}
		
	if(err != ""){
		document.getElementById('error_noti').style.display='block';
		document.getElementById('error_noti').innerHTML=err;
		return false;
		} else{
	if (window.XMLHttpRequest) {
				xmlhttp_usercomment = new XMLHttpRequest();
				  } else if(window.ActiveXObject) {
					xmlhttp_usercomment = new ActiveXObject("MSXML2.XMLHTTP");
				  }
				    					
					var ran_unrounded  = Math.random()*100000;
					var ran_number     = Math.floor(ran_unrounded);
					var action  ='addComments';
					var url ="pages/ajax/login.php";
					
					var posturl = "?rands="+ran_number+"&action="+action+"&txt_mail="+txt_mail+"&txt_name="+txt_name+"&txt_comment="+txt_comment+"&txt_title="+txt_title;
					
					xmlhttp_usercomment.open("POST",url,true);
					xmlhttp_usercomment.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
					xmlhttp_usercomment.send(posturl);
					xmlhttp_usercomment.onreadystatechange=function()
					 {
								
							 if(xmlhttp_usercomment.readyState == 4)
						  	 {
					  			
						  		if(xmlhttp_usercomment.responseText != ''){
								 its.reset();
								 document.getElementById('comm_cont').style.display='none';
								 document.getElementById('error_noti').style.display='block';
								 document.getElementById('error_noti').innerHTML = xmlhttp_usercomment.responseText;
								} 								
						  }	
					 }
	
		}
	}
