/*************** START GLOBAL FUNCTIONS ****************/
	
	/* Load content after the page is fully loaded */
	function afterLoad(element_id,content){
			
		var element = document.getElementById(element_id);
		if(element){
			element.innerHTML = content;
		}
	}
	
	/*Enlarge Image*/
      function open_enlarge(name){
      document.getElementById('enlarge').innerHTML = "<img src='images/live/" + name + "' onclick=\"close_enlarge(\'" + name + "\')\">";
      document.getElementById('enlarge').style.display = 'block';
      }
      
    /*Close Enlarge*/
      function close_enlarge(name){
      document.getElementById('enlarge').style.display = '';
      }
      
    /*Display the search box*/
	function display_search(){
		search.style.display = 'block';
	}
	
	/*Close the search box*/
	function close_search(){
		search.style.display = 'none';
	}
	
	/*Change box content*/
	function change_to(box_location,new_box){
		document.getElementById(box_location).innerHTML = document.getElementById(new_box).innerHTML;
	}
	
	function getType(file_name){
		var mySplitResult = file_name.split(".");
		var count_elem = mySplitResult.length-1;
		return mySplitResult[count_elem];
	}
	
/*************** END GLOBAL FUNCTIONS****************/
	
	
/*************** START MAIN PAGE FUNCTIONS ****************/

	/*Minimize the news box*/
	function maximize(box_id,resize,mini,value){
		var new_value = "<span onclick=\"minimize" + "(\'" + box_id + "\',\'" + resize + "\',\'" + mini + "\');\"><a href='#" + box_id + "'>Minimize</a></span>";
		document.getElementById(box_id).style.height="auto";
		document.getElementById(resize).innerHTML = new_value;
	}
	
	/*Maximize the news box*/
	function minimize(box_id,resize,mini){
		var new_value = "<span onclick=\"maximize" + "(\'" + box_id + "\',\'" + resize + "\',\'" + mini + "\');\"><a href='#" + box_id + "'>Maximize</a></span>";
		document.getElementById(box_id).style.height=mini;
		document.getElementById(resize).innerHTML = new_value;
	}
	
	/*top news slide show*/
	var tab=1;
	var t;
	
	/*Change article in top slide show*/
	function change_art(target){
		document.getElementById('top').innerHTML = document.getElementById('a' + target).innerHTML;
		clearTimeout(t);
	}
	
	/*Next button to forward article in top*/
	function next(total){
		if(tab == total){
			tab=1;
		}else{
			tab = tab + 1;
		}
		change_art(tab);
	}
	
	/*Back button to backward article in top*/
	function back(total){
		if(tab <= 1){
			tab=total;
		}else{
			tab = tab - 1;
		}
		change_art(tab);
	}

	/*Top slide show*/
	function slide(total){
	document.getElementById('top').innerHTML = document.getElementById("a" + tab).innerHTML;
	if (tab == total){
	tab = 0;
	}
	t=setTimeout("tab++;slide(" + total + ");", 15000);
	}
	
	/* Flash advertisement random rotation */
	function randOrd(){
      return (Math.round(Math.random())-0.1);
    }

	function ban_rotate(banners)
	{
		anyArray=banners;
		anyArray.sort( randOrd );
		for(i=0;i<anyArray.length;i++)
		{
			if(getType(anyArray[i])=='swf')
			{
				if(anyArray[i]=='rymco_banner.swf')
					document.getElementById('ban'+i).innerHTML="<div style='background-color: transparent; height:80px;width:525px;position:absolute;' onmouseover=\"this.style.cursor='pointer'\" onclick=\"window.open('http://www.rymco.com/leasetoown.php?utm_source=elnashra&utm_medium=banner&utm_campaign=leasetown')\"></div><object type='application/x-shockwave-flash' data='images/ads/rymco_banner.swf' width='525' height='80'><param name='wmode' value='transparent'></object>";
				else
					document.getElementById('ban'+i).innerHTML="<embed src='images/ads/"+anyArray[i]+"'width=525px height=80px>";	
			}
			else if (getType(anyArray[i]) == "jpg" || getType(anyArray[i]) == "gif")
			{
				var getUrl = anyArray[i].split(',');
				if(getUrl[0]=="")
					document.getElementById('ban'+i).innerHTML="<img src='images/ads/"+getUrl[1]+"'width=525px height=80px>";	
				else
					document.getElementById('ban'+i).innerHTML="<a href='"+getUrl[0]+"' target='_blank'><img src='images/ads/"+getUrl[1]+"' width=525 height=80 border=0'></a>";	
			}
			// If the banner is an HTML document (ie: ads server).
			else
				document.getElementById("ban"+i).innerHTML = "<iframe src=\"" + anyArray[i] + "\" style=\"border:0px;margin-bottom:0px;overflow:hidden;\" frameborder=\"0\" scrolling=\"no\" width=\"525\" height=\"80\"></iframe>";
		}
	}
	
