// JavaScript Document
var checkobj;

function agreesubmit()
{
	//checkobj=el
	
	var username,email,password,confirmPassword,checkbox,fullname;//security_code;
	username=document.frmRegistration.username.value;
	fullname=document.frmRegistration.fullname.value;
	
	email=document.frmRegistration.email.value;
	password=document.frmRegistration.password.value;
	confirmPassword=document.frmRegistration.confirmPassword.value;
	//security_code=document.frmRegistration.security_code.value;
	checkbox=document.frmRegistration.checkbox.value;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(fullname == "" || fullname == "FULL NAME") {
	
	inlineMsg('fullname','You must enter your Fullname.',2);
	return false;
	}
	if(username == "" || username == "USERNAME") {
	inlineMsg('username','You must enter your Username.',2);
	return false;
	}
	if(!username.match(nameRegex)) {
	inlineMsg('username','You have entered an invalid name.',2);
	return false;
	}
	if(email == "" || email == "EMAIL ADDRESS") {
	inlineMsg('email','You must enter your email id.',2);
	return false;
	}
	if(!email.match(emailRegex)) {
	inlineMsg('email','You have entered an invalid email id.',2);
	return false;
	}
	if(password == "" || password == "PASSWORD") {
	inlineMsg('password','You must enter your password.',2);
	return false;
	}
	if(password!=confirmPassword)
	{
		inlineMsg('confirmPassword','Passowrd donot match.',2);
		return false;
	}

	if (document.frmRegistration.checkbox.checked==false)
	{
		inlineMsg('checkbox','You must agree Papatoto terms of use.',2);
		return false;
	}
	
	document.frmRegistration.submit();
}

function changeCommentStatus(t)
{
	window.location.href="operation/processing.php?commentStatus="+t;
}

function orderUp(t)
{
	window.location.href="operation/processing.php?orderUp="+t;
}

function orderDown(t)
{
	window.location.href="operation/processing.php?orderDown="+t;
}

function submitform()
{
	document.frmRegistration.submit();
}

function promote_page()
{
	var names = new Array();
	var email;
	email=document.frmPromote.email.value; 
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	names=email.split(",");
	
	for(i=0;i<names.length;i++)
	{
		if(names[i].indexOf('@')=='-1'||names[i].indexOf('.')=='-1')
		{
			alert("Invalid email id of "+names[i]);
			return false;
		}
	}
	document.frmPromote.submit();
}

function contact_us()
{
	var name,address,email,message;
	name=document.frmContactUs.name.value;	
	address=document.frmContactUs.address.value; 
	email=document.frmContactUs.email.value;
	message=document.frmContactUs.message.value;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	if(name == "" || name == "NAME") {
	inlineMsg('name','You must enter your name.',2);
	return false;
	}
	if(address == "" || address == "ADDRESS") {
	inlineMsg('address','You must enter your address.',2);
	return false;
	}
	if(email == "" || email == "EMAIL") {
	inlineMsg('email','You must enter your email id.',2);
	return false;
	}
	if(!email.match(emailRegex)) {
	inlineMsg('email','You have entered an invalid email id.',2);
	return false;
	}
	if(message == "" || message == "MESSAGE") {
	inlineMsg('message','You must enter your message.',2);
	return false;
	}
	
	document.frmContactUs.submit();

}


function submittag()
{
        var a=document.frmAddMoreTag.tag.value;
	if(a=='')
	{
		alert('please enter the tag name!');
		return false;
	}
	document.frmAddMoreTag.submit();
}

function submitComment()
{
	var username,email,rating,comment;
	username=document.frmSendComment.username.value;
	email=document.frmSendComment.email.value;
	//rating=document.frmSendComment.rating.value;
	comment=document.frmSendComment.comment.value;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	if(username == "") {
	inlineMsg('username','You must enter your name.',2);
	return false;
	}
	if(!username.match(nameRegex)) {
	inlineMsg('username','You have entered an invalid name.',2);
	return false;
	}
	if(email == "") {
	inlineMsg('email','You must enter your email id.',2);
	return false;
	}
	if(!email.match(emailRegex)) {
	inlineMsg('email','You have entered an invalid email id.',2);
	return false;
	}
	
	if(comment == "") {
	inlineMsg('comment','You must enter your comment.',2);
	return false;
	}
	document.frmSendComment.submit();
}

function submitlogin()
{
	var email,pwd;
	email=document.frmLogin.email.value;
	
	pwd=document.frmLogin.pwd.value; 
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	if(email == "" || email == "USERNAME / EMAIL ADDRESS") {
	inlineMsg('email','You must enter your Username/Email id.',2);
	return false;
	}
	if(pwd == "" || pwd == "PASSWORD") {
	inlineMsg('pwd','You must enter your password.',2);
	return false;
	}
      if (document.getElementById('remember_me').checked)
      {
        
	toMem(document.frmLogin); 
     }
	else 
	delMem(document.frmLogin); 
	
	document.frmLogin.submit();

}

