var imageShown = false;

 function slideDiv(id){
 	element = $(id);
 	new Effect.toggle(element.id, 'slide', {duration:1, toggle:true});
 }
 
 function hideOnTimer(id){
 	setTimeout('clearDiv("'+id+'")', 3000);
 }

function isPhoneNumber(phone){
	regphone = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/i;
	return regphone.test(phone);
}

function format_phone(field_id){
	// Attempt to auto-format basic US phone numbers.  This method supports
	// 7 and 10 digit numbers.  Example: (410) 555-1212
	// Get the field that fired the event
	var oField = document.getElementById(field_id);
	// If we have the field and all is well
	if (typeof(oField) != "undefined" && oField != null){
		// Remove any non-numeric characters
		var sTmp = oField.value.replace(/[^0-9]/g, "");
		// If the number is a length we expect and support, format the number
		if(sTmp.length<10){
			document.getElementById(field_id + "err").innerHTML = "Invalid Phone";
			return;
		}
		//strip any preceeding 1's
		if(sTmp.indexOf('1')==0){
			sTmp = sTmp.substr(1);
		}
		switch (sTmp.length){
			/*case "14105551212".length:
				oField.value = sTmp.substr(0,1) + "(" + sTmp.substr(1, 3) + ") " + sTmp.substr(4, 3) + "-" + sTmp.substr(7, 4);
				document.getElementById(field_id + "err").innerHTML = "";
				break;*/
			case "4105551212".length:
				oField.value = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
				document.getElementById(field_id + "err").innerHTML = "";				
				break;
			default:
				oField.value = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4) + " ext " + sTmp.substr(10, sTmp.length-10);
				document.getElementById(field_id + "err").innerHTML = "";				
				break;
		}
	}
}


function isValidEmail(anEmail){
	//will check for valid email based on a passed value
	regEmail = /^[A-Za-z0-9\-_]+(\.[A-Za-z0-9\-_]+)*@([A-Za-z0-9\-_\.]+\.)+[A-Za-z]{2,3}$/i;
	return regEmail.test(anEmail);
}

function hideDiv(divid){
	var tdiv = document.getElementById(divid);
	tdiv.style.display='none';
}

function showDiv(divid){
	var tdiv = document.getElementById(divid);
	tdiv.style.display='block';
}

function toggleDiv(id){
	var targ = document.getElementById(id);
	if(targ.style.display=='none'){
		targ.style.display='block';
	}else{
		targ.style.display='none';
	}
}

function clearDiv(id){
	document.getElementById(id).innerHTML = "";
}

function setDiv(id,content){
	document.getElementById(id).innerHTML = content;
}

function setClass(id,content){
	document.getElementById(id).className = content;
}

function setImage(id,img){
	document.getElementById(id).src = '/uploads/gallery/'+img;	
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function highlightElement(element_id){
	//get element sizes
	if(document.getElementById('highligh_div_'+element_id)==null){
		var width = getElementWidth(element_id);
		var height = getElementHeight(element_id);
		var top = getElementTop(element_id);
		var left = getElementLeft(element_id);
		//drawdiv
		var newdiv = document.createElement('div');
		var divIdName = 'highligh_div_'+element_id;
		newdiv.setAttribute('id',divIdName);
		newdiv.style.width = width + "px";
		newdiv.style.height = height + "px";
		newdiv.style.top = top + "px";
		newdiv.style.left = left + "px";
		newdiv.style.opacity = .3;
		newdiv.style.position = 'absolute';
		newdiv.innerHTML="&nbsp;";
		newdiv.style.filter = 'alpha(opacity=30)';
		newdiv.style.background = '#FFFCCC';
		newdiv.style.zIndex = '18';
		newdiv.onMouseOut = "unhighlight('" + element_id + "')";
		document.body.appendChild(newdiv);
	}
}

function unhighlight(element_id){
	element = document.getElementById('highligh_div_'+element_id);
	
	if(element!=null){
		document.body.removeChild(element);
	}else{
		alert ('false');
	}
}


/***********************************************
* Dynamic Ajax Content- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var page_request = false

function ajaxLink(url, containerid, commands, no_jump){
	loading(containerid);
	/* fetches url, inserts response into container element,
	then runs commands. */
	new Ajax.Updater(containerid,url, {
	  evalScripts: true,
	  onComplete : function(transport){
	  	after_comp(containerid, commands, no_jump);
	  }
	});
}

