
function popup_friend_id_help() 
{
	window.open('/friend_id_help', 'friend_id_help', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=690,height=150,left = 295,top = 325');
}

function fixCpollLayout()
{
	var main_table_row = document.getElementById('main_table_row');
	var content_user = document.getElementById('content_user');
	var bottom_ads = document.getElementById('bottom_ads');
	if(main_table_row && content_user && bottom_ads)
	{
		if(main_table_row.scrollHeight > content_user.scrollHeight + bottom_ads.scrollHeight)
		{
			content_user.style.height = (main_table_row.scrollHeight - bottom_ads.scrollHeight)+"px";
		}
	}
	fixWelcomeLayout();
}

function fixWelcomeLayout()
{
	var	hot_or_not_random = document.getElementById('hot_or_not_random');
	var welcome_message = document.getElementById('welcome_message');
	if( hot_or_not_random && welcome_message )
	{
		/*if(hot_or_not_random.clientHeight < 200) 
		{	
			hot_or_not_random.style.height=200+'px';

		}*/
		if(hot_or_not_random.clientHeight > welcome_message.clientHeight)
		{
			welcome_message.style.height = (hot_or_not_random.clientHeight-15) +'px';
		}
		
	}
}


// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function IsValidEmail(str) 
{
	/*if ( str.indexOf(".") <=2 || str.indexOf("@") <=0  )
		return false;*/
		
	if( str.indexOf(",") >=0 )
		return false;
	if( str.indexOf(";") >=0 )
		return false;
	if( str.indexOf("(") >=0 )
		return false;
	if( str.indexOf(")") >=0 )
		return false;
	if( str.indexOf("+") >=0 )
		return false;
	if( str.indexOf(" ") >=0 )
		return false;
	if( str.indexOf("?") >=0 )
		return false;
	if( str.indexOf("`") >=0 )
		return false;
	if( str.indexOf("#") >=0 )
		return false;
	if( str.indexOf("!") >=0 )
		return false;
	if( str.indexOf("$") >=0 )
		return false;
	if( str.indexOf("%") >=0 )
		return false;
	if( str.indexOf("*") >=0 )
		return false;
	if( str.indexOf("=") >=0 )
		return false;																										
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}
function $(id) 
{
	return document.getElementById(id);
}
function clearText(thefield) 
{ 
	if (thefield.defaultValue == thefield.value) 
	thefield.value = "" ;
	else thefield.value = thefield.defaultValue 
}
function validateLogin(form)
{
	if (form.username.value.length == 0 ) 
	{
		alert("Please enter your \"Username\".");
		form.username.focus();
		return (false);
	}
	if (form.password.value.length == 0 ) 
	{
		alert("Please enter your \"Password\".");
		form.password.focus();
		return (false);
	}

}
function validateRecoverPassword(form)
{
	stremail=document.getElementById("email");
	if (stremail.value.length==0)
	{
		alert("Please enter your email!");
		stremail.focus();
		return (false);
	}
	if(!IsValidEmail(stremail.value))
	 {
		alert("Email format is incorect.");
		stremail.focus();
		return(false);
	}
}
function check_username() {
		var user_name_value  = $F( 'username' );
		var pars = 'check_username=true&username=' + user_name_value;
		/*need to modified
		hide_bad_login_msg();
		show_doing_login_msg();
		hide_login_form();
		
		var myAjax = new Ajax.Request('/', 
		                              {method: 'get', parameters: pars, onComplete: login_response}
									 );
*/
		return false;
	}
function delete_item(title, id)
{
	if (confirm("Really Delete '"+title+"'"))
	   window.location="poll_delete?redirect=browse&id="+id;

}
function delete_item_user_polls(title, id)
{
	if (confirm("Really Delete '"+title+"'"))
	   window.location="poll_delete?redirect=user_polls&id="+id;

}
function ClipBoard(obj) {
	var text = document.getElementById(obj);
	text.select();
	var agt = navigator.userAgent.toLowerCase();
	var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	if( is_ie ) {
		Copied = text.createTextRange();
		Copied.execCommand("Copy");
		alert( 'Source code has been copied to your clipboard.' );
	} else {
		alert( 'This feature only works in Internet Explorer.' );
	}
}


function validate_title()
{
if (document.getElementById('title').value.length==0)
{ 
	alert("Please enter a question!"); 
	document.getElementById('title').focus();		 
	return;
}
document.poll.submit();		
	
	
}

function remove_answer(id)
{ 
	if (confirm('Really remove?'))
   		document.getElementById(id).submit();
    
}

//validate link exchange.

function trim(str)				
{
	return (str.replace(/^\s*|\s*$/gi,''));
} 

function isEmail(str)			// verifica un string daca e email
{   
	var reEmail  = /^.+\@.+\..+$/;	// expresia regulata pentru verificare email
	return reEmail.test(trim(str));
} 
function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function valid_link_exchange()
{
	if (document.link_exchange.name.value.length==0)
	{ 
		alert("Please enter 'Your Name'!");
		document.link_exchange.name.focus();	
		return;
	}
	if (isEmail(document.link_exchange.email.value)==false)	  
	{ 
		alert("Please enter a valid 'Email' address!");
		document.link_exchange.email.focus();
		return;
	}
	if (document.link_exchange.site_url.value.length==0)
	{ 
	  alert("Please enter enter 'Site URL'!");
	  document.link_exchange.site_url.focus();
	  document.link_exchange.site_url.value="http://";
	  return;
	}
	if(isUrl(document.link_exchange.site_url.value)==false)
	{
		alert("Please enter enter a valid 'Site URL'!");
		document.link_exchange.site_url.focus();
		document.link_exchange.site_url.value="http://";
		return;
	}
	if (document.link_exchange.site_title.value.length==0)
	{ 
		alert("Please enter 'Website Title'!");
		document.link_exchange.site_title.focus();
		return;
	}
	if (document.link_exchange.description.value.length==0)
	{ 
		alert("Please enter 'Site Description'!");
		document.link_exchange.description.focus();
		return;
	}
	if (document.link_exchange.url_to_link.value.length==0)
	{ 
		alert("Please enter 'URL To Page With Our Link'");
		document.link_exchange.url_to_link.focus();
		document.link_exchange.url_to_link.value="http://";
		return;
	}
	if(isUrl(document.link_exchange.url_to_link.value)==false)
	{
		alert("Please enter a valid 'URL To Page With Our Link'");
		document.link_exchange.url_to_link.focus();
		document.link_exchange.url_to_link.value="http://";
		return;
	}

 document.getElementById('link').submit();  
}
var agt = navigator.userAgent.toLowerCase();
var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
function ClipBoard(obj) {
	var text = document.getElementById(obj);
	text.select();
	if( is_ie ) {
		Copied = text.createTextRange();
		Copied.execCommand("Copy");
		alert( 'Source code has been copied to your clipboard.' );
	} else {
		alert( 'This feature only works in Internet Explorer.' );
	}
}
function ValidateSendRequest(form)
{
	if (form.featured_request.value.length == 0 ) 
	{
		alert("Please enter your \"Your suggestion\".");
		form.featured_request.focus();
		return (false);
	}
	if (form.featured_email.value.length == 0 ) 
	{
		alert("Please enter your Email.");
		form.featured_request.focus();
		return (false);
	}
	else
	{
		if (! checkEmail(form.featured_email.value)) {
        alert("Please enter a valid email address");
        return (false);
    }
	}
}


/*
Email Validation
*/

function checkEmail(fld)
{ // simple email check
  //alert(fld);
 if(!fld.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var phony= /@(\w+\.)*example\.(com|net|org)$/i;
  if(phony.test(fld))
  { /*status= 'Please enter your email address in the '+fieldname(fld)+' field.';*/ return false; }
  var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
  if(!emailfmt.test(fld))
  {  return false; }
  return true;
 
}
function delSession()
{
			//var url = 'http://www.newcpoll.cj.webland.ro/resize/del.php';
			//var myAjax = new Ajax.Request( url, { onComplete: showResponse }); 
			window.location='/dell';
}
function delSession3(type)
{
			//var url = 'http://www.newcpoll.cj.webland.ro/resize/del.php';
			//var myAjax = new Ajax.Request( url, { onComplete: showResponse }); 
			window.location='/dell?type='+type;
}
function delSession2(url)
{
			//var url = 'http://www.newcpoll.cj.webland.ro/resize/del.php';
			//var myAjax = new Ajax.Request( url, { onComplete: showResponse }); 
			window.location='/delll?urll='+url;
}
 function setPoll()
{
	
	//var sss = bgi.replace("-abc","");
	//sss ='-'+Math.floor(Math.random()*5000);
	//var rat = $F('background_size');
	var uri = 'http://www.cpoll.com/del';
	//var uri = 'http://www.newcpoll.cj.webland.ro/del';
	//var uri = 'http://127.0.0.1/intranet/del.php';
	var pars = 'title_color=' + $F('title_color') + '&text_color=' + $F('text_color') + '&background_color=' + $F('background_color') + '&background_position=' + $F('background_position') + '&graphic_size=' + $F('graphic_size') + '&graphic_tile=' + $F('graphic_tile') + '&background_image=' + $F('background_image') + '&background_repeat=' + $F('background_repeat') + '&border_style=' + $F('border_style') + '&border_size=' + $F('border_size') + '&border_color=' + $F('border_color');
	
	var myAjax = new Ajax.Request( uri, { method: 'get', parameters: pars }); 

}