function isBlank( s )
{
	if(trim(s).length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Trim
function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}


//email validate
function validateEmail(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
	{
		return false;
	}
	return true;
}

function isDigit (c)
{
   return ((c >= "0") && (c <= "9"))
}

function isFloat (s)
{
    var decimalPointDelimiter = "."
    var i;
    var seenDecimalPoint = false;

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isProper(string) {

   if (!string) return false;
   var iChars = "~!^&+=-*|,:<>[]{}`\';()@&$#%\".";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
} 

function getOSPlatform()	
{
	var agt=navigator.userAgent.toLowerCase();
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

	if(is_win == true)
	{
		if(is_win95 == true){return "win95"; return false;}
		if(is_win16 == true){return "win16"; return false;}
		if(is_win31 == true){return "win31"; return false;}
		if(is_winme == true){return "winme"; return false;}
		if(is_win2k == true){return "win2k"; return false;}
		if(is_win98 == true){return "win98"; return false;}
		if(is_winnt == true){return "winnt"; return false;}
		if(is_win32 == true){return "win32"; return false;}
	}
}

function validateUsername(strString)
{
	var iChars = "`~!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
	
	for (var i = 0; i < strString.length; i++) 
	{
		if (iChars.indexOf(strString.charAt(i)) != -1) 
		{
		//alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
			return false;
		}
	}
	return true;
}


function validateReserveWords(strString)
{
	var myArray = ["admin","webmaster","system","search","email","super","game","test","administrator","consol","contact","help","support","yahoo","gender","male","female","link","machine","technology","agent"];
	for (var i = 0; i < myArray.length; i++) 
	{
		if(strString.toUpperCase() == myArray[i].toUpperCase()) 
		{
			//alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
			return false;
		}
	}
	return true;
}


function validateValgur(strString)
{
	var myArray = ["Sex","Shit","fuck","puSSy","MAD","cunt","nude","naked","asshole","busterd","bastard","cocksucker","porn","dick","Chudi","madarchod","benchod","lund","fakir","chut","chutiya","lauda","bhosda","bully","gand","rand","vaishya","chinal","fodya","penis","vagina","fucker","motherfucker","lier","miser","spy","kutiya","kutta","bhos","bhosad","idiot","stupid","bhadwa"];
	for (var i = 0; i < myArray.length; i++) 
	{
		if(strString.toUpperCase() == myArray[i].toUpperCase()) 
		{
			//alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
			return false;
		}
	}
	return true;
}

//validate image upload file type extensions
//call e.g.	if(!TestFileType(this.frmUploadImg.fileUpload.value, ['gif', 'jpg', 'png', 'jpeg']))
function TestFileType( fileName, fileTypes ) {
	if (!fileName) return;
	
	dots = fileName.split(".")
	
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	//CONVERT FILETYPE IN lower case AS JAVASCRIPT IS CASE SENSITIVE.
	fileType = fileType.toLowerCase();
	//alert(fileType);
	return (fileTypes.join(".").indexOf(fileType) != -1) ? true : false;
}

	function selectdatabasevalue(toselect,cmb) //compares value not text
	{
		for(i=0;i<eval(cmb).length;i++)
		{
			if(eval(cmb).options[i].value.toUpperCase()==toselect.toUpperCase())
			{
				eval(cmb).selectedIndex = i;
			}
		}
	}


function openExit(sPageUrl)
{
	if(window.screenLeft >= 10004)
 	{
		var nwindow = window.open(sPageUrl,'','width=800,height=270');
		nwindow.moveTo(screen.availWidth/2-400,screen.availHeight/2-135);
	}
}

//check date validation
function checkdate(dateField)
{
// ------------- Checking for date in MM/DD/YYYY format ---------------------
	var expirydate="";
	var date="";
	var month="";
	var year="";
	expirydate = dateField;
	month=expirydate.substring(0,expirydate.indexOf("/"));
	date=expirydate.substring((expirydate.indexOf("/")+1),expirydate.indexOf("/",(expirydate.indexOf("/")+2)));
	year=expirydate.substring((expirydate.lastIndexOf("/")+1));
	if(expirydate.indexOf("/")==-1)
	{
		alert("Invalid Date Format");
		return false;
	}

	if(isNaN(date) || isNaN(month) || isNaN(year))
	{
		alert("Enter Date In Numerics Only");
		return false;
	}

	if(date > 31 || date < 1)
	{
		alert("Invalid Date Of Month");
		return false;
	}

	if(month > 12 || month < 1)
	{
		alert("Invalid Month");
		return false;
	}

	if(year < 1850 || year > 5002)
	{
		alert("Invalid Year");
		return false;
	}

	if(month == 4 || month == 6 || month == 9 || month == 11)
	{
		if(date > 30)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}

	if(month == 2)
	{
//----------- checking for leap year-------------
		var lyear=year-1848
		if((lyear%4==0) && (date<30))
		{
			if(date > 29)
			{
				alert("Invalid Date Of Month")
				return false;
			}
			//alert("leap year")
		}
		else if(date > 28)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}
	
	return true;

}
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
function openWin(sURL)
{
	var w;
	var h;
	
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	
	var popW = 500, popH = 400;
	
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	window.open(sURL,'popup','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=1');
}

function ValidateLogin(frmName)
{
	if(trim(eval("document."+frmName).txtEmail.value).length <= 0)
	{
		alert("Enter UserName/Email");
		eval("document."+frmName).txtEmail.focus();
		return false;
	}
	if(trim(eval("document."+frmName).txtPassword.value).length <= 0)
	{
		alert("Enter password");
		eval("document."+frmName).txtPassword.focus();
		return false;
	}
}

function up_launchWM( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;
	window.open( "http://www.tubely.com/chat/wm_ads.php?strDestinationUserID=" + destinationUserID, "WMWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=480,height=597,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_launchUL()
{		
	window.open( "http://www.tubely.com/chat/ul_ads.php" , "ULWindow" , "width=200,height=750,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_replaceAlpha( strIn )
{
	var strOut = "";
	for( var i = 0 ; i < strIn.length ; i++ )
	{
		var cChar = strIn.charAt(i);
		if( ( cChar >= 'A' && cChar <= 'Z' )
			|| ( cChar >= 'a' && cChar <= 'z' )
			|| ( cChar >= '0' && cChar <= '9' ) )
		{
			strOut += cChar;
		}
		else
		{
			strOut += "_";
		}
	}
	
	return strOut;
}
function ajaxobject()
{
	try{
	ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return ajaxRequest;
}
function sendDetails(URL,parameters)
{
	ajaxRequest.open("POST", URL , true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	ajaxRequest.send(parameters);
}
function makepropername(objVal)
{
	var illegalChars = /[^\A-Za-z- ']/; // allow letters, spaces and hyphen
	strng = objVal.value;
	if (illegalChars.test(strng)) 
	{
		return false;
	}
	return true;
}
var staticpath		= 'http://staticcache.tubely.com/';
var imgHome = new Image();
imgHome.src = staticpath + "images/top/icons/home_o.gif";
var imgProfile = new Image();
imgProfile.src = staticpath + "images/top/icons/profile_o.gif";
var imgSearch = new Image();
imgSearch.src = staticpath + "images/top/icons/search_o.gif";
var imgChat = new Image();
imgChat.src = staticpath + "images/top/icons/chat_o.gif";
var imgMessage = new Image();
imgMessage.src = staticpath + "images/top/icons/message_o.gif";
var imgScrap = new Image();
imgScrap.src = staticpath + "images/top/icons/scrap_o.gif";
var imgGame = new Image();
imgGame.src = staticpath + "images/top/icons/games_o.gif";
var imgVideo = new Image();
imgVideo.src = staticpath + "images/top/icons/video_o.gif";

function GetImage(i,s,fname)
{
	if(i == 'h')
	{
		if(s == 'o')
		{
			document.frmLoginTop.home.src=staticpath + 'images/top/icons/home_o.gif';
		}
		else
		{
			if(fname == "/home.php")
			{
				document.frmLoginTop.home.src=staticpath + 'images/top/icons/home_o.gif';
			}
			else
			{
				document.frmLoginTop.home.src=staticpath + 'images/top/icons/home_b.gif';
			}	
		}	
	}
	if(i == 'p')
	{
		if(s == 'o')
		{
			document.frmLoginTop.profile.src=staticpath + 'images/top/icons/profile_o.gif';
		}
		else
		{
			 if(fname == "/profile.php")
			{
				document.frmLoginTop.profile.src=staticpath + 'images/top/icons/profile_o.gif';
			}
			else
			{
				document.frmLoginTop.profile.src=staticpath + 'images/top/icons/profile_b.gif';
			}	
		}	
	}
	if(i == 's')
	{
		if(s == 'o')
		{
			document.frmLoginTop.search.src=staticpath + 'images/top/icons/search_o.gif';
		}
		else
		{
		 if(fname == "/mem_search.php")
			{
				document.frmLoginTop.search.src=staticpath + 'images/top/icons/search_o.gif';
			}
			else
			{
				document.frmLoginTop.search.src=staticpath + 'images/top/icons/search_b.gif';
			}	
		}	
	}
	if(i == 'c')
	{
		if(s == 'o')
		{
			document.frmLoginTop.chat.src=staticpath + 'images/top/icons/chat_o.gif';
		}
		else
		{
			 if(fname == "/wchat/up/chat.php")
			{
				document.frmLoginTop.chat.src=staticpath + 'images/top/icons/chat_o.gif';
			}
			else
			{
				document.frmLoginTop.chat.src=staticpath + 'images/top/icons/chat_b.gif';
			}	
		}	
	}
	if(i == 'm')
	{
		if(s == 'o')
		{
			document.frmLoginTop.message.src=staticpath + 'images/top/icons/message_o.gif';
		}
		else
		{
			 if(fname == "/message.php")
			{
				document.frmLoginTop.message.src=staticpath + 'images/top/icons/message_o.gif';
			}
			else
			{
				document.frmLoginTop.message.src=staticpath + 'images/top/icons/message_b.gif';
			}	
		}	
	}
	if(i == 'sc')
	{
		if(s == 'o')
		{
			document.frmLoginTop.scrap.src=staticpath + 'images/top/icons/scrap_o.gif';
		}
		else
		{
			 if(fname == "/scrap.php")
			{
				document.frmLoginTop.scrap.src=staticpath + 'images/top/icons/scrap_o.gif';
			}
			else
			{
				document.frmLoginTop.scrap.src=staticpath + 'images/top/icons/scrap_b.gif';
			}	
		}	
	}
	if(i == 'g')
	{
		if(s == 'o')
		{
			document.frmLoginTop.game.src=staticpath + 'images/top/icons/games_o.gif';
		}
		else
		{
			 if(fname == "/games/games.php")
			{
				document.frmLoginTop.game.src=staticpath + 'images/top/icons/games_o.gif';
			}
			else
			{
				document.frmLoginTop.game.src=staticpath + 'images/top/icons/games_b.gif';
			}	
		}	
	}
	if(i == 'v')
	{
		if(s == 'o')
		{
			document.frmLoginTop.video.src=staticpath + 'images/top/icons/video_o.gif';
		}
		else
		{
			if(fname == "video")
			{
				document.frmLoginTop.video.src=staticpath + 'images/top/icons/video_o.gif';
			}
			else
			{
				document.frmLoginTop.video.src=staticpath + 'images/top/icons/video_b.gif';
			}	
		}		
	}
			
}
function setImage(fname)
{
	switch(fname)
	{
		case "/home.php":
			document.frmLoginTop.home.src=staticpath + 'images/top/icons/home_o.gif';
		break;
		case "/mem_search.php":
			document.frmLoginTop.search.src=staticpath + 'images/top/icons/search_o.gif';
		break;
		case "/wchat/up/chat.php":
			document.frmLoginTop.chat.src=staticpath + 'images/top/icons/chat_o.gif';
		break;
		case "/message.php":
			document.frmLoginTop.message.src=staticpath + 'images/top/icons/message_o.gif';
		break;
		case "/scrap.php":
			document.frmLoginTop.scrap.src=staticpath + 'images/top/icons/scrap_o.gif';
		break;
		case "/games/games.php":
			document.frmLoginTop.game.src=staticpath + 'images/top/icons/games_o.gif';
		break;
		case "video":
			document.frmLoginTop.video.src=staticpath + 'images/top/icons/video_o.gif';
		break;
	}	
}
var up_cmdURL	= "http://www.tubely.com/chat/cmd.php";
var	main_url	= "http://www.tubely.com/";
moveDiv			= true;
divWidth		= 205;
divHeight		= 120;
NS4=(document.layers);
NS6=(document.getElementById&&!document.all);
IE4=(document.all);
Ypos=0;
Xpos=0;
document.write('<div id="dv_imAlert" style="position:absolute;top:0px;left:0px;width:0px;height:0px;font-family:Arial;font-size:10px;background:#FFFFFF;text-align:center;"></div>');
function imAlert()
{
	if(moveDiv)
	{
		if (NS6)
		{
			Ypos	= window.pageYOffset + window.innerHeight - divHeight - 10;
			Xpos	= window.pageXOffset + window.innerWidth - divWidth*2 - 15;
			document.getElementById("dv_imAlert").style.width	= divWidth;
			document.getElementById("dv_imAlert").style.height	= divHeight;
			document.getElementById("dv_imAlert").style.top		= Ypos + divHeight * Math.sin(-1.045*Math.PI/180);
			document.getElementById("dv_imAlert").style.left	= Xpos-5 + divWidth * Math.cos(-1.045*Math.PI/180);
		}
		if (NS4)
		{
			Ypos	= window.pageYOffset	+ window.innerHeight - divHeight - 20;
			Xpos	= window.pageXOffset	+ window.innerWidth - divWidth - 30;
			document.layers["dv_imAlert"].top		= Ypos*divHeight/4.1*Math.sin(min);
			document.layers["dv_imAlert"].left	= Xpos*divWidth/4.1*Math.cos(min);
		}
		if (IE4)
		{
			Ypos	= document.body.scrollTop + window.document.body.clientHeight - divHeight;
			Xpos	= document.body.scrollLeft + window.document.body.clientWidth - divWidth*2;
			dv_imAlert.style.width			= divWidth;
			dv_imAlert.style.height			= divHeight;
			dv_imAlert.style.pixelTop		= Ypos + divHeight * Math.sin(-1.045*Math.PI/180);
			dv_imAlert.style.pixelLeft		= Xpos + divWidth * Math.cos(-1.045*Math.PI/180);
		}
		setTimeout('imAlert()',100);
	}
}
function clearDiv(m,userid)
{
	moveDiv		= false;
	//eval("document.getElementById('dv_imAlert')").parentNode.removeChild(eval("document.getElementById('dv_imAlert')"));
	if (NS6)
	{
		document.getElementById("dv_imAlert").innerHTML		= "";
		document.getElementById("dv_imAlert").style.width	= "0px";
		document.getElementById("dv_imAlert").style.height	= "0px";
	}
	if (NS4)
	{
		document.layers["dv_imAlert"].width		= "0px";
		document.layers["dv_imAlert"].height	= "0px";
	}
	if (IE4)
	{
		dv_imAlert.innerHTML			= "";
		dv_imAlert.style.width			= "0px";
		dv_imAlert.style.height			= "0px";
	}
	if(m == "y")
	{
		up_launch(userid);
	}
	else
	{
		up_clear(userid,true);
	}
}
function up_launch(_1){
up_ow[_1]=up_ow[_1]==undefined?null:up_ow[_1];
var _2=false;
if(up_ow[_1]!=null){
try{
_2=up_ow[_1].opener==top&&!up_ow[_1].closed;
}
catch(e){
}
}
if(up_ow[_1]==null||!_2){
up_ow[_1]=window.open(up_wmURL+"?strDestinationUserID="+_1+"&ci=1","ICWindow_"+_1,"width=468,height=595,toolbar=0,directories=0,menubar=0,status=1,location=0,scrollbars=0,resizable=1,dependent=1");
if(up_ow[_1]==null)
{
//up_notify(_1);
alert( "Your popup blocker stopped the IM window from a opening" );
}
else{
up_clear(_1,false);
}
}
}
function up_show()
{
	//alert("0");
	var e=document.getElementById("up_nd");
	if(up_la.length > 0)
	{
		//alert("1");
		if(up_uid_display != up_la[0].uid)
		{
			moveDiv		= true;
		//	alert("2");
			if(NS4)
			{
				document.write('<PeelLayer name=ieDigits top=0 left=0 bgcolor=00FFFF clip="0,0,2,2">2132</PeelLayer>');
			}
			else if(IE4 || NS6)
			{
				document.getElementById("dv_imAlert").innerHTML	= '<table width="201" height="118" border="0" cellpadding="0" cellspacing="0" background="'+staticpath+'images/common/chat_alert.jpeg"><tr><td colspan="2" height="28">&nbsp;</td></tr><tr><td align="right" colspan="2" valign="top" style="padding:2px;"><iframe frameborder="0" width="195" height="62" marginheight="0" marginwidth="0" scrolling="no" src="'+main_url+'im_alert.php?userid='+up_la[0].uid+'"></iframe></td></tr><tr><td align="right" style="padding-left:5px;"><a href="" style="background:#FFFFFF;" onClick="javascript:clearDiv(\'y\',\''+up_la[0].uid+'\'); return false;"><img src="'+staticpath+'images/common/chat_accept.jpeg" border="0"></a></td><td align="right"><a style="background:#FFFFFF;" href="" onClick="javascript:clearDiv(\'n\',\''+up_la[0].uid+'\'); return false;"><img src="'+staticpath+'images/common/chat_deny.jpeg" border="0"></a></td></tr></table>';
			}
			up_uid_display	= up_la[0].uid;
			//up_animate(300);
			imAlert();
		}
	}
	else
	{
		up_uid_display="";
		up_animate(-300);
	}
}