function loading(containerid){
	setDiv(containerid,'<img src="/img/loading.gif"><b>loading... please wait...</b>');	
}
function ajaxPOST(url, postString, containerId, command, no_jump){
	/* posts url, inserts response into container element,
	then runs command */	
	new Ajax.Updater(containerId, url, {
		method:'post',
		parameters:postString,	  
		evalScripts: true,
		onComplete: function(transport){
		  	aftercomp(containerId, command, no_jump)
	  	}
	});
}

function repositionDiv(){
	if(objs.style.display == 'none' || objs.style.display == '' || objs.style.display == 'undefined'){
		return;
	}
	var objs = document.getElementById(id);
	var obj2 = document.getElementById('fade-out');
	var width = getViewportSize("width");
	var height = getViewportSize("height");
	posleft = (width/2) - 250;
	postop = (height/2) - 250;
	if(posleft < 0) posleft = 0;
	if(postop < 0) postop = 0;
	objs.style.left = posleft + 'px';
	objs.style.top = postop + 'px';
	objs.style.display = 'block';
	//obj2.style.display = 'block';
	return true;
}

function positionDiv(id) {
	var objs = document.getElementById(id);
	var obj2 = document.getElementById('fade-out');
	var width = getViewportSize("width");
	var height = getViewportSize("height");
	posleft = (width/2) - 250;
	postop = (height/2) - 250;
	if(posleft < 0) posleft = 0;
	if(postop < 0) postop = 0;
	objs.style.left = posleft + 'px';
	objs.style.top = postop + 'px';
	objs.style.display = 'block';
	//obj2.style.display = 'block';
	return true;
}


/***********************************************
* Dynamic Ajax Post/Get Requests
* 
*
***********************************************/

//var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
  	try{
  		var http_request = new XMLHttpRequest();
  	}catch (err){}
     //http_request.overrideMimeType('text/html');
  } else if (window.ActiveXObject) { // IE <7
     try { 
     	var http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
     } 
     catch (e) { 
     	try 
     	{ 
     		var http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
     	} 
     	catch (e) 
     	{} 
     }
  }
  
function makePOSTRequest(url, parameters) {	
  if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; }
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function makeGETRequest(url) {
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
     try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} }
  }
  if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; }
  http_request.open('GET', url, true);
  http_request.send(null);
}

function ajaxSubmit(obj, page){
	//ajax submit to be used from other js functions
	var str = getChildInputValues(obj);
	makePOSTRequest(page, str);
	return http_request
}

function sendAjaxSubmit(formid, submitPage, containerid, no_jump, commands){
	//submit form and echo response to page
	var str = getChildInputValues($(formid));
	return ajaxPOST(submitPage, str, containerid, commands, no_jump);

}

function ajaxPostCommand(url, postString, command){
	//submit form and run command(responseText)
	makePOSTRequest(url, postString);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			try{ command(http_request.responseText); }
			catch(err){
			}
		}
	}
}


function getChildInputValues(obj){
	var str = "";
	var inputs = obj.getElementsByTagName("INPUT");
	var selects = obj.getElementsByTagName("SELECT");
	var textareas = obj.getElementsByTagName("TEXTAREA");
if(inputs.length>0){
		for (var i = 0; i < inputs.length; i++){
			if (inputs[i].type == "text" || inputs[i].type == "password" || inputs[i].type == "hidden" || inputs[i].type=="file") {
				str += inputs[i].name + "=" + escape(inputs[i].value) + "&";
			}
			if (inputs[i].type == "checkbox") {
				if (inputs[i].checked) {
					str += inputs[i].name + "=" + escape(inputs[i].value) + "&";
				} else {
					str += inputs[i].name + "=&";
				}
			}
			if (inputs[i].type == "radio") {
				if (inputs[i].checked) {
					str += inputs[i].name + "=" + escape(inputs[i].value) + "&";
				}
			}
		}
	}
	
	if(selects.length>0){
		//check if mutiples can be selected
		for (var i = 0; i < selects.length; i++){
			var tempstring = "";
			if(selects[i].multiple){
				//if ($(selects[i]).hasClassName('right_select')) {
				if(document.getElementById('pseudo_'+selects[i].id)){
					// element is part of a multi-select compound widget, 
					// use every item for submission:
					for (var j=0; j<selects[i].options.length; j++){
						//alert( selects[i].options[j].value);
						str += selects[i].name + "=" + escape(selects[i].options[j].value) + "&";
    				}
				}else{
					while (selects[i].selectedIndex != -1) { 
						str += selects[i].name + "=" + escape(selects[i].value) + "&";
						selects[i].options[selects[i].selectedIndex].selected = false;
					}
				}
				
			}else{
				str += selects[i].name + "=" + selects[i].value + "&";
			}
		}
	}
	if(textareas.length>0){
		for (var i = 0; i < textareas.length; i++){
			str += textareas[i].name + "=" + escape(textareas[i].value) + "&";
		}
	}
	return str;
}

 function hideOnTimer(id){
 	setTimeout('clearDiv("'+id+'")', 5000);
 }
 
 function clearDiv(id){
	document.getElementById(id).innerHTML = "";
}
 
 
 
 
 // F. Permadi 2005.
