function set_tofrom(obj)
{
	function _chmode(name, mode)
	{
		var ar = document.getElementsByName(name);
		for (var i=0; i<ar.length; i++){
			ar[i].style.display = mode;	
		}
	}
	if(obj.options[obj.selectedIndex].text == "") {
		return;
	}
	if (obj.options[obj.selectedIndex].value <= 1) {
		_chmode('countrysec', 'none');
		_chmode('customsec', '');
	} else {	
		_chmode('countrysec', '');
		_chmode('customsec', 'none');
	}
}

function openNewWindow(url, w, h)
{
	// open a blank window
	w = (w==null) ? 500 : w;
	h = (h==null) ? 400 : h;
	var aWindow = window.open(url, '_blank',
	'scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,top=0,left=0,width='+w+',height='+h);
}

function swapView(id)
{
	obj = document.getElementById('sub'+id);
	img = document.getElementById('icon'+id);
	if(obj.style.display!='block'){
		obj.style.display = 'block';
		if(img){
			img.src = '../images/btn-less.png';
			img.style.background = 'url(../images/btn-less.png)';
		}
	} else {
		obj.style.display = 'none';
		if(img){
			img.src = '../images/btn-more.png';
			img.style.background = 'url(../images/btn-more.png)';
		}
	}		
}

function swapDisplay(id)
{
	obj = document.getElementById(id);
	if(obj.style.display=='none'){
		obj.style.display = 'block';
	} else {
		obj.style.display = 'none';
	}		
}

function setCookie(cName, cValue)
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = cName + "=" + escape (cValue) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");	
}

function getCookie(keyName)
{
	var nameEQ = keyName + "=";
	var ca = document.cookie.split (';');
	for (var i = 0; i < ca.length; i ++)
	{
		var c = ca [i];
		while (c.charAt (0) == ' ') c = c.substring (1, c.length);
		if (c.indexOf (nameEQ) == 0) return c.substring (nameEQ.length, c.length);
	}
	return null;
}

function deleteCookie(cName)
{
	setCookie(cName, "", -1);
}

function sortList(name, value)
{
	if(getCookie(name+'sortBy')!=value) {
		setCookie(name+'sortOrder', 'ASC');
	} else {
		setCookie(name+'sortOrder', getCookie(name+'sortOrder')=='DESC'?'ASC':'DESC');
	}
	setCookie(name+'sortBy', value);
	document.location.href = document.location.href.replace(/&page=[0-9]*/, '');
}

function filter(path, obj)
{
	var name = path + obj.name;
	var value = obj.options[obj.selectedIndex].value;
	setCookie(name, value);
	clearSearch();  // clear page & query and reload
}

function goto(page)
{
	// my paging is n=zzz this is the page number page are start from 1
	q = document.location.href;
	var patern = /^(.*)(\?|\&)page=(\d+)(\&?.*)$/;
	var reg = new RegExp(patern);
	if(!reg.test(q))
	{						// check if n=zzz dose not exists, add n=1 at the end of query
		var reg2 = new RegExp(/.*\?.*/);
		if(reg2.test (q))					// add ?n=zzz or &n=zzz
			q = q + "&page=1"; 
		else
			q = q + "?page=1";				
	}
	if(page == "prev")
	{						// goto previous page
		Page = Number(q.replace (patern, "$3")) - 1;
	}
	else
	{
		if(page=="next")
		{					// goto next page
			Page = Number(q.replace (patern, "$3")) + 1;
		}
		else
		{
			Page = Number(page);				// goto page n
		}
	}	
	q = q.replace(patern, "$1$2page=" + String(Page) + "$4");
	document.location.href = q;
}

function clearSearch()
{
	document.location.href = document.location.href.replace(/&page=[0-9]*/, '').replace(/&showall=1/, '')+'&showall=1';		
}

function ajaxDelete(action, objName, sender)
{
	SendServerRequest(action);
	while(sender = sender.parentNode){
		if(sender.className == objName || sender.id == objName || sender.name == objName){
			sender.style.display = 'none';
			if(sender.tagName=="TR") {
				sender.parentNode.deleteRow(sender.sectionRowIndex);
			}
			if(document.getElementById('message')) {
				document.getElementById('message').innerHTML = '<span style="color: #009900">عملیات حذف اطلاعات با موفقیت انجام شد.</span>';
			}
			return true;
		}
	}
	return false;
}

