﻿var Browsers = navigator.userAgent.toLowerCase();
NS  = ( (Browsers.indexOf('mozilla')!=-1) && ( (Browsers.indexOf('spoofer')==-1) && (Browsers.indexOf('compatible') == -1) ) );
NS_std = ( (document.getElementById) && (!document.all) && (Browsers.indexOf("opera") == -1) );
IE = ( (Browsers.indexOf("msie") != -1) && (Browsers.indexOf("opera") == -1) );
OP = (Browsers.indexOf("opera") != -1);
stdBrowser=(document.getElementById) ? true : false;
obj=(document.images);
var Existing = false , MainID = null;
var HideLater=setTimeout("null",1);
var catWindow = null , Counter = 0;
var preWindow = new Array();

//**************** Load Images ****************\\


function LoadImages(){
	if(obj){
		imgsArray = new Array();
		var arg = 	LoadImages.arguments;
		for(var i=0 ; i<arg.length ; i++){
			imgsArray[i] = new Image();
			imgsArray[i].src = arg[i];
		}
	}
}

LoadImages('../images/arrow_submenu_on.gif','../images/email_on.gif','../images/home_on.gif','../images/flminus.gif','../images/auction_on.gif','../images/commitee_on.gif','../images/contractors_on.gif','../images/council_on.gif','../images/departments_on.gif','../images/financialreports_on.gif','../images/forms_on.gif','../images/introduction_on.gif','../images/mayor_on.gif','../images/news_on.gif','../images/otherfacilities_on.gif','../images/people_on.gif','../images/projects_on.gif','../images/relativeoffices_on.gif','../images/services_on.gif','../images/statistics_on.gif','../images/training_on.gif');
//**************** End Load Images ****************\\


//**************** Rollover ****************\\

function Mouseover(){
	if(obj){
		var i=0;
		while(i<Mouseover.arguments.length){
			document[Mouseover.arguments[i]].src = (Mouseover.arguments[i+1]=="jpg") ? (""+Path+"images/" + Mouseover.arguments[i] + "_on.jpg") : (""+Path+"images/" + Mouseover.arguments[i] + "_on.gif");
			i+=2;
		}
	}
}

function Mouseout(){
	if(obj){
		var i=0;
		while(i<Mouseout.arguments.length){
			document[Mouseout.arguments[i]].src = (Mouseout.arguments[i+1]=="jpg") ? (""+Path+"images/" + Mouseout.arguments[i] + ".jpg") : (""+Path+"images/"+Mouseout.arguments[i]+".gif");
			i+=2;
		}
	}
}

//**************** End Rollover ****************\\

//**************** Build Begining tag ****************\\

function IncreaseHeight(){
	
	var Layer01 = IncreaseHeight.arguments[0] , Layer02 = IncreaseHeight.arguments[1];
	if(document.getElementById(Layer02).offsetHeight > IncreaseHeight.arguments[2]){
		document.getElementById(Layer01).style.height=(document.getElementById(Layer02).offsetHeight-IncreaseHeight.arguments[2])+IncreaseHeight.arguments[3]+'px';
	}
	else{
		document.getElementById(Layer01).style.height=IncreaseHeight.arguments[3]+'px';
	}
}

function position_ly(){
	if(IE || OP){
		var newMargin=( document.body.offsetWidth-1024 > 0 ) ? (Math.ceil( (document.body.offsetWidth-1004) / 2 ) ) : 0;
	}
	else if(NS_std){
		var newMargin=(document.width-1024 >0 ) ? ( Math.ceil( (document.width-1004) / 2 ) ) : 0;
	}
	var Left = (position_ly.arguments[2]+newMargin) , Top = position_ly.arguments[1];
	var Width = (position_ly.arguments[3]!=null) ? (position_ly.arguments[3]+'px') : 'auto' ; Height = (position_ly.arguments[4]!=null) ? (position_ly.arguments[4]+'px') : 'auto' ;  ZIndex = (position_ly.arguments[5]!=null) ? position_ly.arguments[4] : 2;
	MainID=position_ly.arguments[0];
	if( screen.width > 1024 && MainID=="divBody" ){
		document.write("<div id=\""+MainID+"\" style=\"position:absolute;top:"+Top+"px;left:"+Left+"px;width:"+Width+";height:"+Height+";border:1px solid #ffa200;z-index:"+ZIndex+";\">");
	}
	else{
		document.write("<div id=\""+MainID+"\" style=\"position:absolute;top:"+Top+"px;left:"+Left+"px;width:"+Width+";height:"+Height+";z-index:"+ZIndex+";\">");
	}
	Existing=true;
}