function submitEmail()
{
	
	var email1;
	email1=document.frmForgetPwd.email1.value;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(email1 == "") {
	inlineMsg('email1','You must enter your email id.',2);
	return false;
	}
	if(!email1.match(emailRegex)) {
	inlineMsg('email1','You have entered an invalid email id.',2);
	return false;
	}
	document.frmForgetPwd.submit();
}

function submithub()
{
	var page_title,page_category,age,age1;//,security_code,tag1,tag2;
	page_title=document.frmDiscovrey.page_title.value;
	page_category=document.frmDiscovrey.page_category.value;
	age=document.getElementById('age').checked;
	age1=document.getElementById('age1').checked;
	
	
	//security_code=document.frmDiscovrey.security_code.value;
	//tag1=document.frmDiscovrey.tag1.value;
	//tag2=document.frmDiscovrey.tag2.value;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(page_category == "0")
	{
		inlineMsg('page_category','You must select article topic.',2);
		return false;
	}
	
	if(age == false && age1 == false)
	{
		inlineMsg('age','You must select Age bar.',2);
		return false;
	}
	
	if(page_title=="")
	{
		inlineMsg('page_title','You must entered article title.',2);
		return false;
	}
	
	
	document.frmDiscovrey.submit();
}

function submitEditProfile()
{
	document.frmEditProfile.submit();
}

function activate(t)
{
	//alert(t);
	window.location.href="operation/processing.php?status="+t;
}

function changeProfile(t)
{
	//alert(t);
	window.location.href="operation/edit_processing.php?profile="+t;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
 var msg;
 
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
 
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}

function check()
		{
		var a;
		a=document.getElementById('profile').style.display;
		if(a == 'none')
		{
		document.getElementById('profile').style.display = 'block';
		document.getElementById('contact').style.display = 'none';
		document.getElementById('a').className = "activemenu";
		document.getElementById('b').className = "";
        document.getElementById('message').style.display = 'none';
		}
	
		}
		
		function check1()
		{
		var a;
		a=document.getElementById('contact').style.display;
		if(a == 'none')
		{
		document.getElementById('contact').style.display = 'block';
		document.getElementById('profile').style.display = 'none';
		document.getElementById('b').className = "activemenu";
		document.getElementById('a').className = "";
        document.getElementById('message').style.display = 'none';
		}
	
		}
		
		function checkcomment(id,username1,path)
		{
		
		var uname,email,comment,a;
                a=document.frmcomment.username.value;
		if(a == '')
		{
		uname=username1;
		
		}
		else
		{
		uname=a;
			
		}
		
		email=document.frmcomment.email.value;
		
		comment=document.frmcomment.comment.value;
		



		rate=document.frmcomment.rating.value;
		
		
		if(uname == '')
		{
		alert('Enter your name');	
		document.frmcomment.name.focus();
		return false;
		}
		else if(email == '')
		{
		alert('Enter your email id');	
		document.frmcomment.email.focus();
		return false;	
		}
		else if(!emailverify(email))
		{
		alert('Please enter the valid email Id');
		document.frmcomment.email.focus();
		return false;
		}
		else if(comment == '')
		{
		alert('Please enter your comment');
		document.frmcomment.comment.focus();
		return false;	
		}
		
		
		LoadPage1(path+'include.php?option=comment&hub_id='+id+'&email='+email+'&mess='+comment+'&uname='+uname+'&rate='+rate,'dismiss');
		}
		
		function checkmessage(id,email,path)
		{
			
		var name,message,email_session;
		name=document.frmcontact.name.value;
		message=document.frmcontact.message.value;
		email_session=document.frmcontact.email_session.value;
		
		if(name == '')
		{
		alert('Enter your Email address');	
		document.frmcontact.name.focus();
		return false;
		}
		else if(!emailverify(name))
		{
		alert('Please enter the valid email Id');
		document.frmcontact.name.focus();
		return false;
		}
		else if(message == '')
		{
		alert('Please enter your comment');
		document.frmcontact.message.focus();
		return false;	
		}
		LoadPage(path+'include.php?option=email&hub_id='+id+'&email='+email+'&mess='+message+'&semail='+name+'&email_session='+email_session+'&path='+path,'dismess');
		//LoadPage(path+'include.php?option=email&hub_id='+id+'&email='+email+'&mess='+message+'&semail='+name,'dismess');
				
		}
function rbToggle(val)
{
	//var rb1 = document.getElementById('rb1');
	//var rb2 = document.getElementById('rb2');
	
	var v = val;
	
	if(v == 'P')
	{
		document.getElementById('bank').style.display = 'none';
		document.getElementById('paypal').style.display = 'block';
	}
	else if(v == 'B')
	{
		document.getElementById('paypal').style.display = 'none';
		document.getElementById('bank').style.display = 'block';
	}
}