var sdiv;
var active;
var trid;
var stime;
function showStatusBox(id, obj)
{
	active = obj;
	trid = id;
	clearInterval(stime);
	if(!sdiv){										// create status dropdown div
		sdiv = document.createElement('DIV');
		sdiv.className='status-box';
		document.body.appendChild(sdiv);
		var img = new Array();						// create images
		for(var i=0; i<3; i++){
			img[i] = new Image();
			img[i].src = '../images/icons/16x16/status-'+i+'.png';
			img[i].style.margin = '3px';
			img[i].style.cursor = 'pointer';
			img[i].style.background = 'url(../images/icons/16x16/status-'+i+'.png)';
			img[i].style.height = '16px';
			img[i].style.width = '73px';
			img[i].id = "status_"+i;
			sdiv.appendChild(img[i]);
			img[i].onclick =  function (){setStatus(this);};
		}
	}
	document.body.onmousedown = function()			// set mousedown event for body to hide the sdiv
		{
			stime = setTimeout("sdiv.style.display='none'", 200);
			document.body.onmousedown = function(){};
		};
	with(sdiv.style){
		position = 'absolute';
		display = "block";
		top = (findPosY(obj) + 20) + 'px';
		left = (findPosX(obj) - 60) + 'px';
	}
}

function setStatus(obj)
{
	var colors = new Array('#909090', '#00AA00', '#AA0000');		// color array of status
	var i = obj.id.substr(7,1);										// extract index from image id (status-X)
	sdiv.style.display='none';
	document.body.onmousedown = function(){};
	SendServerRequest('index.php?section=admin&module=transport-edit&transportid_frm='+trid+'&status='+i);
	active.style.background = 'url(../images/icons/16x16/status-'+i+'.png) right';		// change the active status image
	var par = active;
	while (par = par.parentNode) {				// find this row first td and change the color
		if (par.className == "transport_row") {
			var ch = par.childNodes[0];	
			if(ch.tagName != 'TD'){				// difrence between ie & mozilla
				ch = par.childNodes[1];
			}			
			ch.style.borderRightColor = colors[i];
			break;
		}
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function showDetail(ObjId, module){
	nw = window.open("front.php?section=guest&module="+module+"&frm_id="+ObjId, "Book_Detail", "width=500,height=350,toolbar=no,scrollbars=yes,status=no,menubar=no");
	nw.focus();
}

function setSub(source, destination, opts, cnt)
{	
	if(opts)
	{
		var src = document.getElementById(source);
		if(!src) {
			src = document.getElementsByName(source)[0];	
		}
		if(src.selectedIndex >= 0){
			var pid = src.options[src.selectedIndex].value;
		} else {
			var pid = 0;
		}			
		var cnt2= 0;
		var dest = document.getElementById(destination);
		if(!dest) {
			dest = document.getElementsByName(destination)[0];	
		}
		while(dest.options[cnt])
		{
			dest.options[cnt] = null;	//remove all options
		}
		if(opts[pid])
		{
			while(opts[pid][cnt2])
			{
				ar = opts[pid][cnt2++].split("*:-)");
				dest.options[cnt++] = new Option(ar[1], ar[0]);		//add new options
			}
		}
	}
}

function CheckBoxes(fmobj)
{
	for(var i = 0; i < fmobj.elements.length; i ++)
	{

		var e = fmobj.elements[i];
		if((e.type == 'checkbox') && (e.type == 'checkbox') && (e.checked == true))
		{
			return true;
		}
	}	
}

function CheckAll(fmobj)
{
	for(var i = 0; i < fmobj.elements.length; i ++)
	{
		var e = fmobj.elements[i];
		if((e.name != 'allbox') && (e.type == 'checkbox') && (!e.disabled))
		{
			e.checked = fmobj.allbox.checked;
		}
	}
}

function CheckCheckedAll(fmobj)
{	
	var TotalBoxes = 0;
	var TotalOn = 0;
	for(var i = 0; i < fmobj.elements.length; i ++)
	{
		var e = fmobj.elements[i];
		if((e.name != 'allbox') && (e.type == 'checkbox'))
		{
			TotalBoxes ++;
			if(e.checked)
			{
				TotalOn ++;
			}
		}
	}
	
	if (TotalBoxes == TotalOn)
	{
		fmobj.allbox.checked = true;
		return -1;		// all of them checked
	}
	else
	{
		fmobj.allbox.checked = false;
		return TotalOn;	// none of them checked=0 else some of them checked
	}
}

function sortList(sortBy, sortMode, sortByVal, sortModeVal, url)
{
	setCookie(sortBy, sortByVal);
	setCookie(sortMode, sortModeVal);
	document.location.href = document.location.href.replace(/&page=([0-9]*)/g, '&page=1');
}

// Centeralized Pop-up Window
// PageURL  	: URL of pop-up page
// pageName		: Name of pop-up page
// w			: Width of pop-up page
// h			: Height of pop-up page
// pageScroll	: Scrollbars view or no : 'yes' or 'no'
// pageCenter	: Center of screen view or no : 'yes' or 'no'
function makePopup(pageURL, pageName, w, h, pageScroll, pageCenter)
{
	var popup = null;
	if(pageCenter == 'yes')
	{
		LeftPosition = (screen.width) ? (screen.width-w) / 2 : 0;
		TopPosition = (screen.height) ? (screen.height-h) / 2 : 0;
	}
	else
	{
		LeftPosition = 10;
		TopPosition = 10;
	}

	pageConfig = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + pageScroll + ', resizable=yes, width=' + (w + 18) + ', height=' + (h + 18) + ', left=' + LeftPosition + ', top=' + TopPosition;
	popup = window.open(pageURL, pageName, pageConfig);
	popup.focus();
}

function setTend(obj)
{
	var res = getAllChilds(obj.parentNode.parentNode);
	for(var i=0; i<res.length; i++){
		if(res[i].name == "frm_tendid[]"){
			res[i].checked = obj.checked;	
		}
	}
}

function checkTend(obj)
{
	var res = getAllChilds(obj.parentNode.parentNode);
	var flag_and = true;
	for(var i=0; i<res.length; i++){
		if(res[i].name == "frm_tendid[]"){
			flag_and &= res[i].checked;
		}
		if(res[i].tagName == "INPUT" && res[i].name==""){
			var chk = res[i];
		}
	}
	if(chk){
		chk.checked = flag_and;
	}
}

function getAllChilds(obj)
{
	var res = new Array();
	var cnt = 0;
	if(obj && obj.childNodes){
		for(var i=0; i<obj.childNodes.length; i++){
			res[res.length] = obj.childNodes[i];
			if(obj.childNodes[i].firstChild){
				var tmp = getAllChilds(obj.childNodes[i]);
				if(tmp){
					res = res.concat(tmp);
				}
			}
		}
		return res;
	}
}

//	parse URL
function createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}

FORM_DATA = createRequestObject();
// This is the array/object containing the GET data.
// Retrieve information with 'FORM_DATA [ key ] = value'.

function showTab(id, num, page)
{
	if(typeof(num) == "undefined")
		num = 1;
	$$('.tab').each(function(el) {
		el.addClass('hidden');});
	$('tabdiv'+id).removeClass('hidden');
		 if (num == 2) {
			switch(parseInt(id)){
				case 1:
					if(page == 'project')
					$('left_img').src = '../guest/img/p_ex.jpg';
					$('titr').className  = 'title-tab-m';
					$('link1').className = 'white-link';
					$('link2').className = '';
					break;
				case 2:
					if(page == 'project')
						$('left_img').src = '../guest/img/p_unex.jpg';
					$('titr').className  = 'title-tab-m2';
					$('link1').className = '';
					$('link2').className = 'white-link';
					break;
			}
		}else if(num == 3) {
			//alert(id);
			switch(parseInt(id)){
				case 1:
					if(page == 'about-us')
						$('left_img').src = '../guest/img/about3.jpg';
					$('titr').removeClass('title-tab-t2');
					$('titr').removeClass('title-tab-t3');
					$('titr').className  = 'title-tab-t1';
					$('link1').className = 'white-link';
					$('link2').className = '';
					$('link3').className = '';
					break;
				case 2:
					if(page == 'about-us')
						$('left_img').src = '../guest/img/about1.jpg';
					$('titr').removeClass('title-tab-t1');
					$('titr').removeClass('title-tab-t3');
					$('titr').className  = 'title-tab-t2';
					$('link1').className = '';
					$('link2').className = 'white-link';
					$('link3').className = '';
					break;
				case 3:
					if(page == 'about-us')
						$('left_img').src = '../guest/img/falat.jpg';
					$('titr').removeClass('title-tab-t1');
					$('titr').removeClass('title-tab-t2');		
					$('titr').className  = 'title-tab-t3';
					$('link1').className = '';
					$('link2').className = '';
					$('link3').className = 'white-link';
					break;
				case 4:

					break;					
			}
		}
}
function showBoxAboutfa(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxAboutfa("'+Obj+'");', 800);
		return;
	}
	$('extratableheight').style.height = window.ie?'257px':'237px';
	if(typeof(selectedtab)=="undefined") {
		if(typeof(hr[1]) != "undefined") $(Obj).style.display = (hr[1]==3?'':'none');
	} else {
		$(Obj).style.display = (selectedtab==3?'':'none');
	}
}
function showBoxAbouten(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxAbouten("'+Obj+'");', 800);
		return;
	}
	$('extratableheight').style.height = window.ie?'367px':'362px';
	if(typeof(selectedtab)=="undefined") {
		if(typeof(hr[1]) != "undefined") $(Obj).style.display = (hr[1]==1?'':'none');
	} else {
		$(Obj).style.display = (selectedtab==1?'':'none');
	}
}
function showBoxEquipmentfa(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxEquipmentfa("'+Obj+'");', 800);
		return;
	}
	if(typeof(selectedtab)=="undefined") {
		if(typeof(hr[1]) == "undefined") {
			$(Obj).style.display = 'none';
		} else {
			if(hr[1]==1)
			{
				$(Obj).style.display = '';
				$('extratableheight').style.height = window.ie?'1332px':'1222px';
			}
			if(hr[1]==2) {
				$(Obj).style.display = '';
				$('extratableheight').style.height = window.ie?'891px':'802px';
			}
			if(hr[1]==3) {
				$(Obj).style.display = 'none';
			}
		}
	} else {
		if(selectedtab==1)
		{
			$(Obj).style.display = '';
			$('extratableheight').style.height = window.ie?'1332px':'1222px';
		}
		if(selectedtab==2) {
			$(Obj).style.display = '';
			$('extratableheight').style.height = window.ie?'891px':'802px';
		}
		if(selectedtab==3) {
			$(Obj).style.display = 'none';
		}
	}
}
function showBoxEquipmenten(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxEquipmenten("'+Obj+'");', 800);
		return;
	}
	if(typeof(selectedtab)=="undefined") {
		if(typeof(hr[1]) == "undefined") {
			$(Obj).style.display = 'none';
		} else {
			if(hr[1]==1)
			{
				$(Obj).style.display = '';
				$('extratableheight').style.height = window.ie?'1350px':'1420px';
			}
			if(hr[1]==2) {
				$(Obj).style.display = '';
				$('extratableheight').style.height = window.ie?'930px':'1020px';
			}
			if(hr[1]==3) {
				$(Obj).style.display = 'none';
			}
		}
	} else {
		if(selectedtab==1)
		{
			$(Obj).style.display = '';
			$('extratableheight').style.height = window.ie?'1350px':'1420px';
		}
		if(selectedtab==2) {
			$(Obj).style.display = '';
			$('extratableheight').style.height = window.ie?'930px':'1020px';
		}
		if(selectedtab==3) {
			$(Obj).style.display = 'none';
		}
	}
}
function showBoxProjectfa(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxProjectfa("'+Obj+'");', 800);
		return;
	}
	var lochr = document.location.href.split('&tab=');
	if(lochr[1]!=null) {
		lochr = lochr[1].split('#');
		if(typeof(lochr[0]) == "undefined") {
			lochr[0] = 1;
		}
	} else {
		lochr[0] = 1;
	}
	if(typeof(selectedtab)=="undefined") {	
		if(lochr[0]==1) {
			$('extratableheight').style.height = (window.ie?152+(counte-4)*155:116+(counte-4)*150)+'px';
		}
		if(lochr[0]==2) {
			$('extratableheight').style.height = (window.ie?86+(countu-3)*198:49+(countu-3)*195)+'px';
		}
	} else {
		if(selectedtab==1) {
			$('extratableheight').style.height = (window.ie?152+(counte-4)*155:116+(counte-4)*150)+'px';
		}
		if(selectedtab==2) {
			$('extratableheight').style.height = (window.ie?86+(countu-3)*198:49+(countu-3)*195)+'px';
		}
	}
}

