/*
	NEW
	THIS LIBRARY HAD BEEN MODIFIED FOR IE6 COMPATIBILITY.
	CHANGES WERE MADE BY: TAREK ORABI ON 10/16/2008 AT 9:16PM-CST
	
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	WARNING WARNING WARNING WARNING WARNING WARNING WARNING
	DO NOT MAKE ANY CHAGES WITHOUT CONSULTING WITH TAREK ORABI (tarek71@gmail.com)
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
var ajax_path="http://www.shortlister.net/";
var ERROR_ON_PAGE = false;
var EMAIL_ERROR = false;
var SEARCH_START = false;
var URL_THANKYOU = "_thankyou.php";

// Images 
var WAIT_IMG = '<img src=/images/wait.gif border=0 style="vertical-align: middle">';
var ERROR_IMG = '<img src="/images/error.png" border="0" style="vertical-align: bottom; width: 24px; height: 24px;">';
var OK_IMG = '<img src=/images/ok.gif border=0 style="vertical-align: bottom">';
var DEL_IMG = '<img src=' + ajax_path + 'images/del.gif' + '  border=0 style="vertical-align: bottom">';
var INFO_IMG= '<img src=' + ajax_path + 'images/info.gif' + '  border=0 style="vertical-align: bottom">';
var WORKING_IMG= '<img src=' + ajax_path + 'images/working.gif' + '  border=0 style="vertical-align: middle">';
var WARNING_IMG= '<img src="/images/warning.png" border=0 style="vertical-align: bottom; width: 24px; height: 24px;">';
var DUP_IMG= '<img src=' + ajax_path + 'images/dup.gif' + '  border=0 style="vertical-align: middle">';
var DBQ_IMG= '<img src=' + ajax_path + 'images/qry.gif' + '  border=0 style="vertical-align: middle">';
var LOADING_IMG= '<img src=' + ajax_path + 'images/loading.gif' + '  border=0 style="vertical-align: middle">';
var DOWNLOADOK_IMG= '<img src=' + ajax_path + 'images/downloadok.gif' + '  border=0 style="vertical-align: middle">';


var GOOGLE_ANALYTIC_IMG = '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1038880909/?value=1&amp;label=yCTLCPOLuwEQjaGw7wM&amp;guid=ON&amp;script=0"/>';
var BUSINESS_ANALYTIC_IMG = '<img height="1" width="1" style="border-style:none;" alt="" src="http://roi.business.com/crm/images/conversion.gif?bdc_conversion_id=11946&bdc_conversion_value=1.00"/>';

// ####################################################################################################################################
function ajax_SignCheckEmail(_email, _step)
{
	//alert(_email);
	//alert(_step);
	if(_email.length == 0)
	 {
		return; 
	 }
	var update_lbl = null;
	switch(_step)
	 {
		case "main":
			//update_lbl = "sign_check_email";
			$('#' + update_lbl).html(WAIT_IMG);	
			 var check_email = $.ajax({
								  // Define ajax url
								  url: ajax_path + "/wrk_new/sign_check_email.php", 
								  // Define ajax method
								  type: "POST",
								  // Prevent caching
								  cache: false,
								  async: true, 
								  // Pass paramaters to ajax object
								  data: "ACC_EMAIL=" + _email,
								  // Execute when ajax call was successful
								  success: function(ajax)
											  {
												//alert(ajax);
												switch(ajax)
												 {
													case "DUP":
														//$('#sign_check_email').html("");
														$("#dup").html(WARNING_IMG + " Email address already exist in our database; you must login before you post any projects.");
														$("#dup").dialog("open");
														$('*[name=imageField]').hide();
														EMAIL_ERROR = true;
													break;
													
													case "INVALID":
														//$('#sign_check_email').html("");
														$("#dup").dialog("open");
														$("#dup").html(ERROR_IMG + " You have provided invalid email address.");
														$('*[name=imageField]').hide();
														EMAIL_ERROR = true;
													break;
													
													case "VALID":
														$('*[name=imageField]').show();
														EMAIL_ERROR = false;
													break;
												 }
											  },
								  // Execute when ajax call failed
								  error: function(ajax)
											  {
												  alert('Error ' + ajax.responseText);	
											  }
						  });
		break;
		
		case "confirm":
			update_lbl = "sign_check_email_confirm";
			//alert($("#ACC_EMAIL").val());
			//alert($("#ACC_EMAIL_CONFIRM").val());
			$('#' + update_lbl).html(WAIT_IMG);
			if($("#ACC_EMAIL").val().toUpperCase() != $("#ACC_EMAIL_CONFIRM").val().toUpperCase())
			 {
					$('#' + update_lbl).html("");
					$("#missEmail").dialog("open");
					$('#btnSubmit').hide();
					EMAIL_ERROR = true;
					return;											 
			 }
			 else
			 {
						$('#' + update_lbl).html(OK_IMG);
						$('#btnSubmit').show();
			 }
		break;
	 }
}
// ####################################################################################################################################
function ajax_GetZipCodeDetails(_zip)
{
	var params = "ZIP=" + _zip + "&sid=" + Math.random();		
	
	var GET_ZIP = $.ajax({
							url: ajax_path + "wrk_new/doGetZipCodeDetails.php",
							data: params,
							success: function(ajax)
										{
											//alert(ajax);
											var data = ajax.split("|");
											$('#ACC_CITY').val(data[1]);
											$('#ACC_STATE').val(data[2]);
										},
							error: function()
										{
											alert(ajax.responseText);
										}		   
					   });
}
// ####################################################################################################################################
function ajax_PostProject(_step)
{
		var params = ""; 
		var DynamicURL= ajax_path + "wrk_new/doPostNewProject.php";
		$('*[name=' + _step + ']').each(function()
									{ 
										// Check if the paramater is empty; this indicates it's the first item in the loop
										if(params.length == 0)
										 {
											// Create the first parameter
											params = $(this).attr('id') + "=" + $(this).val();	  
										 }
										else
										 {
											// Concat the next item in the loop to the parameter 
											params += "&" + $(this).attr('id') + "=" + $(this).val();	 
										 }
             				}); 
							
							if(ERROR_ON_PAGE)
							{
								return false;	
							}
							
							// Get security field
							
							params += "&SID=" + Math.random();
							//alert(params);
							//return;
							$("#progress_" + _step).html(WAIT_IMG + " Processing ...");
							$("#btnSubmit").hide('slow');
							
							// Initilize ajax object
							var POST_PROJECT = $.ajax({
													// Define ajax url
													
													url: DynamicURL, 
													
													// Define ajax method
													type: "POST",
													
													// Prevent caching
													cache: false,
													
													// Pass paramaters to ajax object
													data: params,
													
													// Execute when ajax call was successful
													success: function(ajax)
																{
																	switch(ajax)
																	 {
																		case "ERROR_ACCOUNT":
																			$("#error").html(ERROR_IMG + " Error occured while creating user account; user account already exist. "); 
																			$("#error").dialog("open");
																			$("#progress_" + _step).html("");
																			
																		break;
																		
																		case "ERROR":
																			$("#error").html(ERROR_IMG + " Unexpected error occured, please try again."); 
																			$("#error").dialog("open");
																			$("#progress_" + _step).html("");
																		break;
																		
																		default:
																			var data = ajax.split("***");
																			//$("#confirmation").html("<p><strong>" + data[0] + "</strong></p>");
																			$("#matches").html(data[1]);
																			
																			$("#matches-personal").html("<p><strong>" + data[1] + "</strong></p>");
																			$("#ACC_DEADLINE").val(data[2]);
																			$("#step1").hide("blind", {}, 1000);
																			$("#step2").show("fold", {}, 1000);
																			window.open(URL_THANKYOU,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no, width=400, height=400");
																			
																		break;
																	 }
																	//$("#buffer").html(ajax);
																},
													// Execute when ajax call failed
													error: function(ajax)
																{
																		alert(ajax.responseText);
																}
											});
	
}
// ####################################################################################################################################
function ajax_UpdateProject(_step)
{
		var params = ""; 
		var DynamicURL= ajax_path + "wrk_new/doUpdateNewProject.php";
		$('*[name=' + _step + ']').each(function()
									{ 
										// Check if the paramater is empty; this indicates it's the first item in the loop
										if(params.length == 0)
										 {
											// Create the first parameter
											params = $(this).attr('id') + "=" + $(this).val();	  
										 }
										else
										 {
											// Concat the next item in the loop to the parameter 
											params += "&" + $(this).attr('id') + "=" + $(this).val();	 
										 }
             				}); 
							
							if(ERROR_ON_PAGE)
							{
								return false;	
							}
							
							// Get security field
							
							params += "&SID=" + Math.random();
							//alert(params);
							//return;
							$("#progress_" + _step).html(WAIT_IMG + " Processing ...");
							$("#btnUpdateProject").hide('slow');
							
							// Initilize ajax object
							var POST_PROJECT = $.ajax({
													// Define ajax url
													
													url: DynamicURL, 
													
													// Define ajax method
													type: "POST",
													
													// Prevent caching
													cache: false,
													
													// Pass paramaters to ajax object
													data: params,
													
													// Execute when ajax call was successful
													success: function(ajax)
																{
																	if(ajax == "OK")
																	 {
																			$("#step2").hide("blind", {}, 1000);
																			$("#step3").show("fold", {}, 1000);

																	 }
																	 else
																	 {
																		alert("Unexpected error, please try again \r\n" + ajax); 
																	 }
																	//
																	
																	//$("#buffer").html(ajax);
																},
													// Execute when ajax call failed
													error: function(ajax)
																{
																		alert(ajax.responseText);
																}
											});
}
// ####################################################################################################################################
function ajax_UpdateUserAccount(_step)
{
		var params = ""; 
		var DynamicURL= ajax_path + "wrk_new/doUpdateUserAccount.php";
		$('*[name=' + _step + ']').each(function()
									{ 
										// Check if the paramater is empty; this indicates it's the first item in the loop
										if(params.length == 0)
										 {
											// Create the first parameter
											params = $(this).attr('id') + "=" + $(this).val();	  
										 }
										else
										 {
											// Concat the next item in the loop to the parameter 
											params += "&" + $(this).attr('id') + "=" + $(this).val();	 
										 }
             				}); 
							
							if(ERROR_ON_PAGE)
							{
								return false;	
							}
							
							// Get security field
							
							params += "&SID=" + Math.random();
							//alert(params);
							//return;
							$("#progress_" + _step).html(WAIT_IMG + " Processing ...");
							$("#btnUpdateUser").hide('slow');
							
							// Initilize ajax object
							var POST_PROJECT = $.ajax({
													// Define ajax url
													
													url: DynamicURL, 
													
													// Define ajax method
													type: "POST",
													
													// Prevent caching
													cache: false,
													
													// Pass paramaters to ajax object
													data: params,
													
													// Execute when ajax call was successful
													success: function(ajax)
																{
																	if(ajax == "OK")
																	 {
																		jsf_CompleteProcess();
																		 setTimeout(function()
																							 {
																								 window.location.reload(true);
																							 }, 2000);
																		
																							 
																	 }
																	 else
																	 {
																		 alert('Unexpected error, please try again. \r\n' + ajax); 
																	 }
																},
													// Execute when ajax call failed
													error: function(ajax)
																{
																		alert(ajax.responseText);
																}
											});
}

// ####################################################################################################################################
var START_SEARCH = false;
function ajax_ProductSearch(_product)
{
	//alert(_product.length);
	$("#div_Products").html("");
	if(_product.length < 4)
	 {
		$("#div_Products").hide(2000);
		return false;
	 }
	
	  //$("#div_Products").show('fold',{}, 1500);
	  START_SEARCH = true;
	
	//$("#div_Products").html('<span style="font: 12px Arial, Helvetica, sans-serif; color: #000000; font-weight: bold">Please wait ...</span>  <img src="../images/wait.gif" style="margin-left: auto; margin-right: auto; margin-top: auto; margin-bottom: auto;" />');		 
	
	$("#product").toggleClass("working");
	$("#product").toggleClass("work");
	var params = "PRODUCT=" + _product;
	var PRODUCT_SEARCH = $.ajax({
							url: ajax_path + "wrk_new/doSearchProduct.php",
							type: "POST",
							data: params,
							cache: true,
							success: function(ajax)
										{
											//alert(ajax);
											//$("#div_Products").show("slow");
											$("#product").toggleClass("working");
											$("#product").toggleClass("work");
											$("#div_Products").show('blind',{}, 1500);
											$("#div_Products").html(ajax);
											setTimeout(function()
																{
																	
																	
																}, 1000);

											setTimeout(function()
																{
																	var _newWidth = $("#SEARCH_DATA").width();
																	//$("#div_Products").width(_newWidth + 15);
																	
																}, 3000);
										},
							error: function()
										{
											alert(ajax.responseText);
										}		   
					   });
}
// ####################################################################################################################################
function ajax_RemoveUpload(_file_path, _row_id )
{
	var params = "file_path=" + _file_path + "&sid=" + Math.random();
	$.ajax({
							url: ajax_path + "wrk_new/doDeleteFile.php",
							type: "GET",
							data: params,
							cache: true,
							success: function(ajax)
										{
											if(ajax == "OK")
											 {
												$("#" + _row_id).fadeOut('slow');
												//$('#divUPLOADLIST').html("Reloading ..."); 
												//$('#divUPLOADLIST').load("../wrk_new/doNewUploadList.php?SID=" + Math.random()); 
											 }
										},
							error: function()
										{
											alert(ajax.responseText);
										}		   
		   });
}
// ####################################################################################################################################

