function imagePreloader(){
	var imgs = new Array();
	
	imgs[0] = imagePath + "menu_what_off.jpg";
	imgs[1] = imagePath + "menu_what_on.jpg";
	imgs[2] = imagePath + "menu_action_off.jpg";
	imgs[3] = imagePath + "menu_action_on.jpg";
	imgs[4] = imagePath + "menu_cool_off.jpg";
	imgs[5] = imagePath + "menu_cool_on.jpg";
	imgs[6] = imagePath + "menu_mobile_off.jpg";
	imgs[7] = imagePath + "menu_mobile_on.jpg";
	imgs[8] = imagePath + "menu_download_off.jpg";
	imgs[9] = imagePath + "menu_download_on.jpg";
	imgs[10] = imagePath + "site_bg.jpg";
	
	handle = new Image();
	
	for(i=0;i<imgs.length;i++){
		handle.src = imgs[i];
	}
}

function pause(ms){
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < ms);
} 

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function jumpTo(url){
	parent.location.href = url;
}

function showLogin(){
	var loginWin = document.getElementById("login_window");
	initLogin();
	replaceCheckByID('login_remember');	
	loginWin.style.display = '';
	document.forms["frmLogin"].elements["user"].focus();
}

function showLoginBig(){
	var loginWin = document.getElementById("login_big");
	initLoginBig();
	replaceCheckByID('login_remember');	
	loginWin.style.display = '';
	document.forms["frmLogin"].elements["user"].focus();
}

function initLogin(){
	var loginWin = document.getElementById("login_window");
	loginWin.innerHTML = '<form action="javascript:void();" onsubmit="return doLogin(this);" method="POST" name="frmLogin"><table border="0" cellspacing="2" cellpadding="2" style="padding: 2px; spacing: 2px;"><tr><td>USERNAME:</td><td><input class="text" type="text" name="user" id="login_user" /></td></tr><tr><td>PASSWORD:</td><td><input class="text" type="password" name="pass" id="login_pass" /></td></tr> <tr><td colspan="2"><input class="checkbox" type="checkbox" id="login_remember" name="remember" />&nbsp;&nbsp;<span style="color: #7d7d7d;">REMEMBER ME</span>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="' + basePath + 'reset_password.php">FORGOT PASSWORD?</a></td></tr><tr><td colspan="2" style="height: 5px;"><span style="font-size: 1px;">&nbsp;</span></td></tr><tr><td><span style="cursor: pointer;" onclick="hideLogin();"><img src="' + imagePath + 'close.jpg" style="position: relative; top: 2px;" />&nbsp;&nbsp;CLOSE</span></td><td><input type="image" src="' + imagePath + 'btn_signin.jpg" style="float: right;" /></td></tr></table></form>';
}

function initLoginBig(){
	var loginBig = document.getElementById("login_big");
	loginBig.innerHTML = '<form name="frmBigLogin" onsubmit="return doLogin(this);" action="javascript:void();"><table border="0" cellpadding="0" cellspacing="5"><tr><td>Username:</td><td><input type="text" class="text" name="user" /></td></tr><tr><td>Password:</td><td><input type="password" class="text" name="pass" /></td></tr><tr><td colspan="2"><input class="checkbox" type="checkbox" id="login_remember" name="remember" />&nbsp;&nbsp;<span style="color: #7d7d7d; font-size: 10px;">REMEMBER ME</span>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="' + basePath + 'reset_password.php" style="font-size: 10px;">FORGOT PASSWORD?</a></td><tr><td colspan="2"><div style="width:180px;"><a class="button" onclick="doLogin(document.forms[\'frmBigLogin\']);" >Login</a></div><input type="submit" style="display: none;" /></td></tr></table></form>';
}

function submitOnPress(e){
	var keynum
	var keychar
	var numcheck

	if(window.event) // IE
	{
	keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which
	}
	
	if(keynum == 13)
		doLogin();
}

