/* function for opening popup window */
function openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-350)/2);
	var top			= parseInt((screen.height-300)/2)
	if(!height)
		height = 550;
	if(!width)
		width = 580;
		
	var win_options = 'height='+ parseInt(height) +',width='+ parseInt(width) +',resizable=yes,' 
	+ 'scrollbars=yes,left=' + left + ',top=' + top;
	window.open(url,popup_name,win_options,'');
}

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function showhidetab(spanid)
{
	i=0;
	while(true)
	{
		var span_id = document.getElementById(spanid+i);
		if(!span_id)
			break;
		else
		{
			if (span_id.style.display != '') 
			{
				span_id.style.display='';
			} 
			else 
			{
				span_id.style.display='none';
			}	
			i++;
		}    
	}	
}

function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}


function CalcNewPenisSize()
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/;	
	var SizeIn;
	if (document.getElementById('CurPenisSize').value != null && document.getElementById('CurPenisSize').value != "")
	{
		if(anum.test(document.getElementById('CurPenisSize').value) == true && document.getElementById('CurPenisSize').value > 0)
		{
			if (parseFloat(document.getElementById('CurPenisSize').value) > 0 && parseFloat(document.getElementById('CurPenisSize').value) < 15)
			{
				SizeIn = parseFloat(document.getElementById('CurPenisSize').value) + parseFloat(document.getElementById('duration_months').value);
					document.getElementById("show_new_size").style.display = "";
					document.getElementById("newPenisSize").innerHTML =  SizeIn.toFixed(1) + " inches";
		   } 
		   else 
		   {
			 document.getElementById("newPenisSize").innerHTML = "Too huge!";
		   }
		}
		else
		{
			alert('Please enter valid current size!');
		}
	  }
	  else{
	  	alert('Please enter current size!');
	  }
}

function CalcNewAndroPenisSize()
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/;	
	var SizeIn;
	if (document.getElementById('andro_length').value != null && document.getElementById('andro_length').value != "")
	{
		if(anum.test(document.getElementById('andro_length').value) == true && document.getElementById('andro_length').value > 0)
		{
			Sizecms = parseFloat(document.getElementById('andro_length').value) + parseFloat(-0.327+(0.562*document.getElementById('duration_months').value));
			document.getElementById("show_new_andro_size").style.display = "";
			document.getElementById("newAndroPenisSize").innerHTML = Sizecms.toFixed(1) + " cms";
		}
		else
		{
			alert('Please enter valid current size!');
		}
	  }
	  else{
	  	alert('Please enter current size!');
	  }
}


function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
return "";
}

function redirect_ip_popup()
{
	if(getCookie('IS_REDIRECT'))
	{
		if(getCookie('REDIRECT_URL') != "")
		{	
			location.href=getCookie('REDIRECT_URL');
		}
		return;
	}
}

function html_get_ip_country_popup(url,qstring,div)
{
	if (url.length==0)
	{
		return;
	}
	if(getCookie('IS_REDIRECT'))
	{
		if(getCookie('REDIRECT_URL') != "")
		{	
			location.href=getCookie('REDIRECT_URL');
		}
		return;		
	}
	$.ajax({
		url: url,
		data:'',
		success: function(data) {
			if(data != '' && trim(data) != 'false'){
				$.superbox.settings = {
					boxId: "superbox", // Id attribute of the "superbox" element
					boxClasses: "", // Class of the "superbox" element
					overlayOpacity: .6, // Background opaqueness
					boxWidth: "600", // Default width of the box
					boxHeight: "500", // Default height of the box
					loadTxt: "<img src='/images/loading.gif' alt='Loading...' />", // Loading text
					closeTxt: "Close", // "Close" button text
					prevTxt: "Previous", // "Previous" button text
					nextTxt: "Next", // "Next" button text
					overflow: "auto"
				};
				$.superbox();
  				$('#anchor').trigger('click');
			}
		}
	});
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