//**************** End Build Begining tag ****************\\

//**************** Position Layer ****************\\


function styObject(nLayer , number){
	if(stdBrowser&&document.getElementById(nLayer)) {document.getElementById(nLayer).style.left = number + "px";}
	else if(IE&&document.all[nLayer]) {document.all[nLayer].style.pixelLeft = number;}
}



function posLayer(){
	var number = 0;
	if(IE || OP) {
		var newLeft=( document.body.offsetWidth-1024 > 0 ) ? (Math.ceil( (document.body.offsetWidth-1004) / 2 ) ) : 0;
	}
	else if(NS_std) {
		var newLeft=(document.width-1024 >0 ) ? ( Math.ceil( (document.width-1004) / 2 ) ) : 0;
	}
	if((TypePage != "Home") && (TypePage !="ChnageVersion")) {styObject("Floating",(newLeft+LeftFloat));}
	if(TypePage !="ChnageVersion"){
		for(var i=0 ; i<MenusGroup.length ; i++) {styObject(MenusGroup[i][0][0],newLeft+MenusGroup[i][1][1]);}
	}
	if(Existing){
		if(screen.width <= 1024){
			if( MainID=="divBody" ){
				if(stdBrowser) {document.getElementById(MainID).style.border = '0px';}
				else if(IE) {document.all[MainID].style.border = '0px';}
			}
			styObject( MainID , newLeft) ;
		}
		else if(screen.width > 1024){
			if( MainID=="divBody" ){
				if(stdBrowser) {document.getElementById(MainID).style.border = '1px solid #ffa200';}
				else if(IE) {document.all[MainID].style.border = '1px solid white';}
			}
			styObject( MainID , newLeft );
		}
	}
}

window.onresize = posLayer;

//**************** End Position Layer ****************\\

//**************** Visibility ****************\\
function VisibilityLayer(){
	clearTimeout(HideLater);
	argFunction=VisibilityLayer.arguments.length;
	for(var i=0 ; i<(argFunction-1) ; i+=2){
		if(stdBrowser) {divPropertie=document.getElementById(VisibilityLayer.arguments[i]).style;}
		else {divPropertie = document.all[VisibilityLayer.arguments[i]].style;}
		if(stdBrowser || IE){
			divPropertie.visibility = (VisibilityLayer.arguments[i+1]=="show") ? "visible" : "hidden";
		}
		else if(NS){
			divPropertie.visibility = (VisibilityLayer.arguments[i+1]=="show") ? "show" : "hide";
		}

	}
}

function HideAll(){
	clearTimeout(HideLater);
	HideLater=setTimeout("null",1);	
	if( HideAll.arguments[0] == null ){
		for(var i=0 ; i<MenusGroup.length ; i++){
			document.getElementById(MenusGroup[i][0][0]).style.visibility = (stdBrowser || IE) ? "hidden" : "hide";
		}
	}
	else{
		for(var i=0 ; i<MenusGroup.length ; i++){
			if(MenusGroup[i][0][0] != HideAll.arguments[0]) {document.getElementById(MenusGroup[i][0][0]).style.visibility = (stdBrowser || IE) ? "hidden" : "hide";}
		}
	}	
}

function HideControl(){
	clearTimeout(HideLater);
	var HideLaters="setTimeout(\'" , LayerStyle=null;
	for(var i=0 ; i<HideControl.arguments.length ; i++){
		LayerStyle=(stdBrowser) ? document.getElementById(HideControl.arguments[i]).style : document.all[HideControl.arguments[i]].style;
		HideLaters=HideLaters+"document.getElementById(\""+HideControl.arguments[i]+"\").style.visibility=\"hidden\";"
	}
	HideLaters+="\',500)";
	HideLater = eval(HideLaters);
}
//**************** End Visibility ****************\\

//**************** Field ****************\\
function ManageField(){
	var Field = eval('document.'+ManageField.arguments[0]+'.'+ManageField.arguments[1]);
	if(Field.value=="" && Field.type=="text") {Field.value='نام کاربری';}
	else if(Field.value=="نام کاربری" && Field.type=="text") {Field.value='';}
	else if(Field.value=="" && Field.type=="password") {Field.value="11111";}
	else if(Field.value=="11111" && Field.type=="password") {Field.value="";}
}
//**************** Field ****************\\

//**************** New Windows ****************\\