// Highlights table row
// Copyright (C) F. Permadi
// This code is provided "as is" and without warranty of any kind.  Use at your own risk.



// These variables are for saving the original background colors
var savedStates=new Array();
var savedStateCount=0;

/////////////////////////////////////////////////////
// This function takes an element as a parameter and 
//   returns an object which contain the saved state
//   of the element's background color.
/////////////////////////////////////////////////////
function saveBackgroundStyle(myElement)
{
  saved=new Object();
  saved.element=myElement;
  saved.className=myElement.className;
  saved.backgroundColor=myElement.style["backgroundColor"];
  return saved;   
}

/////////////////////////////////////////////////////
// This function takes an element as a parameter and 
//   returns an object which contain the saved state
//   of the element's background color.
/////////////////////////////////////////////////////
function restoreBackgroundStyle(savedState)
{
  savedState.element.style["backgroundColor"]=savedState.backgroundColor;
  if (savedState.className)
  {
    savedState.element.className=savedState.className;    
  }
}

/////////////////////////////////////////////////////
// This function is used by highlightTableRow() to find table cells (TD) node
/////////////////////////////////////////////////////
function findNode(startingNode, tagName)
{
  // on Firefox, the TD node might not be the firstChild node of the TR node
  myElement=startingNode;
  var i=0;
  while (myElement && (!myElement.tagName || (myElement.tagName && myElement.tagName!=tagName)))
  {
    myElement=startingNode.childNodes[i];
    i++;
  }  
  if (myElement && myElement.tagName && myElement.tagName==tagName)
  {
    return myElement;
  }
  // on IE, the TD node might be the firstChild node of the TR node  
  else if (startingNode.firstChild)
    return findNode(startingNode.firstChild, tagName);
  return 0;
}

/////////////////////////////////////////////////////
// Highlight table row.
// newElement could be any element nested inside the table
// highlightColor is the color of the highlight
/////////////////////////////////////////////////////
function highlightTableRow(myElement, highlightColor)
{
  var i=0;
  // Restore color of the previously highlighted row
  for (i; i<savedStateCount; i++)
  {
    restoreBackgroundStyle(savedStates[i]);          
  }
  savedStateCount=0;

  // To get the node to the row (ie: the <TR> element), 
  // we need to traverse the parent nodes until we get a row element (TR)
  // Netscape has a weird node (if the mouse is over a text object, then there's no tagName
  while (myElement && ((myElement.tagName && myElement.tagName!="TR") || !myElement.tagName))
  {
    myElement=myElement.parentNode;
  }

  // If you don't want a particular row to be highlighted, set it's id to "header"
  // If you don't want a particular row to be highlighted, set it's id to "header"
  if (!myElement || (myElement && myElement.id && myElement.id=="header") )
    return;
		  
  // Highlight every cell on the row
  if (myElement)
  {
    var tableRow=myElement;
    
    // Save the backgroundColor style OR the style class of the row (if defined)
    if (tableRow)
    {
	  savedStates[savedStateCount]=saveBackgroundStyle(tableRow);
      savedStateCount++;
    }

    // myElement is a <TR>, then find the first TD
    var tableCell=findNode(myElement, "TD");    

    var i=0;
    // Loop through every sibling (a sibling of a cell should be a cell)
    // We then highlight every siblings
    while (tableCell)
    {
      // Make sure it's actually a cell (a TD)
      if (tableCell.tagName=="TD")
      {
        // If no style has been assigned, assign it, otherwise Netscape will 
        // behave weird.
        if (!tableCell.style)
        {
          tableCell.style={};
        }
        else
        {
          savedStates[savedStateCount]=saveBackgroundStyle(tableCell);        
          savedStateCount++;
        }
        // Assign the highlight color
        tableCell.style["backgroundColor"]=highlightColor;

        // Optional: alter cursor
        tableCell.style.cursor='default';
        i++;
      }
      // Go to the next cell in the row
      tableCell=tableCell.nextSibling;
    }
  }
}