function showBoxProjecten(Obj, selectedtab)
{
	if(!$(Obj)){
		setTimeout('showBoxProjecten("'+Obj+'");', 800);
		return;
	}
	var lochr = document.location.href.split('&tab=');
	if(lochr[1]!=null) {
		lochr = lochr[1].split('#');
		if(typeof(lochr[0]) == "undefined") {
			lochr[0] = 1;
		}
	} else {
		lochr[0] = 1;
	}
	if(typeof(selectedtab)=="undefined") {	
		if(lochr[0]==1) {
			$('extratableheight').style.height = (window.ie?0+(counte-2)*155:0+(counte-2)*150)+'px';
		}
		if(lochr[0]==2) {
			$('extratableheight').style.height = (window.ie?58+(countu-3)*172:56+(countu-3)*182)+'px';
		}
	} else {
		if(selectedtab==1) {
			$('extratableheight').style.height = (window.ie?0+(counte-2)*155:0+(counte-2)*150)+'px';
		}
		if(selectedtab==2) {
			$('extratableheight').style.height = (window.ie?58+(countu-3)*172:56+(countu-3)*182)+'px';
		}
	}
}

//-------------------------------//Button Maker//----------------------------------
//---------------------------------------------------------------------------------
function getContent(url, query, cmd, cmdOnError, method, retry)				
{
	if(typeof(cmdOnError)=='undefined')
		cmdOnError = ';';
	if(typeof(method)=='undefined')
		method = 'GET';
	else
		method = method.toUpperCase();
	retry  = (retry || 0);
	if(retry > 5){
		try{
			eval(cmdOnError);
		} catch(e){}
		return;
	}
	var A = createAjax();
	if(method == "GET")
		A.open(method, url+'?'+query+'&_r_=done'+Math.random(), true);
	else
		A.open(method, url, true);

	var onreadystatechange = function(){
			if(A.readyState==4)
				if(A.status==200 || A.status == 304){
					Contents = A.responseText;
					var ScriptCode, regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
					while (ScriptCode = regexp.exec(Contents))
						try{
							eval(ScriptCode[1]);
						}catch(e){}
					// do the finish CMD
					try{
						eval(cmd);
					} catch(e){}
				}else {
					getContent(url, query, cmd, cmdOnError, method, (retry+1));
					}
			};
	A.onreadystatechange = onreadystatechange;
	if(method == "GET")
		A.send(null);
	else{
		var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
		A.setRequestHeader("Content-Type", contentType);
		A.send(query+'&_r_=done'+Math.random());
	}
}
function xMakeVisible(obj, d)												
{
	if(typeof(d) == "undefined")
		d = false;
	if(typeof(obj) != "object")
		obj = $(obj);
	if(!d)
		obj.style.display	= '';
	obj.style.visibility = "visible";
}
function xMakeHidden(obj, d)												
{
	if(typeof(d) == "undefined")
		d = false;
	if(typeof(obj) != "object")
		obj = $(obj);
	if(!d)
		obj.style.display	= 'none';
	obj.style.visibility = "hidden";
}												
function createAjax() 														
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
	try { return new XMLHttpRequest(); }
		catch(e) {}
	return null;
}
/*
var $ =	function (eName)													
	{
		return document.getElementById(eName);	
	};
*/	
function xFindPosX(obj)														
{
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
			}
		}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function xFindPosY(obj)														
{
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
			}
		}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function xRemovePX(strNum)													
{
	return strNum.substr(0, strNum.length - 2) * 1;
}
//-------------------------------//Image Loader//----------------------------------
var xImages = new Array();
var _xImages = new Array();
function _xloadImages() 													
{
	var i,key;
	for (i=0; i<_xloadImages.arguments.length; i++) {
		if (typeof(_xloadImages.arguments[i]) == 'string') {
			_xImages.push(document.createElement('img'));
			_xImages[_xImages.length-1].src = _xloadImages.arguments[i];
			}
		else if (typeof(_xloadImages.arguments[i]) == 'object')
			for(key in _xloadImages.arguments[i])
				if(typeof(_xloadImages.arguments[i][key]) != 'function') {
					_xImages.push(document.createElement('img'));
					_xImages[_xImages.length-1].src = _xloadImages.arguments[i][key];
					}
		}
}
function xloadImages()														
{
	var i,key;
	if (xloadImages.arguments.length == 0) {
		_xloadImages(xImages);
		return true;
		}
//	if (pageLoaded) {
//		for (i=0; i<xloadImages.arguments.length; i++)
//			_xloadImages(xloadImages.arguments[i]);
//		return true;
//		}
	for (i=0; i<xloadImages.arguments.length; i++){
		if (typeof(xloadImages.arguments[i]) == 'string') {
			xImages.push(xloadImages.arguments[i]);
			}
		else if (typeof(xloadImages.arguments[i]) == 'object') 
			for(key in xloadImages.arguments[i])
				if(typeof(xloadImages.arguments[i][key]) != 'function') {
					xImages.push(xloadImages.arguments[i][key]);
					}
		}
}
function xBtnCreate(obj, cmd, cmd2, type)									
{
	if(typeof(cmd2) == "undefined")
		cmd2 = "";
	if(typeof(type) == "undefined")
		type = "normal";
	if(type == "check"){
		oName = (obj.name)?obj.name:obj.id;
		if(oName.length < 1)
			oName = "rcoId"+Math.round(Math.random()*9999);
		var Obj = document.createElement('input');
		Obj.type = 'hidden';
		Obj.name = oName+"IN";
		Obj.id = oName+"IN";
		Obj.value = 0;
		obj.parentNode.appendChild(Obj);
		if(!obj.id)
			obj.id = oName;
	}
	var img = new Array();
	var tmp = obj.src.split('/images/');
	img['path'] = tmp[0]+"/images/";
	tmp = tmp[1].split('.');
	img['img'] = tmp[0];
	img['ext']  = tmp[1];
	if(typeof(img['img']) == 'undefined' || img['img'] == 'undefined' )
		return;
	_xloadImages (img['path']+img['img']+"."+	img['ext'],
				 img['path']+img['img']+"-over"+"."+img['ext'],
				 img['path']+img['img']+"-down"+"."+img['ext']
				);
	obj.style.cursor = "pointer";
	doWhileUp		= function(OBJid, CMD, targetV1, targetV2){
						try{
							OBJ = $(OBJid);
							if(OBJ.src != targetV1 && OBJ.src != targetV2){
								eval(CMD);
								setTimeout("doWhileUp('"+OBJid+"', '"+CMD+"', '"+targetV1+"', '"+targetV2+"')", 50);
								}
							}
						catch(e){}
						};
	obj.onmouseover	= function(){
							if(obj.src == img['path']+img['img']+"-down."+img['ext'])
								obj.src=img['path']+img['img']+"-down-over."+img['ext'];
							else
								obj.src=img['path']+img['img']+"-over."+img['ext'];
						};
	obj.onmouseout	= function(){
							if(obj.src == img['path']+img['img']+"-down-over."+img['ext'])
								obj.src=img['path']+img['img']+"-down."+img['ext'];
							else
								obj.src=img['path']+img['img']+"."+img['ext'];
						};
	obj.onmouseup 	= function(){
							if(type == "check"){
								if ($(obj.id+"IN").value == '0')
									obj.src=img['path']+img['img']+"-down-over."+img['ext'];
								else
									obj.src=img['path']+img['img']+"-over."+img['ext'];
								$(obj.id+"IN").value = ($(obj.id+"IN").value == '1')?0:1;
							}else							
								obj.src=img['path']+img['img']+"-over."+img['ext'];
						};
	obj.onmousedown = function(){
							obj.src=img['path']+img['img']+"-down."+img['ext'];
							if(typeof(cmd2) != "undefined" && cmd2.length > 0)
								doWhileUp(obj.id, cmd2, img['path']+img['img']+"-over."+img['ext'], img['path']+img['img']+"."+img['ext']);
						};
	obj.onclick		= function(){
							try{
								eval(cmd);
							} catch(e){}
						};
						
	obj.onload		= function(){
						};
	obj.ondblclick	= function(){
							obj.src=img['path']+img['img']+"."+img['ext'];
						};
}