/*************** END MAIN PAGE FUNCTIONS ****************/
	

/*************** START AJAX FUNCTIONS ****************/	
	var ajaxRequest;
	function check_browser(){
		try{
			//Opera + firefox + safari
			ajaxRequest = new XMLHttpRequest();
			
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Ajax not supported by browser
					alert("Your browser broke!");
					return false;
				}
			}
		}
	}

	function load_page(link,container,height,width){
	check_browser();
	if(link=='slidear.php' || link=='slidefr.php')
	{
	  var path = link+'?code='+Math.random();
	}
	else
	{
	  var path=link;
	}
	
	ajaxRequest.onreadystatechange = function(){
			if (ajaxRequest.readyState == 1 || ajaxRequest.readyState == 2)
			{
			   document.getElementById(container).innerHTML = "<div class='load' style=\"width:" + width + "px; height:" + height + ";\"><img src = 'template/images/load.gif'></div>";
			}
			if(ajaxRequest.readyState == 4)
			{
				 document.getElementById(container).innerHTML = ajaxRequest.responseText;
			}
	}
	
	ajaxRequest.open("GET",path, true);
	ajaxRequest.send(null); 
}
	
/*************** END AJAX FUNCTIONS ****************/


/*************** START GLOBAL FUNCTIONS ****************/

function popup(width,height,target){
  window.open(target,"Window1","scrollbars=yes,menubar=no,width=" + width + ",height=" + height + ",toolbar=no");
}

function make_visible(id){
  document.getElementById(id).style.display='block';
}

function make_invisible(id){
  document.getElementById(id).style.display='none';
}

function change_src(id,src){
  document.getElementById(id).src=src;
}

function confirm_delete(){
  return confirm("Are you sure you want to delete this entry?");
}

function confirm_task(){
  return confirm("Are you sure you want to perform this operation?");
}

function check_if_empty(ids){
 var id_array=ids;
 for (var i=0; i<id_array.length; i++){
  if(document.getElementById(id_array[i]).value==''){
	alert('Please make sure the required fields are not empty');
	return false;
  }else{
    return true;
   }
  }
}

function display_me(ids){
var to_do=ids;
  for(var i=0; i<to_do.length; i++){
    document.getElementById(to_do[i]).style.display='block';
  }
}
  
function hide_me(ids){
var to_do=ids;
  for(var i=0; i<to_do.length; i++){
    shortcut=document.getElementById(to_do[i]);
	shortcut.style.display='none';
  }
}

function play_audio(container,file_path, file_id){
var box;
var box_value;
 box=document.getElementById(container);
 document.getElementById('audio_box').style.display='block';
 // Increment the file visit counter.
 showHint("audio_stats", file_id, "txtHint2");
 box_value = '<span id="txtHint2"></span><object type="application/x-shockwave-flash" data="./modules/player.swf"  height="24" width="290"><param name="movie" value="modules/player.swf"><param name="FlashVars" value="playerID=1&amp;soundFile='+file_path+'"><param name="wmode" value="transparent"></object>';
 box.innerHTML=box_value;
}

function stop_audio(container){
 document.getElementById('file_info').innerHTML='';
 document.getElementById(container).style.display='none';
}

/*************** END GLOBAL FUNCTIONS ****************/


/************** SPECIAL  FUNCTIONS WITH  SET VALUES ***************/
function count_char(field,counter_field){
    document.getElementById(counter_field).innerHTML=document.getElementById(field).value.length;
  }
  
	// Function to limit the size of the field with a password protection.
  	var limit = 70;
	function checkSizeLimit (id) {
		// If the user needs more space and he's still in the first size prompt for password.
		if ((document.getElementById(id).value.length >= limit) && (limit == 70))
		{
			// Case of correct password - Increase the size limit in JS and in the DOM input field.
			if (prompt ("Please enter your password to enlarge the title field.") == "pazzzword")
			{
				limit = 134;
				document.getElementById(id).setAttribute('maxLength','134');
			}
			// Case of wrong password - truncate the text.
			else
				document.getElementById(id).value = document.getElementById(id).value.substring(0, limit);
		}

	}
  
