var current_domain = 'http://www.goodyearselects.com';
// Rollovers
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 MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) {
	  if (targ == "") {
		  eval("window.open('"+selObj.options[selObj.selectedIndex].value+"')");  
	  } else {
		  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");  
	  }
  }
  if (restore) selObj.selectedIndex=0; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Highlighter

function highlight(itemID, over, overBg, overText, outBg, outText) { 
	var theID = itemID;
	if(over == true){
		document.getElementById(theID).style.background = overBg;
		document.getElementById(theID).style.color = overText;
	} else {
		document.getElementById(theID).style.background = outBg;
		document.getElementById(theID).style.color = outText;
	}
}

// Grey Highlighter

function greyHighlight(itemID, over) { 
	var theID = itemID;
	if(over == true){
		document.getElementById(theID).style.background = "#EFEFEF";
		document.getElementById(theID).style.border = "1px";
		document.getElementById(theID).style.borderStyle = "solid";
		document.getElementById(theID).style.borderColor = "#C9C9C9";
	} else {
		document.getElementById(theID).style.background = "#FFFFFF";
		document.getElementById(theID).style.border = "1px";
		document.getElementById(theID).style.borderStyle = "solid";
		document.getElementById(theID).style.borderColor = "#FFFFFF";
	}
}

// AJAX Xml Object

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	 // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
	// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
return xmlHttp;
}

// Verify form fields

function formVerify(fieldID, fieldName, fieldType) {
	var f = document.forms[0];
	document.getElementById(fieldID+'_error').innerHTML='&nbsp;';
	if (fieldType == 'Txt') {
		if (f[fieldID].value == "") {
			document.getElementById(fieldID+'_error').innerHTML = 'Please enter a valid ' + fieldName + '.';
			return false;
		} else {
			document.getElementById(fieldID+'_error').innerHTML = '&nbsp;';
		}
	}
	
	if (fieldType == 'Pwd') {		
		if (f[fieldID].value.length < 6) {
			document.getElementById(fieldID+'_error').innerHTML = 'Your ' + fieldName + ' must have at least 6 characters.';
			return false;
		}	else {
			document.getElementById(fieldID+'_error').innerHTML = '&nbsp;';
		}
	}
	
	if (fieldType == 'PwdV') {
		if (f[fieldID].value != f['password'].value) {
			document.getElementById(fieldID+'_error').innerHTML = 'Your ' + fieldName + ' do not match.';
			return false;
		} else {
			document.getElementById(fieldID+'_error').innerHTML = '&nbsp;';
		}
	}
	
	if (fieldType == 'Sel') {
		if (f[fieldID].selectedIndex == 0) {
			document.getElementById(fieldID+'_error').innerHTML = 'Please choose a ' + fieldName + '.';
			return false;
		} else {
			document.getElementById(fieldID+'_error').innerHTML = '&nbsp;';
		}
	}
	
	return true;
}

// Check username existence and validity

function checkUsername() {
	document.getElementById("username_error").innerHTML='&nbsp;';
	var error = 0;
	var xmlHttp = null;
	xmlHttp=GetXmlHttpObject();
	var url=current_domain+"/admin/inc/_create_user/existing_user.php";
	url=url+"?username="+document.getElementById("username").value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4) { 
			if (xmlHttp.responseText != 'Allow') {
				document.getElementById("username_error").innerHTML=xmlHttp.responseText;
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// AJAX add user

function addUser() {
	document.getElementById("msg_area").innerHTML='&nbsp;';
	var xmlHttp = null;
	xmlHttp=GetXmlHttpObject();
	var page=current_domain+"/admin/inc/_create_user/insert_user.php";
	var url = "username="+document.getElementById("username").value;
	url=url+"&password="+document.getElementById("password").value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",page,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", url.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(url);
	
	function stateChanged() { 
		if (xmlHttp.readyState==4) { 
			if (xmlHttp.responseText.substr(0,1) == '+') {
				document.getElementById("msg_area").style.display = 'block';
				document.getElementById("msg_area").innerHTML = '<span id="warning_msg">' + xmlHttp.responseText + '</span>';
				document.getElementById("username").value = '';
				document.getElementById("password").value = '';
				document.getElementById("password2").value = '';
			} else {
				document.getElementById("msg_area").style.display = 'block';
				document.getElementById("msg_area").innerHTML = '<span id="error_msg">' + xmlHttp.responseText + '</span>';
			}
		}
	}
}

function colorPicker(itemID, over) {
	var theID = itemID;
	if(over == true){
		document.getElementById('colorpicker').style.display = "block";
		document.getElementById('colorpicker').style.left = findPosX(document.getElementById(theID)) + "px";
		document.getElementById('colorpicker').style.top = findPosY(document.getElementById(theID)) + "px";
		document.getElementById('hexBox').value = document.getElementById(theID).value;
		hexBoxChanged();
	} else {
		document.getElementById('colorpicker').style.display = "none";
		document.getElementById(theID).value = document.getElementById('hexBox').value;
		document.getElementById(theID).style.background = document.getElementById('hexBox').value;
		document.getElementById(theID).style.color = document.getElementById('hexBox').value;
	}
}

function changeTheme() {
	var layout = document.getElementById('layout').value;	
	var theme = document.getElementById('theme').value;	
	document.getElementById('samples').src = 'images/samples/' + layout + '_' + theme + '.jpg';
}