var popupStatus = 'none';
var popupLastPage = '';

function popupWin(cmd, txt, page)						
{
	var popupWidth={
					"news-detail":600
					};
	if(typeof(page) == "undefined")
		page = 'en';
	if(typeof(txt) == "undefined")
		txt = 0;
	switch(cmd){
		case "create":		
			var Obj = document.createElement('div');
			Obj.id = "popupWinHolder";
			document.getElementsByTagName('body')[0].appendChild(Obj);
			$("popupWinHolder").innerHTML =	'<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">'+
													'<tr>'+
														'<td style="background:url(../images/them/Gray90_cornner.gif) no-repeat top left; width:15px; height:15px"></td>'+
														'<td style="background:url(../images/them/bgGray90.gif) repeat ;height:15px"></td>'+
														'<td style="background:url(../images/them/Gray90_cornner.gif) no-repeat top right; width:15px; height:15px"></td>'+
													'</tr>'+
													'<tr style="background:url(../images/them/bgGray90.gif) repeat ;">'+
														'<td style="width:15px"></td>'+
														'<td>'+
															'<div class="liveReportWin">'+
																'<div style="width:100%;height:23px;background:url(../images/them/liveRepWinHeaderBig.gif) repeat-x top;border:1px solid #969696;border-bottom:0;">'+
																	'<img src="../images/them/xwinBtnClose.gif" width="19" height="19" alt="" title="" style="margin:2px 4px 2px 2px; float:right" onLoad="xBtnCreate(this, \'popupWin(\\\'hide\\\')\')" />'+
																	'<img src="../images/them/xwinBtnMin.gif" id="popupBtnMinimize" width="19" height="19" alt="" title="" style="margin:2px; float:right" onLoad="xBtnCreate(this, \'popupWin(\\\'minimize\\\')\')" />'+
																	'<img src="../images/them/xwinBtnMax.gif" id="popupBtnMaximize" width="19" height="19" alt="" title="" style="margin:2px; float:right; display:none;" onLoad="xBtnCreate(this, \'popupWin(\\\'maximize\\\')\')" />'+
																'</div>'+
																'<div style="width:100%; background:#FFFFFF;border:1px solid #969696; border-bottom:0;">'+
																	'<table id="popupwinMainTable" border="0" cellpadding="0" cellspacing="5" style="width:100%;; background:#727272">'+
																		'<tr>'+
																			'<td align="center" id="popupWinContainer">'+
																			'</td>'+
																		'</tr>'+
																	'</table>'+
																'</div>'+
																'<div style="width:100%;height:20px;background:#FFFFFF url(../images/them/liveRepWinStratus.gif) no-repeat bottom left;text-align:right;border:1px solid #969696;color:#666666;" id="popupWinStatus"></div>'+
															'</div>'+
														'</td>'+
														'<td style="width:15px"><div style="display:none"><input type="hidden" id="popupwinPage" /><input type="hidden" id="popupwinText" /><input type="hidden" id="popupwinDirectUrl" /></div></td>'+
													'</tr>'+
													'<tr>'+
														'<td style="background:url(../images/them/Gray90_cornner.gif) no-repeat bottom left; width:15px; height:15px"></td>'+
														'<td style="background:url(../images/them/bgGray90.gif) repeat ;height:15px"></td>'+
														'<td style="background:url(../images/them/Gray90_cornner.gif) no-repeat bottom right; width:15px; height:15px"></td>'+
													'</tr>'+
												'</table>';	
			popupStatus = 'created';
			break;
		case "show":		
			i = 0;
			if(popupStatus == 'none')
				popupWin('create', txt, page);
			popupWin('maximize');
			$("popupWinHolder").style.width = 650 +"px";
//			if(eval("popupLastPage != '"+page+"#"+txt+"';"))
//			{
			popupWin('loading', txt, page);
			if(txt.length < 4)
				txt =  "news-detail&id=" + txt;
			popupWin('fetch', txt, page);
//			}
			popupLastPage = page+"#"+txt;
			var sw = document.getElementsByTagName("body")[0].clientWidth || screen.width;
			var sl = Math.round((sw - 650 )/2);
			st = 250+document.documentElement.scrollTop*1;
			$("popupWinHolder").style.top = st + 'px';
			$("popupWinHolder").style.left = sl + 'px';
			xMakeVisible("popupWinHolder");
			popupStatus = 'visible';
			break;
		case "hide":		
			if(popupStatus == 'none')
				break;
			xMakeHidden("popupWinHolder");
			popupStatus = 'hidden';
			break;
		case "minimize":	
			xMakeHidden('popupwinMainTable');
			xMakeHidden('popupBtnMinimize');
			xMakeVisible('popupBtnMaximize');
			break;
		case "maximize":	
			xMakeVisible('popupwinMainTable');
			xMakeVisible('popupBtnMinimize');
			xMakeHidden('popupBtnMaximize');
			break;
		case "fetch":		
			if(page=='en'){
				popupWin("status", "Loading ...", page);
				getContent(
							'index.php',
								'section=guest&module='+txt+'&lang='+page,
									'$("popupWinContainer").innerHTML = Contents;'+
									'popupWin("status", "Done!", "'+page+'");',
										'popupWin("status", "Loading ...", "'+page+'");'+
										'popupWin("error", "'+txt+'", "'+page+'")',
											'GET'
						);
			}else{
				popupWin("status", "درحال بارگزاری...", page);
				getContent(
							'index.php',
								'section=guest&module='+txt+'&lang='+page,
									'$("popupWinContainer").innerHTML = Contents;'+
									'popupWin("status", "انجام شد", "'+page+'");',
										'popupWin("status", "بارگزاری مجدد...", "'+page+'");'+
										'popupWin("error", "'+txt+'", "'+page+'")',
											'GET'
						);
			}
			break;
		case "loading":		
			if(page == 'en'){
				$("popupWinContainer").innerHTML =	'<div style="margin:0;background:#FFFFFF;width:300px; margin:0 auto;">'+
														'<table border="0" cellpadding="0" cellspacing="5" width="100" style="margin:0 auto; direction:ltr	">'+
														  '<tr><td><br><br><br><br><br><br></td></tr>'+
														  '<tr>'+
															'<td width="40%" style="text-align:right"><img src="../images/them/loading.gif" width="16" height="16" alt="" /></td>'+
															'<td width="60%" style="text-align:left">Please Wait ...</td>'+
														  '</tr>'+
														  '<tr><td><br><br><br><br><br><br></td></tr>'+
														'</table>'+
													'</div>';
			}else{
				$("popupWinContainer").innerHTML =	'<div style="margin:0;background:#FFFFFF;width:300px; margin:0 auto;">'+
														'<table border="0" cellpadding="0" cellspacing="5" width="100" style="margin:0 auto; direction:ltr	">'+
														  '<tr><td><br><br><br><br><br><br></td></tr>'+
														  '<tr>'+
															'<td width="80%" style="text-align:right">لطفاً صبر کنيد</td>'+
															'<td width="20%" style="text-align:left"><img src="../images/them/loading.gif" width="16" height="16" alt="" /></td>'+
														  '</tr>'+
														  '<tr><td><br><br><br><br><br><br></td></tr>'+
														'</table>'+
													'</div>';
			}
			break;
		case "reload":		
			if($('popupwinPage')){
				popupWin('loading');
				popupWin('fetch', $('popupwinText').value, $('popupwinPage').value);
			}
			break;
		case "error":		
			if(page=='en'){
				popupWin("status", "Error in data Transfer", page);
				$("popupWinContainer").innerHTML =	'<div class="whiteBoxHolder" style="margin:0;  width:300px;text-align:left">'+
														'<div class="BoxHeader"><div></div></div>'+
														'<div class="BoxContent" style="margin:0; padding:100px 0;">'+
														'<table border="0" cellpadding="0" cellspacing="0" width="100px" style="margin:0 auto">'+
														  '<tr>'+
															'<td><img src="../images/them/iconTimeout.gif" width="24" height="24" alt="" /></td>'+
															'<td>Please check your Connection status and try again.</td>'+
														  '</tr>'+
														'</table>'+
														'</div>'+
														'<div class="BoxFooter""><div></div></div>'+
													'</div>';
			}else{
				popupWin("status", "اشکال در دريافت اطلاعات!", page);
				$("popupWinContainer").innerHTML =	'<div class="whiteBoxHolder" style="margin:0;  width:300px;text-align:left">'+
														'<div class="BoxHeader"><div></div></div>'+
														'<div class="BoxContent" style="margin:0; padding:100px 0;">'+
														'<table border="0" cellpadding="0" cellspacing="0" width="100px" style="margin:0 auto">'+
														  '<tr>'+
															'<td>دريافت اطلاعات با مشکل مواجه شد. لطفاً بعد از بررسی ارتباط خود با اينترنت دوباره سعی کنيد</td>'+
															'<td><img src="../images/them/iconTimeout.gif" width="24" height="24" alt="" /></td>'+
														  '</tr>'+
														'</table>'+
														'</div>'+
														'<div class="BoxFooter""><div></div></div>'+
													'</div>';
			}
			break;
		case "status":
			if(page=='en')
				$("popupWinStatus").innerHTML = "<div style='direction:ltr'>&nbsp;&nbsp;&nbsp;" + txt + "&nbsp;&nbsp;&nbsp;</div>";
			else
				$("popupWinStatus").innerHTML = "<div style='direction:rtl'>&nbsp;&nbsp;&nbsp;" + txt + "&nbsp;&nbsp;&nbsp;</div>";
			break;
	}
}

