function $$( Element ) {
	if ( document.getElementById( Element ) ) {
		return document.getElementById( Element );
	} else {
		return false;
	}
}

function $$$( Element ) {
	if( document.getElementsByName( Element ) ) {
		var sasannobakht = document.getElementsByName( Element );
		return sasannobakht[0];
	} else {
		return false;
	}
}

function Hide( Element ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).hide();
	} else {
		return false;
	}
}

function Show( Element ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).show();
	} else {
		return false;
	}
}

function Change_Display( Element ) {
	if ( $$( Element ) ) {
		if ( $$( Element ).style.display == 'none' ) {
			Show( Element );
		} else {
			Hide( Element );
		}
	} else {
		return false;
	}
}

function Go_Url( Url , Time) {
	setTimeout('document.location.href="'+Url+'"',Time);
}

function Get_Value( Element ) {
	if( !$$( Element ) && !$$( Element+'1' ) ) {
		return 'No Object';
	} else if( $$( Element ).type == 'checkbox' ) {
       return $$( Element ).checked;
	} else if( $$( Element ).type == 'radio' ||  $$( Element+'1' ).type == 'radio') {
		for( var i = 1; i <= Element.length; i++ ) {
			var nowid = ''+Element+''+i+'';
			if( $$(nowid).checked ) {
				return $$(nowid).value;
			}
		}
		return '';
	} else {
       return $$( Element ).value;
	}
}

function Change_Title( Title ) {
	document.title = Title;
}

function Change_Class( Element , NewClass ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).attr('class', NewClass);
	} else {
		return false;
	}
}

function Change_Opacity( Element , NewAlpha ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).css("filter", "alpha(opacity="+NewAlpha+"%");  
		$( '#'+Element ).css("opacity", NewAlpha/100);  
	} else {
		return false;
	}
}

function Change_Src( Element , NewSrc ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).attr('src', NewSrc);
	} else {
		return false;
	}
}

function Element_Disable( Element ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).attr('disabled', true);
	} else {
		return false;
	}
}

function Element_Enable( Element ) {
	if ( $$( Element ) ) {
		$( '#'+Element ).attr('disabled', '');
	} else {
		return false;
	}
}

function Change_Disable( Element ) {
	if ( $$( Element ) ) {
		if ( $$( Element ).disabled ) {
			Element_Disable( Element );
		} else {
			Element_Enable( Element );
		}
	} else {
		return false;
	}
}

function Write( Element , Note ) {
	if ( $$( Element ) ) {
		Show( Element );
		$( '#'+Element ).html(Note);
	} else {
		return false;
	}
}

function Ajax( Metod , Page , Data , Result_Id , Loading , Type , LoadingPicture , LoadingText , Wait_Id , Javascript ) {
	Data = 'Programmer=Sasan Nobakht&Load=Ajax&'+Data+'';
	$.ajax({ 
		type: Metod, 
		url: Page, 
		data: Data ,
		encoding: 'UTF-8',
		beforeSend : function( msg ) {
			if ( Loading ) {
				Ajax_Loading( Metod , Page , Data , Result_Id , Loading , Type , LoadingPicture , LoadingText , Wait_Id , Javascript , true );
			}
		},
		success :  function( msg ) {
			if ( Loading ) {
				Ajax_Loading( Metod , Page , Data , Result_Id , Loading , Type , LoadingPicture , LoadingText , Wait_Id , Javascript , false );
			}
			if ( Type != 'NoResultShow' &&  Type != 'Input' ) {
				$('#'+Result_Id).show();
				$('#'+Result_Id).html(msg);
			} else if ( Type == 'Input' ) {
				$$(Result_Id).value = msg;
			}
			if ( Javascript != '' ) {
				var sasan_all_java = Javascript.split( ';' )
				for ( i = 0; i < sasan_all_java.length; i++ ) {
					setTimeout("eval("+sasan_all_java[i]+")",100);
				}
			}
		},
		error :  function( msg ) {
			if (Page == 'Pardakht.php?Step=Token' && Data != '') {
				$("#Pay_Form_Div").slideUp("slow");
				$("#Connect_Failed").slideDown("slow");
			}
		}
	});
}

function Ajax_Loading( Metod , Page , Data , Result_Id , Loading , Type , LoadingPicture , LoadingText , Wait_Id , Javascript , Mode ) {
	if ( Mode ) {
		if (Type == 'Text') {
			Write(Wait_Id,LoadingText);
		} else if (Type == 'Picture') {
			Write(Wait_Id,'<table border="0" width="100%" height="80%" cellpadding="0" cellspacing="0" dir="rtl" align="center"><tr><td align="center" onclick="Ajax( \''+Metod+'\' , \''+Page+'\' , \''+Data+'\' , \''+Result_Id+'\' , false , \''+Type+'\' , \''+LoadingPicture+'\' , \'\' , \''+Wait_Id+'\' , \''+Javascript+'\' )" style="cursor:pointer;cursor:hand;"><img src="'+LoadingPicture+'" border="0">'+LoadingText+'</td></tr></table>');
		}
	} else {
		Write(Wait_Id,'');
	}
}

function EvalScript_Url ( url ) {
	$.getScript(url, function() {});
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for ( i = 0; i < a_all_cookies.length; i++ ) {
	a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) 
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
	
function PopUp(page,code,width,height) {
	window.open(page,code,'status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,width='+width+',height='+height+'');
}
