var xmlHttp;

function ContactUs(Form){
    SendDataByAjax(Form,"includes/Site.Ajax.Functions.php?do=ContactUs","?");
}

function SendDataByAjax(form,url,Redirect){
    
	xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
	}
    TextEditor1 = "Content";
    TextEditor2 = "Content2";
	var $inputs = $('#'+form+' input, #'+form+' textarea, #'+form+' select , '+form+' input:radio');
	var params = "";
	$inputs.each(function(i, el) {
	   if(el.name == TextEditor1 || el.name == TextEditor2){
           params += el.name + "=" + escape($(el).val()) + "&";
	   }else{
	       params += el.name + "=" + $(el).val() + "&";
	   }
       }
       );
	xmlHttp.onreadystatechange= function(){
	   
    var ajax_loading = document.getElementById("ajax_loading");
	var tr_error_msg = document.getElementById("tr_error_msg");
	var error_msg = document.getElementById("error_msg");
	var buttons = document.getElementById("buttons");
	var tr_right_msg = document.getElementById("tr_right_msg");
    
	if (xmlHttp.readyState==1){
		tr_error_msg.style.display="none";
		tr_right_msg.style.display="none";
		error_msg.innerHTML='';
		ajax_loading.style.display="";
		buttons.style.display="none";
	}
		
	if (xmlHttp.readyState==4){
		var result = trim(xmlHttp.responseText);
		ajax_loading.style.display="none";
		buttons.style.display="";
		if(result != "true"){
			error_msg.innerHTML=result;
	    	tr_error_msg.style.display="";
		}
		else{
		  if(Redirect == 0)
			tr_right_msg.style.display="";
            else{
                tr_right_msg.style.display="";
                setTimeout('window.location = "'+Redirect+'"', 1000);
            }
		}
	}
	};
	xmlHttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}


function GetXmlHttpObject(){
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
     	xmlHttp=new XMLHttpRequest();
	}
	catch (e){//Internet Explorer
    	try{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e){
     		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
	}
	return xmlHttp;
}
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}

$(document).ready(function() {
	$("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag
	$("#topnav li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
		$(this).find("span").show().html(linkText); //Add the text in the <span> tag
	}); 
	$("#topnav li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({
			marginTop: "-40" //Find the <span> tag and move it up 40 pixels
		}, 250);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0"  //Move the <span> back to its original state (0px)
		}, 250);
	});
});

function ShowAlert(){
    alert("ahmad");
}

$("img").lazyload({
    placeholder : "images/grey.gif",
    effect : "fadeIn" 
});
// create a shorthand function so we don't need to put all this in the opener's onclick
function openYouTube(opener) {
	var returnValue;
	
	// Safari Mobile doesn't have Flash, so we just let the device use the built-in 
	// YouTube viewer.		
	if (/(iPhone|iPod|iPad)/.test(navigator.userAgent)) {
		opener.href = opener.href.replace('/v/', '/watch?v=');
		returnValue = true;		
	}

	else returnValue = hs.htmlExpand(opener, { 
		objectType: 'swf', 
		objectWidth: 480, 
		objectHeight: 385, 
		width: 480, 
		swfOptions: { 
			params: { 
				allowfullscreen: 'true' 
			}
		}, 
		maincontentText: 'You need to upgrade your Flash player' 
	});
	
	return returnValue;
}  
/*
function initMenu() {
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
  );
}
*/
/******* Starting Ajax *******/

$.ajaxSetup ({
    cache: true
});

function GetPage(ID){
    var ajax_load = "<center><img src='images/ajax-loader.gif' alt='Loading .....' /></center>";
    var loadUrl = "includes/Site.Ajax.Functions.php";
    $("#Result").html(ajax_load).load(loadUrl, "p="+ID);
}

function GetSubPage(ID){
	var ajax_load = "<center><img src='images/sub_loading.gif' alt='Loading .....' /></center>";
    var loadUrl = "includes/Site.Ajax.Functions.php";
    $("#SubPage").html(ajax_load).load(loadUrl, "p=subpages&s="+ID);
    $('.MenuIMG').hide();
    $('#MenuCat' + ID).fadeIn("slow");
}