function doLogin(){
	var msgbox = document.getElementById("msgbox");
	var err=''; //= '<b style="color: red;">Login Error(s):</b><br />';
	var user = document.getElementById('toplogin_user');
	var pass = document.getElementById('toplogin_pass');
	var passph = document.getElementById('toplogin_passph');

	
	var tbwin = document.getElementById("TB_window");
	
	if(tbwin != null && tbwin.style.display == 'block') return false;
	
	//if(tbwin && tbwin.style)
	if(user.value == "guest"){
		err = '<center>Login Error(s):<br /><b style="color: red;">Wrong Username/Password</b><br /><br /><a id="logboxClose" href="javascript:tb_remove();document.getElementById(\'toplogin_user\').focus();">Try Again</a></center><br /><br />';
		user.value = 'username or email';
		pass.style.display = 'none';
		pass.value = '';
		passph.style.display = '';
		msgbox.innerHTML = err;
		tb_show("Error", "#TB_inline?height=200&width=450&inlineId=msgbox", "");
		document.getElementById("logboxClose").focus();
	}else{
		var xmlHttp = new GetXmlHttpObject();
		var url = basePath + "actions.php?act=login&user=" + user.value + "&password=" + pass.value;
		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState == 4){
				if(xmlHttp.status == 200){
					if(document.location.href.indexOf("/forum/") != -1){
						var loc = document.location.href.replace(/#/g, "");
					}else{
						var loc = basePath;
					}
					
					parent.location.href = loc;
					return;
				}else{
					var parts = xmlHttp.responseText.split("♠");
					msgbox.innerHTML = '<center>Login Error(s):<br /><b style="color: red;">' + parts[0] + '</b><br /><br /><a id="logboxClose" href="#" onclick="javascript:tb_remove();">Try Again</a><br />';
					
					user.value = 'username or email';
					user.style.color = '#ABABAB';
					pass.style.display = 'none';
					pass.value = '';
					passph.style.display = '';
					
					
					tb_show("Error", "#TB_inline?height=200&width=450&inlineId=msgbox&modal=true", "")
					
					document.getElementById("logboxClose").focus();
				}
			}
		}
	}
	return false;
}

function doLogout(){
	var url = basePath + "actions.php?act=logout";
	var xmlHttp = new GetXmlHttpObject();
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
			if(document.location.href.indexOf("/forum/") != -1){
				var loc = document.location.href.replace(/#/g, "");
			}else{
				var loc = basePath;
			}
			
			parent.location.href = loc;
		}
	}
}

function guestLogin(){
	var xmlHttp = new GetXmlHttpObject();
	var url = basePath + "actions.php?act=login&user=guest&password=guest";
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				parent.location.href = 'http://webplayer.jukata.com';
			}else{
				alert("Can't launch guest web player!");
			}
		}
	}
}

function hideLogin(){
	var loginWin = document.getElementById("login_window");
	loginWin.style.display = 'none';
	
}

function loadMainContent(type){
	var types = new Array("whatisjuk","jukinaction","whatelse","jukmobile","downloads");
	
	for(i=0;i<types.length;i++){
		if(type == types[i]){
			document.getElementById("menu-" + types[i]).src = imagePath + "menu_" + types[i] + "_on.jpg";	
			document.getElementById("content-" + types[i]).style.display = '';
		}else{
			document.getElementById("menu-" + types[i]).src = imagePath + "menu_" + types[i] + "_off.jpg";
			document.getElementById("content-" + types[i]).style.display = 'none';
		}
	}
}

function companyScroll(direction){
	var comps = document.getElementById("main_companyscroll");
	var interval = 25;
	var max = -260;
	var larrow = document.getElementById("what_leftarrow");
	var rarrow = document.getElementById("what_rightarrow");
	
	if(comps.style.left == "") comps.style.left = "0px";
	curPosition = parseInt(comps.style.left);
	
	larrow.src = imagePath + "left_arrow.png";
	rarrow.src = imagePath + "right_arrow.png";
	
	if(direction == 0){		
		if(curPosition + interval >= 0){
			comps.style.left = "0px";
			larrow.src = imagePath + "left_arrow_off.png";
		}else if(curPosition + interval < 0){
			curPosition += interval;
			comps.style.left = curPosition + "px";
		}
	}else if(direction == 1){
		if(curPosition - interval < max){
			rarrow.src = imagePath + "right_arrow_off.png";
			comps.style.left = max + "px";
		}else if(curPosition - interval > max){
			curPosition -= interval;
			comps.style.left = curPosition + "px";
		}
	}
}


function phoneScroll(direction){
	var comps = document.getElementById("main_phonescroll");
	var interval = 20;
	
	
	var larrow = document.getElementById("phones_leftarrow");
	var rarrow = document.getElementById("phones_rightarrow");
	
	if(max_phone_scroll == 0){
		larrow.src = imagePath + "left_arrow_off.png";
		rarrow.src = imagePath + "right_arrow_off.png";
		return;
	}
	
	if(comps.style.left == "") comps.style.left = "0px";
	curPosition = parseInt(comps.style.left);
	
	larrow.src = imagePath + "left_arrow.png";
	rarrow.src = imagePath + "right_arrow.png";
	
	if(direction == 0){
		if(curPosition + interval >= 0){
			comps.style.left = "0px";
			larrow.src = imagePath + "left_arrow_off.png";
		}else if(curPosition + interval < 0){
			curPosition += interval;
			comps.style.left = curPosition + "px";
		}
	}else if(direction == 1){
		if(curPosition - interval <= max_phone_scroll){
			comps.style.left = max_phone_scroll + "px";
			rarrow.src = imagePath + "right_arrow_off.png";
		}else if(curPosition - interval > max_phone_scroll){
			curPosition -= interval;
			comps.style.left = curPosition + "px";
		}
	}
}

