/////////////////////////////////////////////
//  Written Totally by Mamdoh Abd El-Salam //
/////////////////////////////////////////////

var language;
var ImagesDirectory;
var IncludeDirectory;
var admin;

/////////////////////

var preloaded_Static_Images_Array = new Array();


function selectOptionByValue(selectElementName,optionValue){

	var obj = getOptionByValue(selectElementName,optionValue);
	
	if(obj != null){	
		obj.selected = true;
	}

}

function getOptionByValue(selectElementName,optionValue){

	var obj_all = document.getElementById(selectElementName).options;
	

	for(i = 0 ; i < obj_all.length ; i++){
	
		if(obj_all[i].value == optionValue){
		
			return obj_all[i];
		
		}
	
	}
	
	
	return null;

}




function getOptionIndexByValue(selectElementName,optionValue){

	var obj_all = document.getElementById(selectElementName).options;

	for(i = 0 ; i < obj_all.length ; i++){
	
		if(obj_all[i].value == optionValue){
		
			return i;
		
		}
	
	}
	
	
	return -1;

}



//////////////////////////////////////////
//			Start Option By Text	    //
//////////////////////////////////////////




function selectOptionByText(selectElementName,optionText){

	var obj = getOptionByText(selectElementName,optionText);
	
	if(obj != null){	
		obj.selected = true;
	}

}

function getOptionByText(selectElementName,optionText){

	var obj_all = document.getElementById(selectElementName).options;
	

	for(i = 0 ; i < obj_all.length ; i++){
	
		if(obj_all[i].text == optionText){
		
			return obj_all[i];
		
		}
	
	}
	
	
	return null;

}




function getOptionIndexByText(selectElementName,optionText){

	var obj_all = document.getElementById(selectElementName).options;

	for(i = 0 ; i < obj_all.length ; i++){
	
		if(obj_all[i].text == optionText){
		
			return i;
		
		}
	
	}
	
	
	return -1;

}




////////////////////////////////////////
//			End Option By Text		  //
////////////////////////////////////////




function getOffsetLeft(obj){

var element;
var sum = 0;

	if(!obj){
		return 0;
	}

	sum = obj.offsetLeft;
	
	while(obj = obj.offsetParent){
		sum = sum + obj.offsetLeft;
	}
	
	return sum;

}




function getOffsetTop(obj){

var element;
var sum = 0;

	if(!obj){
		return 0;
	}

	sum = obj.offsetTop;
	
	while(obj = obj.offsetParent){
		sum = sum + obj.offsetTop;
	}
	
	return sum;

}


var executeWhenLoaded_Timer_Id = 0;
var executeWhenLoaded_Data_Array = Array();

function executeWhenLoadedTimer(){
	
	var i = 0;
	var length = executeWhenLoaded_Data_Array.length;
	var executed_length = 0;
	
	for(i = 0 ; i < length ; i++){
		
		var obj = null;
		var functionString = '';
		var obj_1;
		
		obj_1 = executeWhenLoaded_Data_Array[i];
		
		if(obj_1.executed == false){
		
			obj = document.getElementById(obj_1.objectName);
		
			if(obj){
				functionString = obj_1.functionName + "(";
				functionString = functionString + getEvalParam("obj_1.param1",obj_1.param1);
				functionString = functionString + ',' + getEvalParam("obj_1.param2",obj_1.param2);
				functionString = functionString + ',' + getEvalParam("obj_1.param3",obj_1.param3);
				functionString = functionString + ',' + getEvalParam("obj_1.param4",obj_1.param4);
				functionString = functionString + ',' + getEvalParam("obj_1.param5",obj_1.param5);
				functionString = functionString + ',' + getEvalParam("obj_1.param6",obj_1.param6);
				functionString = functionString + ',' + getEvalParam("obj_1.param7",obj_1.param7);
				functionString = functionString + ',' + getEvalParam("obj_1.param8",obj_1.param8);
				functionString = functionString + ',' + getEvalParam("obj_1.param9",obj_1.param9);
				functionString = functionString + ',' + getEvalParam("obj_1.param10",obj_1.param10) + ")\;";
//				alert(functionString);
				eval(functionString);
				obj_1.executed = true;
				executed_length++;
			}
			
		}else{
			executed_length++;
		}
		
	}
	
	if(executed_length == length){
		clearInterval(executeWhenLoaded_Timer_Id);
		executeWhenLoaded_Timer_Id = 0;
	}
	
}