function newWindow(){
	if(catWindow){
		if(!catWindow.closed) {catWindow.close();}
	}
	var Char=parseInt(newWindow.arguments[0]);
	if(!Char){
		catWindow=window.open(newWindow.arguments[0],'',"directories=no,status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no");
		catWindow.focus();
		return false;
	}
	var LeftWin=TopWin=WidthWin=HeightWin=0;
	var varScroll=adPage="null";
	if(newWindow.arguments[0]>1000){
		WidthWin = 648;
		varScroll="yes";
	}
	else{
		WidthWin = newWindow.arguments[0];
		varScroll="no";
	}
	if(newWindow.arguments[1]>620){
		HeightWin = 448;
		varScroll="yes";
	}
	else{
		HeightWin = newWindow.arguments[1];
		varScroll="no";
	}
	adPage = newWindow.arguments[2];	
	namPage = "CatWin" + Counter;	
	if(screen){
		LeftWin=((screen.width - WidthWin) / 2 ) + "px";
		TopWin=((screen.height - HeightWin) / 2) + "px";
	}
	if(opener&&opener.catWindow){
		if(opener.catWindow.name==namPage){
			Counter+=1;
			namPage = "CatWin" + Counter;	
		}
	}
	if(newWindow.arguments[3]==true) {varScroll="yes"}
	catWindow=window.open(adPage,namPage,"left="+LeftWin+",top="+TopWin+",height="+HeightWin+",width="+WidthWin+",directories=no,status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars="+varScroll+"");
	preWindow[Counter]=catWindow;
	if(newWindow.arguments[3] && newWindow.arguments[3]!=true){
		var URL="",Length=0;
		catWindow.document.open();
		catWindow.document.writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
		catWindow.document.writeln("<html  xmlns=\"http://www.w3.org/1999/xhtml\">");
		catWindow.document.writeln("<head>");
		catWindow.document.writeln("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" \/>");
		catWindow.document.writeln("<meta name=\"generator\" content=\"Adobe GoLive\" \/>");
		catWindow.document.writeln("<title>Welcome to ferdows ### "+newWindow.arguments[3]+" ###<\/title>");
		catWindow.document.writeln("<link href=\""+Path+"css/ferdows.css\" rel=\"stylesheet\" media=\"screen\">");
		catWindow.document.writeln("<\/head>");
		if(newWindow.arguments[4]){
			var Code=newWindow.arguments[4].charAt(0);	
			if(Code=="#") {catWindow.document.writeln("<body style=\"background:"+newWindow.arguments[4]+";\">");}
			else {catWindow.document.writeln("<body style=\"background:url(\'"+newWindow.arguments[4]+"\') no-repeat top left;\">");}
		}
		for(var i=0 ; i<4 ; i++){
			Length=newWindow.arguments[2].length-4;
			URL += newWindow.arguments[2].charAt(Length+i);
		}
		if( URL==".swf" ){
			catWindow.document.writeln("<p><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\""+newWindow.arguments[0]+"\" height=\""+newWindow.arguments[1]+"\">"+
			"<param name=\"movie\" value=\""+newWindow.arguments[2]+"\" \/>"+
			"<param name=\"quality\" value=\"best\" \/>"+
			"<param name=\"play\" value=\"true\" \/>"+
			"<embed pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\""+newWindow.arguments[2]+"\" type=\"application/x-shockwave-flash\" width=\""+newWindow.arguments[0]+"\" height=\""+newWindow.arguments[1]+"\"><\/embed><\/object></p>");
		}
		else if(URL==".mov"){
			catWindow.document.writeln("<p><object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+newWindow.arguments[0]+"\" height=\""+newWindow.arguments[1]+"\">"+
			"<param name=\"src\" value=\""+newWindow.arguments[2]+"\" \/>"+
			"<param name=\"autoplay\" value=\"true\" \/>"+
			"<param name=\"controller\" value=\"false\" \/>"+
			"<embed pluginspage=\"http://www.apple.com/quicktime/download\" src=\""+newWindow.arguments[2]+"\" type=\"video/quicktime\" width=\""+newWindow.arguments[0]+"\" height=\""+newWindow.arguments[1]+"\"><\/embed><\/object></p>");
		}
		else if(URL==".jpg" || URL==".gif" || URL==".png"){
			catWindow.document.writeln("<img border=\"0\" src=\""+newWindow.arguments[2]+"\" style=\"width:"+newWindow.arguments[0]+";height:"+newWindow.arguments[1]+";\">");
		}
		catWindow.document.writeln("<\/body>");
		catWindow.document.writeln("<\/html>");
		catWindow.document.close();
	}
	Counter+=1;
	catWindow.focus();
}

//**************** End New Windows ****************\\

if((TypePage != "Home") && (TypePage !="ChnageVersion")){
	Buildfloat();
	Mover();
}
if(TypePage !="ChnageVersion"){
	BuildPopupMenu();
}