function reCAPTCHA(){
	var d = new Date();
	
	var input 	= document.getElementById("captcha");
	var img 	= document.getElementById("imgCaptcha");
	
	img.src = appPath + "moc/_includes/captcha.php?" + d.getTime();
	input.value = '';
	input.focus();
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}


function submitRegister(){
	var form = document.forms["register"];
	
	if(form.elements["password"].value != form.elements["password2"].value){
		alert("Password does not match verification!");
		return false;
	}else if(!form.elements["tos"].checked){
		alert("Please read and accept the Jukata Terms of Service and Privacy Policy before proceeding!");
		return false;
	}else{
		form.submit();
	}
}

function submitDownload(){
	parent.location.href = itunesAgentURL;
	/*var frm = document.forms["download"];
	var email = frm.elements["email"].value;
	var offers = (frm.elements["sub_offers"].checked)?"true":"false";
	var news = (frm.elements["sub_news"].checked)?"true":"false";
	
	if(validateEmail(email)){
		var url = basePath + "actions.php?act=subscribe&email=" + email + "&offers=" + offers + "&news=" + news;
		var xmlHttp = new GetXmlHttpObject();
		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
				if(xmlHttp.responseText != "OK"){
					alert("You are already subscribed with this e-mail address, the file will be downloaded anyways")
				}
				
			}
		}
	}else{
		parent.location.href = itunesAgentURL;
	}
	*/
}

function inactionSwitchTo(name){
	var names = new Array("agent","web","mobile");
	
	
	for(i=0;i<3;i++){
		if(names[i] == name){
			document.getElementById("inaction_btn_" + names[i]).src = imagePath + "inaction_" + names[i] + "_on.png";
			//document.getElementById("inaction_content_" + names[i]).style.display = '';
			document.getElementById("inaction_vid_" + names[i]).style.display = '';
		}else{
			document.getElementById("inaction_btn_" + names[i]).src = imagePath + "inaction_" + names[i] + "_off.png";
			//document.getElementById("inaction_content_" + names[i]).style.display = 'none';
			document.getElementById("inaction_vid_" + names[i]).style.display = 'none';
		}
	}
}

var max_phone_scroll = -500;

function loadPhoneScroll(id,operator){
	var opid = 1;
	var op = null
	while ((op = document.getElementById('operator'+opid++)) != null)
	{
		op.setAttribute("class","operator_logo");
	}
	var selected_op = document.getElementById(id);
	selected_op.setAttribute("class","operator_logo_selected");

	var table = document.getElementById("phoneTable");
	var scroll = document.getElementById("phoneScroller");
	var xmlHttp = new GetXmlHttpObject();
	var url	= basePath + "actions.php?act=get_operator_phones&operator=" + operator;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
			var larrow = document.getElementById("phones_leftarrow");
			var rarrow = document.getElementById("phones_rightarrow");
			larrow.src = imagePath + "left_arrow_off.png";
			rarrow.src = imagePath + "right_arrow.png";
			scroll.innerHTML = xmlHttp.responseText;
			table.style.display = '';
			switch (operator)
			{
				case "cellular_south":
					max_phone_scroll=-900;
					break;
				case "ntelos":
					max_phone_scroll=-700;
					break;
				case "cricket":
					max_phone_scroll=-600;
					break;
				case "bms":
					max_phone_scroll=-900;
					break;
			}
		}
	}
	
}

function loadSupportPhoneScroll(operator){
	var table = document.getElementById("phoneTable");
	var scroll = document.getElementById("phoneScroller");
	var xmlHttp = new GetXmlHttpObject();
	var url	= basePath + "actions.php?act=get_operator_phones&mode=support&operator=" + operator;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
			var larrow = document.getElementById("phones_leftarrow");
			var rarrow = document.getElementById("phones_rightarrow");
			larrow.src = imagePath + "left_arrow_off.png";
			rarrow.src = imagePath + "right_arrow.png";
			scroll.innerHTML = xmlHttp.responseText;
			table.style.display = '';
		}
	}
	
}