function GetUnicode(Field)
{     
	var VarConHex1=''
	var VarConHex2='' 
	var VarHex=''
	var VarHex1=''
	var VarHex2=''
	var text1=document.getElementById(Field).value;
	var strLength=document.getElementById(Field).value.length;
	var i 
	var j
	var FirstHeader='000040'
	var SecondHeader='050003C8'
	var Part1=''
	var Part2=''
	var Part1Char=''
	var Part2Char=''
	var PartChar=''
	var VarConHex=''
	if (document.getElementById('to_be_sent').checked==true && strLength <=70)
	{
		for ( i = 0; i < strLength; i++)
		{
		
			if((text1.charCodeAt(i).toString(16).length)==1)
				VarHex="000"+(text1.charCodeAt(i).toString(16))
			else if((text1.charCodeAt(i).toString(16).length)==2)
				VarHex="00"+(text1.charCodeAt(i).toString(16))
			else if((text1.charCodeAt(i).toString(16).length)==3)
				VarHex="0"+(text1.charCodeAt(i).toString(16))
			else
				VarHex=text1.charCodeAt(i).toString(16)
			VarConHex+=VarHex;
		}
		VarConHex=VarConHex.replace('0651','')
                VarConHex=VarConHex.replace('064d','')
                VarConHex=VarConHex.replace('064e','')
                VarConHex=VarConHex.replace('064f','')
 
		document.mainform.unicode_msg.value=VarConHex
	}
	else if(document.getElementById('to_be_sent').checked==true && strLength >70)
	{
		Part1=(text1.substring(0,67))
		Part2=(text1.substring(67))
		for ( j = 0; j < Part1.length; j++)
		{
		       if((Part1.charCodeAt(j).toString(16).length)==1)
				VarHex1="000"+(Part1.charCodeAt(j).toString(16))
			else if((Part1.charCodeAt(j).toString(16).length)==2)
				VarHex1="00"+(Part1.charCodeAt(j).toString(16))
			else if((Part1.charCodeAt(j).toString(16).length)==3)
				VarHex1="0"+(Part1.charCodeAt(j).toString(16))
			else
				VarHex1=Part1.charCodeAt(j).toString(16)
						
			VarConHex1+=VarHex1;
		}
		Part1Char=FirstHeader+SecondHeader+'0201'+VarConHex1
		

		for ( j = 0; j < Part2.length; j++)
		{
		       if((Part2.charCodeAt(j).toString(16).length)==1)
				VarHex2="000"+(Part2.charCodeAt(j).toString(16))
			else if((Part2.charCodeAt(j).toString(16).length)==2)
				VarHex2="00"+(Part2.charCodeAt(j).toString(16))
			else if((Part2.charCodeAt(j).toString(16).length)==3)
				VarHex2="0"+(Part2.charCodeAt(j).toString(16))
			else
				VarHex2=Part2.charCodeAt(j).toString(16)

			VarConHex2+=VarHex2;
		}
		Part2Char=SecondHeader+'0202'+VarConHex2
		PartChar=Part1Char+Part2Char
	document.mainform.unicode_msg.value=PartChar
	}	
}

function check_live(max,field,Password){
var title=document.getElementById(field);
var to_be_sent=document.getElementById('to_be_sent');
  if(to_be_sent.checked==true){
	if(title.value.length > max){
	  if(max=70){
	    if(title.value.length > 70 && title.value.length < 134){
	      name=prompt("Please enter your password to enlarge the title length");
          if (name==Password){
	        title.setAttribute('maxLength','134');
	      }else{
		    to_be_sent.checked=false;
		  }
		}else{
		  to_be_sent.checked=false;
		  alert('Your news it too long, please shorten it to less than 134 characters');
		}
	  }else{
	    if(title.value.length > max){
		  to_be_sent.checked=false;
		  alert('Your news is too long, please shorten it to less than 160 characters');
		}
	  }
	}else{
      title.setAttribute('maxLength',max);
      title.value.length=max;
    }
  }else{
    title.setAttribute('maxLength','');
  }
}

// mobile news page 
function display_code(value){
var value;
 document.getElementById('price_label').innerHTML=value+'$';
}

function verify(){
	document.getElementById('verify_phone').innerHTML=document.getElementById('country_code').value + document.getElementById('phone').value;
}