// Basic image swap script
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];}
}



// Check functions below.. do we need all of them for new page?

function disableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}
		
		setTimeout('alert("Your form has been submitted.  ")', 2000);
		return true;
	} else {
		alert("The form has been submitted.  Do not click the submit button again.");
		return false;
	}
}
function testdivcreation(arg){
		var newElement =  document.createElement('div');
		newElement.id='newdiv';
		newElement.className="comment";
		newElement.innerHTML= '<a href="#"><strong>' + document.form1.username.value + '</strong>(18 seconds ago)<br/>' + document.getElementById('comment').value + '</a><img src="images/icon_comment_sm.png" alt="sample clip" width="40" height="35" border="0" />';
		document.getElementById('leftColumn').insertBefore(newElement,document.getElementById('firstcomment'));
		document.getElementById("comFrm").style.display = "none";
		document.getElementById('firstcomment').style.display = "none";
		return false;
}

var changeMe = 0;
function showCommFrm(){
	//alert("test");
	if(changeMe ==0){
		document.getElementById("comFrm").style.display = "inline";
		changeMe = 1;
	}else if(changeMe == 1){
		document.getElementById("comFrm").style.display = "none";
		changeMe = 0;
	}
	/*if(changeMe ==0){
		document.getElementById("comFrm").style.display = "inline";
		changeMe = 1;
	}else if(changeMe == 1){
		document.getElementById("comFrm").style.display = "none";
		changeMe = 0;
	}*/
}
var sendMe = 0;
function showEmailFrm(){
	//alert("test");
	if(sendMe ==0){
		document.getElementById("emailFrm").style.display = "inline";
		sendMe = 1;
	}else if(sendMe == 1){
		document.getElementById("emailFrm").style.display = "none";
		sendMe = 0;
	}
}

function clearTxt(str){
	//alert(str);
	//return;
		document.getElementById("to").value ="";
}
function putTxt(){
		document.getElementById("to").value ="Type in Email Here";
}
//  End -->


/*startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;
*/
//google map functions
//<![CDATA[
function showAdd(INTaddress,city, state, zipCode){ 
	var map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();
	var address = INTaddress + ',' + city +',' + state + ',' + zipCode;
	//alert(address);
	//return;
	geocoder.getLatLng(address,
		function(point) {
			//alert(point);
			if (!point) {
				alert(address + " not found");
			} else {
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
			}
		}
	);
}
j=0;
function showMap(){
	if(j==0){
		document.getElementById("mapWrap").style.display="inline";
		j=1;
	}else if(j==1){
		document.getElementById("mapWrap").style.display="none";
		j=0;
	}
}
    //]]>


function hidediv(pass) { 
	var divs = document.getElementsByTagName('div'); 
	for(i=0;i<divs.length;i++){ 
		if(divs[i].id.match(pass)){//if they are 'see' divs 
		
		
		
			if (document.getElementById) // DOM3 = IE5, NS6 
				divs[i].style.visibility="hidden";// show/hide 
			else 
				if (document.layers) // Netscape 4 
					document.layers[divs[i]].display = 'hidden'; 
				else // IE 4 
					document.all.hideshow.divs[i].visibility = 'hidden'; 
		} 
	} 
}


function showdiv(pass) { 
	var divs = document.getElementsByTagName('div'); 
	for(i=0;i<divs.length;i++){ 
		if(divs[i].id.match(pass)){ 
			if (document.getElementById) 
				divs[i].style.visibility="visible"; 
			else 
				if (document.layers) // Netscape 4 
					document.layers[divs[i]].display = 'visible'; 
				else // IE 4 
					document.all.hideshow.divs[i].visibility = 'visible'; 
		} 
	} 
} 

function setfocus() {
	document.login.username.focus();
	return;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//window.name='parentwin';


function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
//alpho started here
function textCont(id){
//snap together id plus the comma
	var newText = "," + id;
//create the string to search through
	var keywords = document.vidInfo.keywords.value;
//search the string for newText
	var checkTxt = keywords.search(newText);
//alert (checkTxt);
//if a match is not found add it to the textarea
		if(checkTxt == -1){
			//alert("Go");
			document.vidInfo.keywords.value = keywords + newText;
/*if it is found don't add to the textarea -1 is the 
value are looking for to trigger the alert,
if found alert the user that it is already there
*/
		}else if(checkTxt != -1){
			alert("Keyword is already included!");
		}
}
//AJAX functions
var xmlHttp
/*--first ajax function--*/
function insertComment(){
	//var insVal = 'userid=' + document.getElementByid('userid').value + '&title=' + document.getElementById('title').value + '&comment=' + document.getElementById('comment').value;
	var insVal = '?cm=2&clipid=' + document.getElementById('clipid').value + '&userid=' + document.getElementById('userid').value + '&title=' + document.getElementById('title').value + '&comment=' + document.getElementById('comment').value;
	//alert(insVal);
	//return;
	xmlHttp = new XMLHttpRequest();
	xmlHttp.open('GET' , 'ajax.php' + insVal , true);
	if (xmlHttp.readyState==4){
		 document.getElementById("testInsert").innerHTML=xmlHttp.responseText;
	}
	xmlHttp.send(null);
}
/*-----second ajax function--------*/
function miniSearch(str){
	if (str.length==0){ 
	  document.getElementById("miniResults").innerHTML="";
	  return;
	}
xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
		var url="ajax.php";
		url=url+"?cm=3&q="+str;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=checkState;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} 

function checkState(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById("miniResults").innerHTML=xmlHttp.responseText;
	}
}
/*--3rd ajax function-----------*/
function showUname(str){
if (str.length==0){ 
  document.getElementById("passHint").innerHTML="";
  return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
  alert ("Your browser does not support AJAX!");
  return;
} 
var url="ajax.php";
url=url+"?cm=1&act=chkpw&pw="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
/*--4th ajax function---------------inserts rating that user clicks*/   
function userSetsRating(clipid,rating){
	
	var insVal = '?cm=4&clipid=' + clipid + '&userid=' + document.getElementById('userid').value + '&rating=' + rating;
	alert(insVal);
	xmlHttp = new XMLHttpRequest();
	xmlHttp.open('GET' , 'ajax.php' + insVal , true);
	//xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.send(null);
}


function stateChanged(){ 
if (xmlHttp.readyState==4){ 
	document.getElementById("passHint").innerHTML=xmlHttp.responseText;
	}
}

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;
}
//end AJAX
function opDiv(){
	//alert('test');
	document.getElementById("logBx").style.display = "inline";
}
function lvDivOp(){
	//alert('Hello');
	document.getElementById("logBx").style.display = "inline";
}
