function doeval(js){
	if(js!=null){
	var sc = document.createElement('script');
	jsCode = js;
	sc.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(sc);
	sc.text = 'try{eval(jsCode);}catch(e){}jsCode="";';
	//sc.text = 'try{eval(jsCode);}catch(e){try{alert(e.fileName+" : "+e.lineNumber+"\\n"+e.name+" : "+e.message); alert(e.stack);}catch(e){}}jsCode="";';
	sc.text = "\/\/ :-)";
	}
}

function getscript(str){
let_out=str;
	jstr=let_out.split('<script>');
	if( jstr[1] !=null){
		newstr=jstr[1].split('</script>');
		if( newstr[1] !=null){
			setTimeout("doeval( newstr[0] )", 500);
		}
	}


return let_out;
}



function HAM3D_block_loader(page,this_block,post){
if(page!='HAM3D_article_category'){if(get_div_value_for_ajax('HAM3D_category_status')==1){hide_id('HAM3D_category');hide_id('HAM3D_category_status');}}
main_ajax_do(page+'.php',this_block,post);		
}

function flash_header_loader(page,this_block,post){
main_ajax_do('flash_link.php','main_part',post);		
}

function ham3d_search(){
         
    ham3d=get_value_for_ajax('ham3d_search');	
	if (ham3d == '')
		{
			write_in_id('ham3d_net_place_block_search_error' ,'Empty!')
		}
		else
		{	
			main_ajax_do('search.php', 'main_part', 'ham3dsearch='+ham3d+'')
		}
}
function image_show_loader(page,this_block,post){
main_ajax_do(page+'.php','gallery_show',post);		
}

function show_id(id){
    if(document.getElementById(id)){
    	document.getElementById(id).style.display ='';
	}
}

function write_in_id(id,note){
 	if(document.getElementById(id)){
  		show_id(id);
 		document.getElementById(id).innerHTML=note;
	}
}

function hide_id(id){
    if(document.getElementById(id)){
		document.getElementById(id).style.display ='none';
	}
}

function HAM3D_hide_id_check(id){
	document.getElementById('HAM3D_category_status').innerHTML=1;
    if(document.getElementById(id)){
		document.getElementById(id).style.display ='none';
	}
	hide_id('HAM3D_main2');
}

function write_in_blank_id(id){
 	if(document.getElementById(id)){
  		show_id(id);
 		document.getElementById(id).innerHTML=' ';
	}
}
function get_value_for_ajax(this_id){
	if(! document.getElementById(this_id) ){
		return '';
	}else if(document.getElementById(this_id).type == 'checkbox'){
        return document.getElementById(this_id).checked;	
	}else{
        return encodeURIComponent(replace_for_ajax(document.getElementById(this_id).value));
	}
}

function get_div_value_for_ajax ( id ){
	return encodeURIComponent(document.getElementById(id).innerHTML);
}
function replace_for_ajax(note){
	note= note.replace(/&/g,"**am**");
	note= note.replace(/=/g,"**mosavi**");
	note= note.replace(/\+/g,"**jam**");
	return note;
}

//--------------------------------------------------------------------

function loading_effect(k){
	ht = document.getElementsByTagName("html");
	if(k==1){
	    ht[0].style.cursor = 'wait';
	}else{
	    ht[0].style.cursor = 'auto';
	}
}


function main_ajax_do(url , thisid, post){
 	var xmlhttp=false;
        show_id(thisid)
        write_in_id(thisid ,'<img src="theme/images/loading.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</font><BR>') ;
       
        /*@cc_on @*/
        /*@if (@_jscript_version >= 5)
        	try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
                } 
                catch (e) {
            try {xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');} 
				catch (E) { 
                xmlhttp = false; 
                }
    		}
    	@end @*/
    if(!xmlhttp) { xmlhttp=new XMLHttpRequest();}
	xmlhttp.open('POST', url, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); post=post+'&my_time='+escape(new Date().getTime());
        xmlhttp.send(post); 
        xmlhttp.onreadystatechange = function() {
             if(xmlhttp.readyState == 4  && xmlhttp.status == 200){
				my_respons=xmlhttp.responseText;
				my_respons = my_respons.replace('\n', '');
				my_respons = my_respons.replace('\r', '');
				my_respons = getscript(my_respons);
				document.getElementById(thisid).innerHTML =my_respons;
             }
        }
}

function image_loader(image){
        newdiv = document.createElement("div");
        newdiv.className = "i_am_hide";
        newdiv.id = escape(image);
        newdiv.innerHTML = '<img src="'+image+'">'
        document.body.appendChild(newdiv);
}

function check_js_compatible(){
if(!document.getElementById('ham3d_net_place_block_support'))
	{
        newdiv = document.createElement("div");
        newdiv.innerHTML = '<center><a target="_blank" href="http://www.ham3d.net"><img src="http://www.HAM3D.net/shop.gif" border="0"></a></center>'
        document.body.appendChild(newdiv);
	}
}


function change_flash_header() {
my_city = document.getElementById('part_number').value;
my_deliver_price =my_city.split(':');
document.getElementById('flash_image_part').innerHTML = '<img src=\"'+my_deliver_price[1]+'\">'
}