function validateUser(e){
	var img = document.getElementById("user_tester");
	if(e.value.trim().length == 0)
		img.src = imagePath + "spacer.gif";
	else if(e.value.trim().length < 5)
		img.src = imagePath + "icn_x.png";
	else{
		var xmlHttp = GetXmlHttpObject();
		var url = basePath + "actions.php?act=validateuser&user=" + e.value.trim();
		img.src = imagePath + "loader_small.gif";
		
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
				if(xmlHttp.responseText.trim() == "OK")
					img.src = imagePath + "icn_v.png";
				else
					img.src = imagePath + "icn_x.png";
			}
		}
	}
}

function validateRegMail(e){
	var img = document.getElementById("email_tester");
	if(e.value.trim().length == 0)
		img.src = imagePath + "spacer.gif";
	else{
		var xmlHttp = GetXmlHttpObject();
		var url = basePath + "actions.php?act=validateemail&email=" + e.value.trim();
		
		img.src = imagePath + "loader_small.gif";
		
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
				if(xmlHttp.responseText.trim() == "OK")
					img.src = imagePath + "icn_v.png";
				else
					img.src = imagePath + "icn_x.png";
			}
		}
	}
}

function validatePasswords(){
	var pw1tester = document.getElementById("pw1_tester");
	var pw2tester = document.getElementById("pw2_tester");
	
	var pw1 = document.getElementById("password");
	var pw2 = document.getElementById("password2");
	
	if(pw1.value.trim().length > 0 && pw2.value.trim().length > 0){
		if(pw1.value.trim() != pw2.value.trim()){
			pw1tester.src = imagePath + "icn_x.png";
			pw2tester.src = imagePath + "icn_x.png";
		}else{
			pw1tester.src = imagePath + "icn_v.png";
			pw2tester.src = imagePath + "icn_v.png";
		}
	}else{
		pw1tester.src = imagePath + "spacer.gif";
		pw2tester.src = imagePath + "spacer.gif";
	}
}

function validateEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   
   return reg.test(address);
}


function switchImage(objName, src){
	document.getElementById(objName).src = src;
}

function divShow(div){
	document.getElementById(div).style.display = 'block';
}

function divHide(div){
	document.getElementById(div).style.display = 'none';	
}

function divToggle(div){
	if(document.getElementById(div).style.display == 'none'){
		divShow(div);
	}else{
		divHide(div);
	}	
}

var track_gallery_xml_request = false;
var track_gallery_xsl_request = false;

function launchWebPlayer(){
	window.open(basePath + "welcome.php");
}

function openWindow()
{
	window.open('http://www.google.com');
	alert('im here2');
}

function onGalleryFileLoaded()
{
	document.getElementById("mainblock2").innerHTML='';
	if (
		(track_gallery_xml_request && track_gallery_xml_request.readyState == 4 && track_gallery_xml_request.status == 200)
		&&
		(track_gallery_xsl_request && track_gallery_xsl_request.readyState == 4 && track_gallery_xsl_request.status == 200)
		)
	{
		if (window.ActiveXObject)
		{
			var xsl=new ActiveXObject("Microsoft.XMLDOM");
			xsl.loadXML(track_gallery_xsl_request.responseXML.xml);
			var xml=new ActiveXObject("Microsoft.XMLDOM");
			xml.loadXML(track_gallery_xml_request.responseXML.xml);
			ex=xml.transformNode(xsl);
			document.getElementById("mainblock2").innerHTML=ex;
		}
		// code for Mozilla, Firefox, Opera, etc.
		else if (document.implementation && document.implementation.createDocument)
		{
			xsltProcessor=new XSLTProcessor();
			xsltProcessor.importStylesheet(track_gallery_xsl_request.responseXML);
			resultDocument = xsltProcessor.transformToFragment(track_gallery_xml_request.responseXML,document);
			document.getElementById("mainblock2").appendChild(resultDocument);
		}
	}
}



function getXmlHttpObj()
{
   if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			return new XMLHttpRequest();
        } catch(e) {
			return false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	return new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		return new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		return false;
        	}
		}
    }
}



function loadXMLDoc(url,req) {
	// branch for native XMLHttpRequest object
 	if(req) {
		req.onreadystatechange = onGalleryFileLoaded;
		req.open("GET", url, true);
		req.send("");
	}
}

function loadFileToDiv(file,divid){
	var target = document.getElementById(divid);
	var xmlHttp = new GetXmlHttpObject();
	
	target.innerHTML = '<center><p></p><p></p><img src="' + basePath + 'images/loader.gif" /><br /><b>Loading ...</b></center>';
	
	xmlHttp.open("GET", file, true);
	xmlHttp.send(null);
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
			target.innerHTML = xmlHttp.responseText;
		}
	}
}

function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode != 9){
		if (unicode<48||unicode>57) return false ;
	}
}