/////////////////////////////////////////////////////
// This function is to be assigned to a <table> mouse event handler.
// If the element that fired the event is within a table row,
//   this function will highlight the row.
/////////////////////////////////////////////////////
function trackTableHighlight(mEvent, highlightColor)
{
  if (!mEvent)
    mEvent=window.event;
		
  // Internet Explorer
  if (mEvent.srcElement)
  {
    highlightTableRow( mEvent.srcElement, highlightColor);
  }
  // Netscape and Firefox
  else if (mEvent.target)
  {
    highlightTableRow( mEvent.target, highlightColor);		
  }
}

/////////////////////////////////////////////////////
// Highlight table row.
// newElement could be any element nested inside the table
// highlightColor is the color of the highlight
/////////////////////////////////////////////////////
function highlightTableRowVersionA(myElement, highlightColor)
{
  var i=0;
  // Restore color of the previously highlighted row
  for (i; i<savedStateCount; i++)
  {
    restoreBackgroundStyle(savedStates[i]);          
  }
  savedStateCount=0;

  // If you don't want a particular row to be highlighted, set it's id to "header"
  if (!myElement || (myElement && myElement.id && myElement.id=="header") )
    return;
		  
  // Highlight every cell on the row
  if (myElement)
  {
    var tableRow=myElement;
    
    // Save the backgroundColor style OR the style class of the row (if defined)
    if (tableRow)
    {
	  savedStates[savedStateCount]=saveBackgroundStyle(tableRow);
      savedStateCount++;
    }

    // myElement is a <TR>, then find the first TD
    var tableCell=findNode(myElement, "TD");    

    var i=0;
    // Loop through every sibling (a sibling of a cell should be a cell)
    // We then highlight every siblings
    while (tableCell)
    {
      // Make sure it's actually a cell (a TD)
      if (tableCell.tagName=="TD")
      {
        // If no style has been assigned, assign it, otherwise Netscape will 
        // behave weird.
        if (!tableCell.style)
        {
          tableCell.style={};
        }
        else
        {
          savedStates[savedStateCount]=saveBackgroundStyle(tableCell);        
          savedStateCount++;
        }
        // Assign the highlight color
        tableCell.style["backgroundColor"]=highlightColor;

        // Optional: alter cursor
        tableCell.style.cursor='default';
        i++;
      }
      // Go to the next cell in the row
      tableCell=tableCell.nextSibling;
    }
  }
}


function showImgLink(val){
/*	switch(val)
	{
		case 1:
			showDiv('top_bnr');
		break;
		case 2:
			showDiv('inline_bnr');
		break;
		
		default:
			showDiv('corner_bnr');
		
	}*/
	
	showDiv('adv_file');
	$("ad_type").value=val;
}

//---------------------------------------------------------
//         RESIZE OBJECT
//---------------------------------------------------------
function resizeObj(id,w,h){
	/*var h=document.body.clientHeight;
	var w=document.body.clientWidth;*/
	//alert("height:"+h+" width:"+w +" id "+id);
	document.getElementById(id).style.height=h;
	document.getElementById(id).style.width=w;
}

function resizePlayer(w,h){
	/*var h=document.body.clientHeight;
	var w=document.body.clientWidth;*/
	//alert("height:"+h+" width:"+w +" id "+id);
	document.getElementById("MediaPlayer").style.height=h;
	document.getElementById("MediaPlayer").style.width=w;
	document.getElementById("embed_obj").style.height=h;
	document.getElementById("embed_obj").style.width=w;
}