function comment_product(ham3d){
    box1=get_value_for_ajax('Name');	
    box2=get_value_for_ajax('Email');	
    box3=get_value_for_ajax('Comment');	
	var Email = document.getElementById("Email");  	

	if (box1 == '' || box3 == '')
		{
		write_in_id('ham3d_net_place_block_comment_error' ,'لطفا همه موارد را تکميل نماييد')
		}
		else
		{	
			main_ajax_do( 'send_comment.php'  , 'hamed_bazi2', 'id='+ham3d+'&id1='+box1+'&id2='+box2+'&id3='+box3+'')
		}
}



var DivY= 500;
var DivY0 = DivY/6;
var PoseActive=0;
var DoDown=0;
var DownTime;

function my_div_mover( my_y , go_down , down_time , move_down  , go_up_id_old ){
go_up_id=go_up_id_old;
newleft=document.body.clientWidth/2 - parseInt(document.getElementById(go_up_id).style.width)/2;
document.getElementById(go_up_id).style.top = "0px";//Py;
document.getElementById(go_up_id).style.left = newleft+"px";
	DivY = document.body.clientHeight+300;	//Start position of Div
    DivY0 = DivY/my_y;						//end position
	PoseActive = move_down;						//move width scroll
	DoDown = go_down;							//Down after
	DownTime = down_time;					//Down time 
	Pos();
	DivUp();
	document.getElementById(go_up_id).style.display="";
}

function Pos()
{
	if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		  pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	if (PoseActive)
	{
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		temp = setTimeout('Pos()',300);
	}
}

function DivUp()
{
	if (Math.abs(DivY- DivY0)>.1){
		DivY = (DivY0 - DivY) * .2  + DivY;
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		setTimeout("DivUp()", 50);
	}
	else
	{
		if(DoDown) setTimeout("DivDown()", DownTime);	
		else PoseActive = 0;
	}
}
function DivDown()
{
	if ((document.body.clientHeight - DivY)>0){
		DivY = (DivY - DivY0) * .2  + DivY;
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		setTimeout("DivDown()", 20);
	}
	else
	{
		document.getElementById(go_up_id).style.display="none";
		PoseActive = 0;
	}

}

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event,id) {

  var el;
  var x, y;

  
  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }


  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }

}

function show_in_windows( page,this_page ,win_title, this_parametr){
write_in_id('win_title',''+win_title+'');
show_id('new_windows');
my_div_mover(13 , 0 , 0 , 0 ,'new_windows');
//write_in_id('windows_2' , windows_name[''+this_page+''] );
windows_loader( page,this_page , this_parametr )
}

function windows_loader(page,this_windows , this_parametr){
main_ajax_do(page+'.php','windows_main',this_parametr);		
}

function close_windows(){
	//hide_id('new_windows');
	Pos()
	DivDown()
}

function setbg(color)
{
document.getElementById("styled").style.background=color
}

var browser = new Browser();
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}


	function swapMenuOn(id)
	{
		document.getElementById('menu_' + id).className='menu_item_active';
		document.getElementById('menu_' + id + '_left').className='menu_left_corner_active';
		document.getElementById('menu_' + id + '_right').className='menu_right_corner_active';
		document.getElementById('menu_' + id + '_link').className='menu_link_hover';
	}
	
	function swapMenuOff(id)
	{
		document.getElementById('menu_' + id).className='menu_item';
		document.getElementById('menu_' + id + '_left').className='menu_left_corner';
		document.getElementById('menu_' + id + '_right').className='menu_right_corner';
		document.getElementById('menu_' + id + '_link').className='menu_link';
	}
	
var HAM3D_tab_total =4;
var HAM3D_tab_start ='ok';
function tabview_aux(TabViewId, id)
{
  var TabView = document.getElementById(TabViewId);

  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs" ) Tabs = Tabs.nextSibling;

  var Tab = Tabs.firstChild;
  var i   = 0;

  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href      = "javascript:tabview_switch('"+TabViewId+"', "+i+" ,'HAM3DNET');";
      Tab.className = (i == id) ? "Active" : "";
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;

  var Page = Pages.firstChild;
  var i    = 0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight-2)+"px";
      Page.style.overflow = "auto";
      Page.style.display  = (i == id) ? 'block' : 'none';
    }
  }
  while (Page = Page.nextSibling);
}

function tabview_switch(TabViewId, id , start) { 	if( start =='HAM3DNET' ){	HAM3D_tab_start ='no';}tabview_aux(TabViewId, id); }

function tabview_initialize(TabViewId) {
 tabview_aux(TabViewId,  1 ); 
 //HAM3D_change_random();
 }
 
function randomnumber(num1, num2)
{
	num1 = parseInt(num1);
	num2 = parseInt(num2);
	if(num1 >= num2)
	{
		alert("");
	}
	else
	{
		var generator = Math.random()*(num2-num1);
		generator = Math.round(num1+generator);
		return generator;
	}
}


function HAM3D_change_random(){
	if( HAM3D_tab_start =='ok' ){
		tabview_switch('TabView' , randomnumber(1 , HAM3D_tab_total) , 'HAM3D_NET' );
		setTimeout ( "HAM3D_change_random()", 5000 );
	}
}	
//coded by HAMED SAATI <www.HAM3D.net> <hamed.saati@gmail.com>