function getEvalParam(param,paramObj){
	
	var result;

	
	if(!paramObj){
		result = "obj";
		return result;
	}
	
	if (typeof paramObj == 'object'){
		result = param;
	}else{
		result = param;
	}
	
	return result;
	
}

function executeWhenLoaded(objectName,functionName,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10){
	
	var i = 0;
	
	i = executeWhenLoaded_Data_Array.length;

	executeWhenLoaded_Data_Array[i] = new Object();
	executeWhenLoaded_Data_Array[i].objectName = objectName;
	executeWhenLoaded_Data_Array[i].functionName = functionName;
	executeWhenLoaded_Data_Array[i].executed = false;
	executeWhenLoaded_Data_Array[i].param1 = param1;
	executeWhenLoaded_Data_Array[i].param2 = param2;
	executeWhenLoaded_Data_Array[i].param3 = param3;
	executeWhenLoaded_Data_Array[i].param4 = param4;
	executeWhenLoaded_Data_Array[i].param5 = param5;
	executeWhenLoaded_Data_Array[i].param6 = param6;
	executeWhenLoaded_Data_Array[i].param7 = param7;
	executeWhenLoaded_Data_Array[i].param8 = param8;
	executeWhenLoaded_Data_Array[i].param9 = param9;
	executeWhenLoaded_Data_Array[i].param10 = param10;
	
	if(executeWhenLoaded_Timer_Id == 0){
		executeWhenLoaded_Timer_Id = window.setInterval(executeWhenLoadedTimer,50);
	}
	
}




function isIE(){
	
	var result = false;

	if(navigator.appName == 'Microsoft Internet Explorer'){
		result = true;
	}else{
		result = false;
	}
	
	return result;
	
}




function strToInt(str){
	
	var char = 0;
	var result = '';

	for(i = 0 ; i < str.length ; i++){
		char = str.charCodeAt(i);
		if(char >= 48 && char <= 57){
			result = result + str.charAt(i);
		}
	}
	
	return parseInt(result,10);
	
}




function obj(id){

	return document.getElementById(id);
	
}




function disableSelection(object){
	
	object = obj(object);

	if (typeof object.onselectstart!="undefined"){ //IE route
		object.onselectstart=function(){return false;};
	}
	else if (typeof object.style.MozUserSelect!="undefined"){ //Firefox route
		object.style.MozUserSelect="none";
	}
	else{ //All other route (ie: Opera)
		object.onmousedown=function(){return false;};
		object.style.cursor = "default";
	}
	
}



function add_To_Preloaded_Images(src){
	
	preloaded_Static_Images_Array[preloaded_Static_Images_Array.length] = src;
	
}


function preload_All_Document_Images(){

	var preload_images_array = Array();
	var preload_images_array_II = Array();
	
	try{
	
		if(document.images){
			for(i = 0 ; i < document.images.length ; i++){
	//			alert(document.images[i].src);
				preload_images_array[i] = new Image();
				preload_images_array[i].src = document.images[i].src;
			}
		}
		
	}catch(exception){
		
	}
	
	try{
	for(i = 0 ; i < preloaded_Static_Images_Array.length ; i++){
		
		preload_images_array_II[i] = new Image();
		preload_images_array_II[i].src = preloaded_Static_Images_Array[i];
		
	}
	}catch(exception){
		
	}

}




function shuffle_array(myArray){
  var i = myArray.length;
  var resultArray = new Array();
  resultArray = myArray;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     resultArray[i] = tempj;
     resultArray[j] = tempi;
   }
  return resultArray;
}



function strToInt(str){
	
	var char = 0;
	var result = '';

	for(i = 0 ; i < str.length ; i++){
		char = str.charCodeAt(i);
		if(char >= 48 && char <= 57){
			result = result + str.charAt(i);
		}
	}
	
	return parseInt(result,10);
	
}




function getViewPortWidth(){

	var viewportwidth;
	var viewportheight;
 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	return viewportwidth;
	
}




function getViewPortHeight(){

	var viewportwidth;
	var viewportheight;
 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	return viewportheight;
	
}



function getImageFullPath(image_src,event_function){
	
	var image = new Image();
	
	image.event_function = event_function;
	
	image.onload = function image_loaded(){
						eval(this.event_function + '("' + this.src + '");');
					};
					
	image.src = image_src;
	
}